问题描述
$DoneFiles
但是,在我的 java -jar --illegal-access=permit target/Something.jar
中配置我的 spring boot maven 插件会给我同样的错误,就像我在没有 pom.xml
部分的情况下运行我的 cmd 一样,告诉我它被忽略了:
illegal-access=permit
我做错了什么?这个应用程序在 java 14 中运行良好,我正在升级到 java 16。除了由于缺少 <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.something.PreMain</mainClass>
<jvmArguments>
--illegal-access=permit
</jvmArguments>
</configuration>
</plugin>
JVM 参数,intelliJ 无法在调试模式下启动它之外,一切仍然运行良好。
解决方法
如果您尝试在 IntelliJ 中运行应用程序,则无需向 Maven 传递任何内容。在 IntelliJ 中,打开应用程序的运行配置,然后在 Environment->VM 选项下添加 --illegal-access=permit。请参阅附加图片,主类将是您的 @SpringBootApplication
类的完全限定位置,例如com.something.MySpringBootApplication
当您在 IntelliJ 中以调试模式启动应用程序时,您会看到类似
/Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:52737,suspend=y,server=n --illegal-access=permit -XX:TieredStopAtLevel=1...
,注意传递给您的应用的参数。
您可能想尝试将其放入属性中。试试这个:
<properties>
<jvm.options>--illegal-access=permit</jvm.options>
</properties>
然后在插件中使用如下:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.something.PreMain</mainClass>
<compilerArgs>
<arg>${jvm.options}</arg>
</compilerArgs>
</configuration>
注意:如果您要访问非法访问参数,则需要使用 argline 而不是 args。