7

Java 6 と Scala 2.10 で Eclipse 3.7 w/m2e (2 週間前にインストール) を使用しています。

m2e を使用してプロジェクト構成を更新するときはいつでも、.pom の構成方法に応じて、ソース フォルダーとして常にsrc/main/java&&を選択するsrc/test/javaか、 src/main/scala&&を選択します。src/test/scala4 つすべてをソース フォルダーとして使用したいと考えています。

これが私の.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 を使用してビルドする方法に戻るかもしれません。

PS指定された.pomでは、Javaソースフォルダーを使用します

4

3 に答える 3

7

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>
于 2013-03-06T10:46:46.783 に答える
4

2 つのオプションがあります。1 つ目は、プロジェクトを 2 つのモジュールを持つ親プロジェクトに分割し、それぞれに独自の pom を持たせることです。これはmavenでそれを行うより自然な方法ですが、私自身はscalaユーザーではないため、あなたのセットアップで実現可能かどうかは完全にはわかりません.

 <parent> ai.chess (packaging: pom)
    <module> ai.chess.java (packaging: jar)
    <module> au.chess.scala (using <sourceDirectory>)

2 番目のオプションは、レイアウトをそのまま維持し、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>
于 2013-03-06T00:41:03.700 に答える
0
  1. scala-maven-plugin への更新 (scala-tools.org は 2 年ぶりに存在しなくなりました)
  2. ゴール add-source を使用します (scala のみの場合は build-helper-maven-plugin と同じことを行います)

.java ファイルと .scala ファイルを同じ src/main/xxx と src/test/xxx の下に格納することもできます。Java コンパイラは *.scala を無視し、scala コンパイラは両方を使用します。

于 2013-03-11T11:00:54.330 に答える