How to pass add-module to spring boot application? - spring

I am using a maven dependency which require me to pass add-module during compilation and runtime as mentioned here.
Can someone let me know how can I pass --add-module option to a spring boot application during compilation and runtime? It will be good if I can control both compilation and runtime behaviour from the pom.xml.

For compilation you can use the maven-copmiler-plugin in your build of your pom.xml.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<parameters>true</parameters>
</configuration>
</execution>
</executions>
<configuration>
<source>14</source>
<target>14</target>
<compilerReuseStrategy>reuseSame</compilerReuseStrategy>
<compilerArgs>
<arg>--enable-preview</arg>
<arg>--add-modules=jdk.incubator.foreign</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
As you see I have included also the --enable-preview. In JDK14 as reported in JEPS 370 it is not needed since this is not a preview feature. But keep an eye on it since it might be needed in other jdk versions since in some versions this belongs in preview features.
As for runntime a spring-boot application is normally just a .jar executable file which you start with the normal java -jar myApp.jar command.
According to oracle documentation, the format of the command line is
To execute a JAR file:
java [options] -jar jarfile [args...]
So the command you want would be
java --add-modules jdk.incubator.foreign -jar myApp.jar

Related

Spring boot Jar cannot work in Debian 8.1 via /etc/init.d/myapp, But work in CentOS

I use the spring-boot-starter, my pom is:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
when I execute service myapp start, the message shown:
/etc/init.d/weacar: 2: /etc/init.d/weacar: Syntax error: ")" unexpected
But it's ok In CentOS, Why this happen? Is it bug of Spring-boot?
Thanks
I got a similar error when I was trying to start a regular/fat boot jar accidentally using this approach. I had changed my build.xml to create an executable jar, but I had not updated the /var folder on the Linux machine with the new executable jar. Once I did a 'mvn clean package', and then copied the resulting new executable jar to the Linux machine I was trying this on, 'service start' worked as expected. 

Eclipse, WebSphere7.0, Maven: AspectJ does not weave code during hot deployment

My System Information:
IDE: Eclipse Blue 10.0,
Server: Websphere 7.0
Build Management Tool: Maven 3.0
I perform compile time weaving in my Maven project using below configuration:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<!-- <goal>test-compile</goal> -->
</goals>
</execution>
</executions>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>com.xxx.logger</groupId>
<artifactId>my-aspect-logger</artifactId>
</aspectLibrary>
</aspectLibraries>
<showWeaveInfo>true</showWeaveInfo>
<outxml>true</outxml>
<Xlint>warning</Xlint>
<verbose>true</verbose>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
During development, I use to add my EAR file in exploded mode in Eclipse itself by following below path:
Windows > Show View > Servers > WebSphere 7 > Right Click > Add Deployment
I am facing one issue that whenever I change my java classes those are compiled and hot deployed in server. But, they are not re-weaved. But if I remove the EAR, build my project from command prompt and re-deploy it then it works properly.
Can somebody please help me to resolve this issue.
I'm not familiar with AspectJ but MyEclipse does not execute maven goals to build and deploy projects (though you can add builders, which may invoke maven externally - note that the Maven Project Builder doesn't execute Maven goals), so processing specified in your pom will not be executed automatically, though, obviously, you can run maven goals from the Run As menu item. So changed Java classes will be recompiled using the configured JRE and redeployed. Any additional processing specified in the pom will not be run. However, you say that removing the deployment and then re-deploying actually works, so I'm not sure how the re-weaving gets done, if you don't execute a maven build before redeployment.

Specify javaagent argument with Maven exec plugin

