文章目录
初始情况
文件
Main.java
public class Main {
public static void main(String[] args) {
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
执行
debug
Error:java:error:release version 5 not supported
run
Error:java:error:release version 5 not supported
mvn install(GUI)
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< org.example:test >--------------------------
[INFO] Building test 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/qbit/IdeaProjects/test/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.024 s
[INFO] Finished at: 2020-03-04T16:44:28+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test: Compilation failure: Compilation failure:
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[ERROR] -> [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/MojoFailureException
其实package都无法通过
mvn install(CLI)
执行结果和上面一致。
调整Java Compiler
操作
打开file → settings
进入 build,execution,Deployment → Compiler→ Java Compiler页面
找到per-module bytecode version下面的Target bytecode version改为11
结果
没有任何帮助
java.version
在pom.xml里添加下面没有帮助
<properties>
<java.version>11</java.version>
</properties>
no main manifest attribute
报错
在intellij下可以允许,但是打成jar后运行报错
no main manifest attribute, in qbit-1.0-SNAPSHOT.jar
MANIFEST.MF
修改这个配置文件加入Main-Class是无法解决这个问题,打开打包好的jar就会发现resource/META-INF/MANIFEST.MF根本没有被复制进去,虽然target/classes/META-INF目录下有相应文件
pom.xml
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.qbit.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Error: Unable to initialize main class
操作
引入外部的jar后
java -jar qit-1.0-SNAPSHOT.jar
报错
Error: Unable to initialize main class com.qbit.Main
Caused by: java.lang.NoClassDefFoundError: io/netty/channel/EventLoopGroup
解决方案
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>