我当前的java版本是7:
java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) Server VM (build 24.80-b11, mixed mode)
我有命令mvn8
,其中java_home
设置为8:
mvn8 -version
Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /home/.../apache-maven-3.0.3
Java version: 1.8.0_66, vendor: Oracle Corporation
Java home: /home/.../jdk1.8.0_66/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-45-generic", arch: "i386", family: "unix"
现在问题。当我在项目中运行我的一个配置文件(有maven exec插件生成文件)时:
mvn8 exec:exec -P mo2ja -o
我得到了例外:
Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
[INFO] Scanning for projects...
...
ERROR:java.time.LocalDateTime cannot be resolved to a type.
ERROR:java.time.LocalDate cannot be resolved to a type.
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:764)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:711)
at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:289)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
所以它似乎仍然需要我的系统java。为什么当mvn版本打印java8?当我更改我的系统java然后它工作正常。这是maven的一些功能,或者它可能是我使用的插件问题?
更新
当我调试maven exec插件时,我看到这一行:
[DEBUG] Executing command line: java -classpath ... org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader -control definitions.model -models entity.model,dao.model -source src/main/resources -target src-gen
所以问题是如何使用与执行mvn相同的java版本
这是我的个人资料:
<profile>
<id>mo2ja</id>
<dependencies>
<dependency>
<groupId>org.sqlproc.model</groupId>
<artifactId>sqlmodel</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<classpathScope>runtime</classpathScope>
<arguments>
<argument>-classpath</argument>
<classpath>
<dependency>org.sqlproc.model:sqlmodel</dependency>
<dependency>mysql:mysql-connector-java</dependency>
<dependency>org.sqlproc:sql-processor</dependency>
<dependency>org.slf4j:slf4j-api</dependency>
</classpath>
<argument>org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader</argument>
<argument>-control</argument>
<argument>definitions.model</argument>
<argument>-models</argument>
<argument>entity.model,dao.model</argument>
<argument>-source</argument>
<argument>src/main/resources</argument>
<argument>-target</argument>
<argument>src-gen</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
答案 0 :(得分:0)
更改maven编译器插件以允许级别1.8
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>