1
回答
mvn install 时的问题
【腾讯云】校园拼团福利,1核2G服务器10元/月!>>>   
[INFO] Reactor Summary:
[INFO]
[INFO] bi-platform ........................................ SUCCESS [  3.000 s]
[INFO] fileserver ......................................... FAILURE [  1.597 s]
[INFO] model .............................................. SKIPPED
[INFO] cache .............................................. SKIPPED
[INFO] common-api ......................................... SKIPPED
[INFO] schedule ........................................... SKIPPED
[INFO] designer ........................................... SKIPPED
[INFO] parser ............................................. SKIPPED
[INFO] tesseract .......................................... SKIPPED
[INFO] queryrouter ........................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.768 s
[INFO] Finished at: 2015-10-20T15:45:37+08:00
[INFO] Final Memory: 21M/181M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project fileserver: Fatal error compiling: 无效的目标发行版: 1.8 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :fileserver
举报
逍遥wansheng
发帖于3年前 1回/1K+阅
共有1个答案 最后回答: 2年前

maven可以指定使用另外的JDK来编译。

http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

Compiling Sources Using A Different JDK

The compilerVersion parameter can be used to specify the version of the compiler that the plugin will use. However, you also need to set fork to true for this to work. For example:

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <verbose>true</verbose>
          <fork>true</fork>
          <executable><!-- path-to-javac --></executable>
          <compilerVersion>1.3</compilerVersion>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

To avoid hard-coding a filesystem path for the executable, you can use a property. For example:

<executable>${JAVA_1_4_HOME}/bin/javac</executable>

Each developer then defines this property in settings.xml, or sets an environment variable, so that the build remains portable.

<settings>
  [...]
  <profiles>
    [...]
    <profile>
      <id>compiler</id>
        <properties>
          <JAVA_1_4_HOME>C:\Program Files\Java\j2sdk1.4.2_09</JAVA_1_4_HOME>
        </properties>
    </profile>
  </profiles>
  [...]
  <activeProfiles>
    <activeProfile>compiler</activeProfile>
  </activeProfiles>
</settings>

If you build with a different JDK, you may want to customize the jar file manifest.


但是在windows下并没有用,因为执行mvn install的时候,实际执行的命令是拼接出来的,所以,按照上面例子的配置,假设你的cmd窗口所在路径是C:\,那么本来执行的命令是javac -d ......就会变成了

C:\C:\Program Files\Java\j2sdk1.4.2_09\bin\javac -d ......

执行的时候会出错。

如果不嫌麻烦,可以手动执行命令,

mvn install -X > err.txt

在输出中找到出错的位置,找到原始的命令,复制出来,稍作修改,在cmd窗口中直接执行。



或者更简单的,直接将将JAVA_HOME改为jdk8的目录

顶部