11

scala 2.9.2 プロジェクトと Java 8 バージョンの間に互換性がないため、maven プロジェクトで jvm の使用を手動で指定する必要があります。

ここのドキュメントを使用して、私が作成したpom.xml :

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.netlogo.extension</groupId>
    <packaging>jar</packaging>
    <artifactId>rungekuta</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${lib.org.scala-lang.scala.version}</version>
        </dependency>
        <dependency>
           <groupId>org.nlogo</groupId>
           <artifactId>netlogo</artifactId>
            <version>5.2</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <properties>
        <lib.org.scala-lang.scala.version>2.9.3</lib.org.scala-lang.scala.version>
        <maven.scala.version>${lib.org.scala-lang.scala.version}</maven.scala.version>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                    <version>3.2.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Extension-Name>rungekuta</Extension-Name>
                            <Class-Manager>org.netlogo.extension.rungeKuta.RungeKutaExtension</Class-Manager>
                            <NetLogo-Extension-API-Version>5.0</NetLogo-Extension-API-Version>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <verbose>true</verbose>
                    <fork>true</fork>
                    <executable>/home/reyman/Logiciels/jdk1.7.0_80/bin/javac</executable>
                    <compilerVersion>1.3</compilerVersion>
                </configuration>
            </plugin>
        </plugins>
    </build>


    <name>${project.artifactId} ${project.version}</name>


    <repositories>
        <repository>
            <id>snapshots.scala-tools.org</id>
            <name>Scala snapshots repository</name>
            <url>http://scala-tools.org/repo-snapshots/</url>
        </repository>
        <repository>
            <id>scala-tools.org</id>
            <name>Scala repository</name>
            <url>http://scala-tools.org/repo-releases/</url>
        </repository>
    </repositories>

</project>

私は成功せずにこれを試してみました.mavenは現在のjvm 8を使用し続け、で指定されたjvmは使用しませんmaven-compiler-plugin:<executable>/home/reyman/Logiciels/jdk1.7.0_80/bin/javac</executable>

mvn compilescala/java ソースが混在するプロジェクトでjvm 7 を強制的に使用するにはどうすればよいですか?

4

4 に答える 4

6

これは私のために働いた:

<plugin>
    <inherited>true</inherited>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>
于 2016-02-19T10:31:45.723 に答える
3

java6でminify-maven-plugin 1.7を使用しようとして同じ問題が発生しました。Java7 が必要です。問題は、プラグインを使用するには適切な JVM で Maven を実行する必要があることです。そのため、私が見つけた唯一の解決策は、maven を実行する前に JAVA_HOME をエクスポートすることでした。

ORIGINAL_JAVA_HOME=$JAVA_HOME
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_79
mvn jetty:run
export JAVA_HOME=$ORIGINAL_JAVA_HOME

これを頻繁に行う必要がある場合は、次のようなエイリアスをbashrcに追加できます

alias mvn7='ORIGINAL_JAVA_HOME=$JAVA_HOME; export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_79; mvn jetty:run; export JAVA_HOME=$ORIGINAL_JAVA_HOME'
于 2016-02-22T11:03:25.597 に答える