我在哪里可以查看Apache Maven Java构建版本?什么是 JNI 错误?



我的maven有问题。专家可以成功地构建项目。但是我不能运行mvn构建的jar。在哪里可以检查mvn Java构建版本?我还没有安装好几个版本的java。我是java的初学者。在哪里可以检查Java配置?

第三个是pom.xml作者:Stephen C。然而,mvn无法清理项目。

环境变量:

JAVA_HOME:C:Program FilesJavajdk1.8.0_251
M2_HOME:C:apache-maven-3.6.3
$mvn package package dModule=100Main
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ h ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ h ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ h ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ h ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ ch ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ h ---
[INFO] Building jar: C:BATtargeth-0.0.1.jar
[INFO]
[INFO] --- maven-assembly-plugin:3.1.0:single (batch) @ h ---
$"C:Program FilesJavajdk1.8.0_251binjava" -jar  A100.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: /Package/name/100Main has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)

pom.xml

<name>batch</name>
<description>mvn clean compile -P [local/development/production] package -Dmodule=***</description>
<properties>
<sourceEncoding>UTF-8</sourceEncoding>
<compileSource>1.8</compileSource>
<java-version>1.8</java-version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.test.skip>true</maven.test.skip>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${sourceEncoding}</encoding>
<debug>false</debug>
<optimize>true</optimize>
<showDepercation>true</showDepercation>
<showWarning>true</showWarning>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<finalName>${module}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/src.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>com.tmn.batch.${module}.${module}Main</mainClass>
</manifest>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
<executions>
<execution>
<id>batch</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
$ mvn clean -e
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project batch: Failed to clean project: Failed to delete C:batchtarget -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project tmn-batch: Failed to clean project: Failed to delete C:batchtarget
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)

异常消息显示:

.... has been compiled by a more recent version of 
the Java Runtime (class file version 55.0) ....

版本55.0对应于Java 11的目标版本。因此,这告诉您Maven构建代码的实际目标版本是什么。(你可以在这里查找类文件的版本号。(


POM文件是告诉Maven编译的目标平台。如果你想以Java8为目标,你可以通过设置属性来实现;例如

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

或者您在编译器插件的配置中;例如

<plugins>
<plugin>    
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>

以上是POM文件的摘录。我建议您花点时间对Maven和POM文件进行一些背景阅读。

最新更新