I have an application that runs just fine when running this from the command prompt :
java -jar --illegal-access=permit target/Something.jar
However, configuring my spring boot maven plugin in my pom.xml as such gives me the same error as if I ran my cmd without the illegal-access=permit part, telling me it is being ignored :
<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>
What am I doing wrong? This app worked perfectly in java 14 and I'm in the process of upgrading to java 16. Everything still works perfectly except intelliJ not being able to launch it in debug mode due to the missing illegal-access=permit JVM argument.
If you're trying to run the application in IntelliJ, you don't need to pass anything into Maven. In IntelliJ, open the run configuration for your app and under Environment->VM options add --illegal-access=permit. See the attached image, Main class would be your fully qualified location of your #SpringBootApplication class, e.g. com.something.MySpringBootApplication
When you start your app in debug mode in IntelliJ, you'll see something like
/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..., notice the argument getting passed to your app.
You may want to try putting it in the properties instead. Try this:
<properties>
<jvm.options>--illegal-access=permit</jvm.options>
</properties>
Then use it in the plugin as follows:
<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>
Note: Instead of args, you would need to use argline if you're accessing illegal-access parameter for surefire.
Related
I am writing unit tests on a large project which I need to pass JVM arguments to, those are my JVM arguments built into the Eclipse run configuration for that project :
--module-path lib/javafx-sdk-13.0.2/lib --add-modules=javafx.controls
-javaagent:lib/aspectjweaver-1.9.5.jar
-javaagent:lib/spring-instrument-5.2.3.RELEASE.jar
My issue is that I need to add those arguments for EVERY JUnit test or testing sequence. Is there a better approach for this? Some way to not have to add those arguments manually into every new test I create?
******EDIT******
This also has the nasty side-effect of not letting me build this project at all! Maven does not use my custom JUnit run config for running the entire set of tests for the application (which works fine because I set the JVM arguments in there) but rather its own which obviously fails because the arguments are not there. That is a huge problem, is there a way to "hardcode" those JVM arguments directly into the POM somehow?
******EDIT 2******
This is my Spring-Boot-Maven-Plugin config in my POM.xml file :
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArguments>
--module-path lib/javafx-sdk-13.0.2/lib
--add-modules=javafx.controls
-javaagent:lib/aspectjweaver-1.9.5.jar
-javaagent:lib/spring-instrument-5.2.3.RELEASE.jar
</jvmArguments>
</configuration>
</plugin>
******SOLUTION******
Adding the Maven Surefire plugin and setting it up this way fixed the issue :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<argLine>
--module-path lib/javafx-sdk-13.0.2/lib
--add-modules=javafx.controls
-javaagent:lib/aspectjweaver-1.9.5.jar
-javaagent:lib/spring-instrument-5.2.3.RELEASE.jar
</argLine>
</configuration>
</plugin>
Thanks!
You can set the jvm args in the surefire plugin. Use mvn test to run tests. Something like
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<argLine>-Djava.security.policy=${basedir}/src/test/resources/java.policy</argLine>
</configuration>
</plugin>
</plugins>
More here http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#argLine
I'm using spring-boot-maven-plugin to package my REST service. I'm building the jar using mvn clean install or mvn clean package. After I decompile the jar, I don't find any of the dependencies added (I was expecting it to be a fat jar with all dependencies)
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.9.RELEASE</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>true</executable>
<finalName>myapp</finalName>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
When I run the spring boot using java -jar myapp.jar -Drun.jvmArguments="-Dspring.profiles.active=qal" I'm getting ClassNotFoundException for many of the classes. It's clear that artifact didn't build as expected. However, if I start spring boot application using maven ./mvnw spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=qal" I guess, it finds all the dependencies in target folder hence works fine. How can I fix the build issue so that I can start app using java -jar command.
EDIT: It's multi-module maven project
it seems you are using a wrong command. mvn clean package is maven command, you should use command 'repackage', it used for
Repackages existing JAR and WAR archives so that they can be executed
from the command line using java -jar
as it mentioned here https://docs.spring.io/spring-boot/docs/current/maven-plugin/repackage-mojo.html
Or probably it's plugin configuration issue. Just checked: it works with spring-boot-maven-plugin-2.0.0.RELEASE
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
Use this one
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>${start-class}</mainClass>
<executable>true</executable>
<fork>true</fork>
<!-- Enable the line below to have remote debugging of your application on port 5005
<jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
-->
</configuration>
</plugin>
I'm tring to import data from remote wsdl. I have written in maven simple code as below
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-stubs1</id>
<phase>process-classes</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlUrls>
<wsdlUrl>http://www.webservicex.com/globalweather.asmx?wsdl</wsdlUrl>
</wsdlUrls>
<packageName>com.sth.remote</packageName>
</configuration>
</execution>
</executions>
</plugin>
And what is strange in behaviour of this script is that it works only the first time. After, for instance "clean install", java code from wsdl is not generated again. And in debug mode I'm getting this output:
[DEBUG] -- end configuration --
[DEBUG] The wsdl Directory is Q:\workspace\xxx\src\wsdl
[INFO] No WSDLs are found to process, Specify at least one of the following parameters: wsdlFiles, wsdlDirectory or wsdlUrls.
How to resolve this problem ?
UPDATE:
I have noticed that this task works in Eclipse background when I delete target directory and then refresh eclipse project so that eclipse would compile code and run this task but via direct invoking mvn jaxws:wsimport not.
UPDATE 2:
What else, it sems that script running via mvn jaxws:wsimport omit my configuration because if I change for instance staleFile
<staleFile>Q:\workspace\xxx\target\jaxws\stale2</staleFile>
I still have in info in debug that default path to staleFile is in use:
<staleFile default-value="${project.build.directory}/jaxws/stale"/>
...
[DEBUG] (f) staleFile = Q:\workspace\visasin-gwt\target\jaxws\stale
Does someone have some idea what is going on ? #dienerd solution not working for me
i removed your
<id>generatestubs-1</id>
and this ran perfectly. i did a super simple pom w/ just a maven compiler & java.version 1.8. i'm not sure what you are doing but i'd take it back down to simple & add stuff in:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlUrls>
<wsdlUrl>http://www.webservicex.com/globalweather.asmx?wsdl</wsdlUrl>
</wsdlUrls>
<packageName>com.sth.remote</packageName>
</configuration>
</execution>
</executions>
</plugin>
I have a maven plugin (jaxb2) and I need to supply a jvm arg to it. I don't think there is a tag to add jvm args in the pom for it.
I know I can pass in jvm args on the command line eg: mvn clean install -Djavax.xml.accessExternalSchema=all
Is it possible to set this jvm arg in the pom so that I don't have to type it into the command line every time?
(As aside - this jvm arg is required in order for it to work with JAVA-8. It works fine with JAVA-7)
This is relevant to the new XML security properties in JAXB 1.5, introduced in Java 8. This is why your builds now fail on Java 8 but work with Java 7.
If you're using my maven-jaxb2-plugin, please upgrade to the version 0.9.0 or later (current is 0.10.0). It has now a accessExternalSchema switch (default is all).
This sets precisely javax.xml.accessExternalSchema=all.
Please see the documentation.
I came across this issue while working with jaxb2-maven-plugin. I found a related jira issue for maven-jabx2-plugin - https://java.net/projects/maven-jaxb2-plugin/lists/issues/archive/2014-03/message/0
According to this issue Stephan202 suggested using properties-maven-plugin which worked like charm. Here is a sample code from his post -
<plugin>
<!-- We use this plugin to ensure that our usage of the
maven-jaxb2-plugin is JDK 8 compatible in absence of a fix
for https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN-80. -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<id>set-additional-system-properties</id>
<goals>
<goal>set-system-properties</goal>
</goals>
</execution>
</executions>
<configuration>
<properties>
<property>
<name>javax.xml.accessExternalSchema</name>
<value>file,http</value>
</property>
</properties>
</configuration>
</plugin>
Re; the post - "I needed a solution that doesn't use alpha versions as that is my companies rules. –"
Changing the version to 1.0 & the value to 'all' got it working for me:
<plugin>
<!-- We use this plugin to ensure that our usage of the
maven-jaxb2-plugin is JDK 8 compatible in absence of a fix
for https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN-80. -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<!--
<version>1.0-alpha-2</version> -->
<version>1.0.0</version>
<executions>
<execution>
<id>set-additional-system-properties</id>
<goals>
<goal>set-system-properties</goal>
</goals>
</execution>
</executions>
<configuration>
<properties>
<property>
<name>javax.xml.accessExternalSchema</name>
<value>all</value>
</property>
</properties>
</configuration>
</plugin>
It has worked for me :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<vmArgs>
<arg>-Djavax.xml.accessExternalSchema=all</arg>
</vmArgs>
<keep>true</keep>
<verbose>true</verbose>
<wsdlDirectory>${project.build.directory}/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>ServiceWsService.wsdl</wsdlFile>
</wsdlFiles>
<bindingFiles>
<bindingFile>custom-binding.xml</bindingFile>
<bindingFile>custom-binding2.xml</bindingFile>
</bindingFiles>
</configuration>
</execution>
</executions>
</plugin>
Take a look at the Maven Compiler Plugin. Specifically you should be able to use the <compilerArgument> element to pass settings to the compiler.
See http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html for examples.
If you are trying to change the behavior of the JVM that is running Maven itself, add options to MAVEN_OPTS in the environment before launching mvn.
For maven-jaxb2-plugin version 2.5.0 trying to generate from DTD and spitting
org.xml.sax.SAXParseException: External parsing is disabled. Cannot
parse URI: ...
it helped adding the following to plugin configuration
<configuration>
...
<externalEntityProcessing>true</externalEntityProcessing>
</configuration>
Suppose I have a profile
<profile>
<id>ak</id>
<properties>
<db.host>localhost</db.host>
<db.name>ak_cit</db.name>
<db.user>user</db.user>
<db.password>pass</db.password>
</properties>
</profile>
And somewhere in root of pom.xml there are default values
<db.host>NOT_DEFINED</db.host>
<db.name>NOT_DEFINED</db.name>
<db.host.reporting.db>NOT_DEFINED</db.host.reporting.db>
<db.name.reporting.db>NOT_DEFINED</db.name.reporting.db>
The problem I have while launching my application mvn -Pak clean install is that I get an exception because database NOT_DEFINED does not exist. Same command works totally fine on ubuntu or windows. After asking around my co-workers, I've found that some of them are experiencing same problem on OS X.
The only solution which somewhat works for me right now is passing variables through a command line: -Ddb.host=localhost -Ddb.user=user -Ddb.password=pass -Ddb.name=ak_cit. The problem with this solution is that there are a lot of properties which need to be passed through.
does anybody knows how to fix this or what might be causing such issue?
The problem was in settings.xml. was overriding my selected profiles. After checking my other systems I've noticed that there were no profiles defined in settings.xml.
Huge help in figuring this out was plugin echoproperties
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>