execute java -jar name.jar -p myproject by maven - maven-plugin

by command line in the directory of myproject I run java -jar cnesreport.jar -p myproject and it works. Now I want to execute a mvn exec: exec or exec: java and I do not know how I should modify the pom.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>C:/Users/jvegacas/git/web/web/target</argument>
<argument>-p</argument>
<argument>C:/Users/jvegacas/git/web</argument>
</arguments>
</configuration>
</plugin>
Command execution failed.

Use <goal>exec</goal> (since java:
execute(s) Java programs in the same VM
)
<executable>java</executable> could work, but only when it is on the PATH
arguments, like this:
<arguments>
<argument>-jar</argument>
<!-- !! -->
<argument>target/cnesreport.jar</argument>
<argument>-p</argument>
<!-- if you mean rather the "location" than the "name", then:
<argument>.</argument>
or <argument>${baseDir}</argument>
-->
<argument>myproject</argument>
</arguments>
#See

Related

Upload React Application to Nexus

I built a React-Application using create-react-app.
The production build is done on Jenkins via:
npm install --prod
npm run build
Then I have the "ready to deploy" artifact.
But how can I get this artifact on my Nexus-Server?
Can i use the version from package.json?
Do I have to make a zip or something like that on my own before uploading?
This would be pretty nice to have a history and it would be easier/faster to build dockers from the artifact on nexus than building again.
How you guys solved that?
Thanks for answers.
I know this question is old, but it might help others.
I recently had to do something similar. My approach was:
Convert the project to a Maven one
Configure my private repository in pom.xml
<distributionManagement>
<snapshotRepository>
<id>RepoId</id>
<url>http://.../repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>RepoId</id>
<url>http://.../repositories/releases/</url>
</repository>
</distributionManagement>
Configure maven clean plugin to empty the build directory
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>build</directory>
<includes>
<include>**/*</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
Configure maven jar plugin to skip the jar creation
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
Integrate frontend-maven-plugin - my project needed yarn, but it can also run with npm
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.12.1</version>
<executions>
<!-- install node & yarn -->
<execution>
<id>install node and yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<configuration>
<nodeVersion>v16.13.0</nodeVersion>
<yarnVersion>v1.22.17</yarnVersion>
</configuration>
</execution>
<!-- yarn install -->
<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
</execution>
<!-- yarn run build -->
<execution>
<id>yarn run build</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
Integrate maven assembly plugin in order to pack everything under build directory into a zip file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<!-- pack everything under /build into a zip -->
<execution>
<id>create-distribution</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
where assembly.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>build</directory>
</fileSet>
</fileSets>
</assembly>
Finally run mvn clean deploy in order to get the zip file uploaded to nexus.
Also, I found this solutions for synchronizing the package.json version with the pom.xml version, but I did not use it.

Wildfly-Swarm enable debug

I've managed to convert my "war" application to a hollow jar.
My biggest issue is that even after following the documentation, still cannot enable debug mode (my desired port is 8784)
I am pretty sure that I am missing something but ... what?
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${wildfly-swarm.version}</version>
<executions>
<execution>
<id>package</id>
<goals>
<goal>package</goal>
</goals>
<configuration>
<hollow>true</hollow>
<properties>
<swarm.debug.port>8784</swarm.debug.port>
<debug.port>8784</debug.port>
<swarm.debug.bootstrap>true</swarm.debug.bootstrap>
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
</properties>
</configuration>
</execution>
</executions>
</plugin>
The swarm.sebug.port property is only relevant when starting the application via the Swarm Maven plugin, or when using the Swarm Arquillian adapter. When starting the application using java -jar myapp-swarm.jar, you need to use the standard Java way of enabling remote debugging, i.e. something like java -Xdebug -agentlib:jdwp=transport=dt_socket,address=8784,server=y,suspend=n -jar myapp-swarm.jar.
You may want to look into:
https://issues.jboss.org/browse/THORN-1321
or
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206848015-Breakpoints-not-working-when-debugging-simple-Java-EE-app-on-wildfly?page=1#community_comment_360000176459
The first link is the relevant one. I am including the second one just for further information if you are using IntelliJ for IDE.
Briefly, here is my pom configuration:
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${version.wildfly.swarm}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
<configuration>
<debugPort>5005</debugPort>
<properties>
<swarm.debug.port>5005</swarm.debug.port>
</properties>
</configuration>
</plugin>
After starting the application with the mvn swarm plugin, I am connecting with a remote debugger.
Good luck!
Edit (2019.05.31):
My current setup for debugging in the pom.xml is the following:
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${version.wildfly.swarm}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArguments>
<jvmArgument>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArgument>
</jvmArguments>
</configuration>
</plugin>

maven-jarsigner-plugin Enter Passphrase for keystore

I am using maven-jarsigner-plugin to sign my applet jar. When i run "maven clean install" my build fails and gives following error.
[DEBUG] 'cmd.exe /X /C ""C:\Program Files\Java\jdk1.6.0_33\jre\..\bin\jarsigner.exe" -keystore mykeystore -keypass '*****' C:\myproject\target\myapplet-1.0.0.jar applet"'
[INFO] jarsigner: you must enter key password
[WARNING] Enter Passphrase for keystore:
following is my maven configuration.
<plugin>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>sign</id>
<phase>install</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>mykeystore</keystore>
<alias>myapplet</alias>
<keypass>mykeypass</keypass>
</configuration>
</plugin>
I can see it prompts for password.
please let me know what i have missed in this configuration
Are you missing
<storepass>mystorepass</storepass>
in
<configuration>
<keystore>mykeystore</keystore>
<alias>myapplet</alias>
<keypass>mykeypass</keypass>
<storepass>mystorepass</storepass>
</configuration>
?

Pass command line Params in mvn exec:exec

I am amazed that what should have been a very easy job is turning into a very annoying task for me. All i need is to pass few command line parameters to my maven exec:exec plugin. unfortunately hours of googling has not helped at all.
Here is my plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>-javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar</argument>
<argument>-Xmx256m</argument>
<argument>com.myPackage.Myclass</argument>
</arguments>
</configuration>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
Now from the command prompt i am typing in:
mvn exec:exec -Dexec.args=-Dmy.property=myProperty
I also tried:
mvn exec:exec -Dexec.arguments=-Dmy.property=myProperty
And many other things. However nothing seems to be working. I know that exec:exec runs in a separate VM but as per the documentation -Dexec.args should work for me. Can someone please suggest where i am going wrong?
Two ways to pass command line arguments into mvn:exec:
Method 1, on the command line:
mvn exec:java -Dexec.mainClass="com.myPackage.myClass" -Dexec.args="command line arguments"
Method 2, in the maven POM file:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>com.myPackage.myClass</mainClass>
<commandlineArgs>command line arguments</commandlineArgs>
</configuration>
</plugin>
</plugins>
</build>
Then on the command line all you have to do is run:
mvn exec:java
Good luck.
I was able to get JVM args working for exec:exec using the following after reading this article:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Dhttp.proxyHost=myproxy.example.com</argument>
<argument>-Dhttp.proxyPort=8080</argument>
<argument>-classpath</argument>
<classpath />
<argument>com.example.Main</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
why not use system property?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>bobo.Abc</mainClass>
<arguments>
<argument>argument1</argument>
</arguments>
<systemProperties>
<systemProperty>
<key>jvmProperty1</key>
<value>dev</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
If you want to pass command line arguments to Java VM use <commandlineArgs> tag instead of <arguments>. Maven Exec Plugin
Cheers
I use the following command line setting to pass arguements to my Main-Class with the exceution plugin.
mvn clean install -Dexec.arguments="arg0"
I don't think the selected answer solves the problem. Here is my somewhat hacky solution that works:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>-Xmx256m</argument>
<argument>com.myPackage.Myclass</argument>
<argument>${myProperty1}</argument> <!-- variable args here!!! -->
<argument>${myProperty2}</argument>
</arguments>
</configuration>
<executions>
<execution>
<id>myExecution</id> <!-- defined an id here! -->
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
Now you can simply execute passing the arguments.
mvn exec:exec#myExecution -DmyProperty1=XXX -DmyProperty2=YYY
The problem is that you use -Dexec.args on the command line and it overrides the <arguments> given in pom.xml. You can use either of them, not both.

How to install/deploy artifacts compiled by make-maven-plugin

I'm using the make-maven-plugin to build a software written in C with Maven. My goal is to automatically install and deploy the source tarball AND the binary artifact to the Maven repository when I run mvn install and mvn deploy. My current pom.xml looks like this:
<project>
<groupId>myGroup</groupId>
<artifactId>myProject</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>make-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<configuration>
<destDir>${project.build.directory}/dest</destDir>
<workDir>${basedir}</workDir>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>make-dist</goal>
</goals>
<configuration>
<skipDist>false</skipDist>
<sourceArchive>${project.name}-${project.version}.tar.bz2</sourceArchive>
<sourceArchivePath>${project.build.directory}</sourceArchivePath>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I package the project then I have the following files in the target directory:
myProject-2.0.bin (The compiled binary artifact)
myProject-2.0.tar.bz2 (The source tar ball)
When running mvn install then the created source tar ball and the POM file is installed to the local maven repository. How can I tell Maven to also install the binary file? I don't want to copy it by hand.
Attach the binary file as an artifact using build-helper-maven-plugin

Resources