I have a similar question to: this previous question
I am converting a Java project using Netbeans to Maven. In order to launch the program, one of the command-line arguments we need is the -javaagent setting. e.g.
-javaagent:lib/eclipselink.jar
I'm trying to get Netbeans to launch the application for development use (we will write custom launch scripts for final deployment)
Since I'm using Maven to manage the Eclipselink dependencies, I may not know the exact filename of the Eclipselink jar file. It may be something like eclipselink-2.1.1.jar based on the version I have configured in the pom.xml file.
How do I configure the exec-maven-plugin to pass the exact eclipselink filename to the command line argument?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Xmx1000m</argument>
<argument>-javaagent:lib/eclipselink.jar</argument> <==== HELP?
<argument>-classpath</argument>
<classpath/>
<argument>my.App</argument>
</arguments>
</configuration>
</plugin>
I figured out a way that seems to work well.
First, setup the maven-dependency-plugin to always run the "properties" goal.
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>getClasspathFilenames</id>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
Later on, use the property it sets as documented here with the form:
groupId:artifactId:type:[classifier]
e.g.
<argument>-javaagent:${mygroup:eclipselink:jar}</argument>
Simply define a property for the eclipse link version and use the property in your <dependency> and the exec plugin:
<properties>
<eclipselink.version>2.4.0</eclipselink.version>
</properties>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>${eclipselink.version}</version>
</dependency>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Xmx1000m</argument>
<argument>-javaagent:lib/eclipselink-${eclipselink.version}.jar</argument>
<argument>-classpath</argument>
<classpath/>
<argument>my.App</argument>
</arguments>
</configuration>
</plugin>
the maven-dependency-plugin and exec-maven-plugin should be put under the node ,otherwise it will not work

How to appoint specific jdk version for maven to build my project?

My problem is: Test cases are green on local, but some are failed on hudson server because of non-supported jdk version. Local is ibm jdk1.6 sr4 windows, but hudson server installed ibm jdk1.6 sr9 linux. "This Java virtual machine is not supported for use with Blaze Advisor because the implementation of java.beans.Introspector failed to pass validation."
I was told Hudson server cannot change to other jdk, so I am think is there any work around to bypass those failure?
Can I tell maven to compile project with specific jdk? Like, 1.6 version with sr4, instead of sr9. Also I need maven to download sr4 as dependency coz there is no this version on server.
Seems it's hard to do this as I searched out. So what else option i could have?
Thanks for any suggestion.
Maven should start with the java specified in JAVA_HOME if you need to use a different version I would use the toolchain plugin to run your build with a specified jdk version. It will require the version be already installed on the server though.
http://maven.apache.org/guides/mini/guide-using-toolchains.html
You will need to add the plugin to your pom and add a toolchains.xml file.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.5</version>
<vendor>sun</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
toolchains.xml file added to .m2 folder which specifies the install location for the jdk
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>1.5</version>
<vendor>sun</vendor>
<id>default</id>
</provides>
<configuration>
<jdkHome>/path/to/jdk/1.5</jdkHome>
</configuration>
</toolchain>
Are you sure? The Hudson should support switching JDKs, I've done it in Jenkins. In worst case you could specify JAVA_HOME env variable in the Hudson build. It is impossible to change in maven, because maven itself needs JDK to start.
You can configure this in your maven-compiler-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
You can also use profiles -P to set versions based on environments.

JAXB2 Maven Plugin not reading Configuration

I am trying to generate some JAXB classes via my schema. I have my jaxb2 maven plugin configured the following way.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>aces.soa.schema</packageName>
<generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
<schemaDirectory>${basedir}/src/main/resources/schema/ea</schemaDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
When running the mvn jaxb2:xjc it complains that it cannot find the Schema, which is in the src/main/resources/schema/ea directory. When executing mvn -X jaxb2:xjc I see that the variables are not getting set at all. Is there something else I need to do to configure the plugin propoerly?
There's an issue with running this plugin with configuration elements in the execution elements, when the plugin is being called using:
mvn jaxb2:xjc
A workaround for me was using:
mvn generate-sources
Actually no. Having configuration outside executions configures the plugin globally. Here is the doc: http://mojo.codehaus.org/jaxb2-maven-plugin/usage.html
So, you should be able to configure each execution but it does not work some reason :( The question is still valid

Resources