我想在我的scala项目中使用线程池。它可以在我的IntelliJ Idea中运行良好,但是当我编译项目时使用maven命令行抛出异常:mvn compile。我添加了依赖项" scala-libray"和" scala-actors",但没有任何影响。你能救我吗?
我的代码:
import scala.actors.threadpool.Executors
val execService = Executors.newFixedThreadPool(10)
错误:
[ERROR] /project../server/EasyServer.scala:6: error: object actors is not a member of package scala
[ERROR] import scala.actors.threadpool.Executors
[ERROR] ^
[ERROR] /project../server/EasyServer.scala:16: error: not found: value Executors
[ERROR] val execService = Executors.newFixedThreadPool(10)
[ERROR] ^
[ERROR] two errors found
我的pom.xml的一部分:
<properties>
<scala.version>2.11.6</scala.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-actors</artifactId>
<version>${scala.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/.svn/</exclude>
</excludes>
</resource>
</resources>
<plugins>
<!-- the Maven compiler plugin will compile Java source files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- the Maven Scala plugin will compile Scala source files -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!--
Bind the maven-assembly-plugin to the package phase this will create
a jar file without the storm dependencies suitable for deployment to
a cluster.
-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
答案 0 :(得分:2)
从2.11开始,scala actor作为单独的库提供:
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-actors</artifactId>
<version>2.11.6</version>
</dependency>
请注意,它们也被弃用,以支持Akka:http://docs.scala-lang.org/overviews/core/actors-migration-guide.html