我使用的是Eclipse 3.7 w/m2e(2周前安装的),Java 6和Scala 2.10。
当我使用m2e来更新项目配置时,取决于我如何配置我的。pom,它总是选择src/main/java
&&src/test/java
或者选择src/main/scala
&&src/test/scala
作为我的源文件夹。我希望这四个文件夹都是源文件夹。
这是我的。pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.my.name</groupId>
<artifactId>ai.chess</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>chessAI</name>
<description>Chess AI</description>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- <sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory> -->
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArgs>
<jvmArg>-Xms64m</jvmArg>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
<sources>
<source>src/main/scala</source>
<source>src/main/java</source>
<source>src/test/scala</source>
<source>src/test/java</source>
</sources>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.scala-tools
</groupId>
<artifactId>
maven-scala-plugin
</artifactId>
<versionRange>
[2.15.2,)
</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
最终,我想创建一个UberJar与所有必要的依赖,这样它可以运行在一个服务器上,不支持scala(但Java)。国际象棋游戏的框架是用Java给出的,所以我想把它和Scala一起使用
如果Maven继续让人头疼,我可能会切换回使用Ant来构建。
注:对于给定的.pom,它使用java源文件夹
Scala -maven-plugin(之前命名为maven-scala-plugin)需要一些额外的配置来完成混合Scala/Java项目,但是如果您按照它们的说明(下面复制),它应该将所有必要的目录添加到您的构建路径中。
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
您有两个选择:第一种是将您的项目拆分为具有两个模块的父项目,每个模块都有自己的pom。这是使用maven更自然的方式,但由于我自己不是scala用户,我不完全确定在您的设置中是否可行。
<parent> ai.chess (packaging: pom)
<module> ai.chess.java (packaging: jar)
<module> au.chess.scala (using <sourceDirectory>)
第二个选项是保持布局不变,并使用build-helper-maven-plugin将源目录添加到构建中;这样的:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/scala</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
- 更新到scala-maven-plugin (scala-tools.org已经不存在了,因为2年了)
- 使用目标添加源(只对scala使用build-helper-maven-plugin)
你也可以把你的。java和。scala文件存放在src/main/xxx和src/test/xxx目录下,java编译器会忽略*。