繁体   English   中英

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

[英]Where Can I check Apache Maven Java build version? What's JNI Error?

我的 maven 有问题。maven 可以成功构建项目。 但我无法运行 mvn 构建的 jar。 我在哪里可以查看 mvn Java 构建版本? java几个版本我都没装过,我是java的新手,Java的配置在哪里可以查看?

第三个是 pom.xml。 我按照@Stephen C 的指示修改了它。但是 mvn 无法清理项目。

环境变量:

JAVA_HOME:C:\Program Files\Java\jdk1.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:\BAT\target\h-0.0.1.jar
[INFO]
[INFO] --- maven-assembly-plugin:3.1.0:single (batch) @ h ---

$"C:\Program Files\Java\jdk1.8.0_251\bin\java" -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:\batch\target -> [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:\batch\target
    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 要针对哪个目标平台进行编译。 如果要针对Java 8,可以通过设置属性来实现; 例如

<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 文件的背景知识。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM