Using mvn and the maven-assembly-plugin, I create a .jar with dependencies and run it like this:
java -cp ../target/module-jar-with-dependencies.jar module.Launcher --project=example --network=toy_ags_network.sif
I wanted to create a mvn profile that does exactly that. So in my pom.xml I added this:
<profiles>
<profile>
<id>runExample</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>module.Launcher</mainClass>
<arguments>
<argument>--project</argument>
<argument>example</argument>
<argument>--network</argument>
<argument>toy_ags_network.sif</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<mainClass>com.test.Startup</mainClass>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
So, when I do: mvn compile -P runExample I would get the same results. It seems though that some classes from a dependency are not fully loaded or something and this throws exceptions, etc. and when I don't include that particular code that uses these other classes then everything is fine. I want to make sure that with my way above I have included all dependencies, e.g. that the java command and the maven one are equal.
Edits
I managed to have a simple plugin that behaves the same way as the java command, by running mvn exec:exec:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<argument>target/module-jar-with-dependencies.jar</argument>
<argument>module.Launcher</argument>
<argument>--project</argument>
<argument>example</argument>
<argument>--network</argument>
<argument>toy_ags_network.sif</argument>
</arguments>
</configuration>
</plugin>
But I want a profile with that plugin inside, that's what I still not have!
The correct configuration for the pom.xml is:
<profiles>
<profile>
<id>runExample</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<argument>target/module-jar-with-dependencies.jar</argument>
<argument>module.Launcher</argument>
<argument>--project</argument>
<argument>example</argument>
<argument>--network</argument>
<argument>toy_ags_network.sif</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Thus, running: mvn compile -P runExample is the same as:
java -cp ../target/module-jar-with-dependencies.jar module.Launcher --project=example --network=toy_ags_network.sif
Related
I created 4 run profiles that contain only the maven-exec plugin with goal java to run my war with different startup parameters. Problem is that profiles are always triggering rebuilding my war file, and it causes failure because the war file is in use when at least one of these profiles is already running. I don't want to rebuild war when I run these profiles. Is it possible to run the build profile without building war and just run the plugins in the profile?
<profiles>
<profile>
<id>devAdmin</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>main.Main</mainClass>
<arguments>
<argument>-admin</argument>
</arguments>
...
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>devCluster</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>main.Main</mainClass>
<arguments>
<argument>-cluster</argument>
</arguments>
...
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>devClient</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>main.Main</mainClass>
<arguments>
<argument>-client</argument>
</arguments>
...
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>devWeb</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>main.Main</mainClass>
<arguments>
<argument>-web</argument>
</arguments>
...
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Thank you so much for help :)
Execute just the single goal: mvn exec:java -PdevClient
When building my service project with jib command mvn clean compile jib:build it's give the following error:
Failed to execute goal
com.google.cloud.tools:jib-maven-plugin:1.0.2:build
(build-image-and-tag-image) on project my-service: Multiple valid
main classes were found: com.myservice.MyServiceApplication,
io.swagger.Swagger2SpringBoot, perhaps you should add a mainClass
configuration to jib-maven-plugin -> [Help 1]
However I have set the main classes for spring-boot
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.myservice.MyServiceApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
It's still doesn't work.
I've tried to add it to the jib config to:
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<container>
<mainClass>com.myservice.MyServiceApplication</mainClass>
</container>
</configuration>
<executions>
<execution>
<id>build-image-and-tag-image</id>
<phase>package</phase>
<goals>
<goal>dockerBuild</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
It's still doesn't work.
Any other way to force jib to ignore the other class and use com.myservice.MyServiceApplication instead.
Note: mvn clean install work fine and I have no problem using it has a stand alone spring boot app.
The main class need to be set in the < plugins > define in < build > of the pom.xml file.
It would look like this to fix the problem:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.myservice.MyServiceApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<container>
<mainClass>com.myservice.MyServiceApplication</mainClass>
<ports>
<port>8080</port>
</ports>
<environment>
<application.title>${project.name}</application.title>
<application.version>${project.version}</application.version>
</environment>
<jvmFlags>
<jvmFlag>-javaagent:/usr/local/newrelic/newrelic.jar</jvmFlag>
</jvmFlags>
</container>
</configuration>
</plugin>
.... (more plugin)
</plugins>
</build>
I am trying to run a pom.xml that ultimately runs my java main class. On running the pom.xml I am getting the error:-
The pom.xml looks something like this (main class resides within ScreenShotUtility package):-
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>ScreenShotUtility.ScreenShotutility2</mainClass>
<arguments>
<argument>arg0</argument>
<argument>arg1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
Add
<build>
<defaultGoal>exec:java</defaultGoal>
...
</build>
to the pom and run
mvn
Why exec:java? Because it is a shorthand for exec-maven-plugin:java what is the name of the build-plugin.
I have a Question about the Exec Maven Plugin.
I want to execute my setup.iss file (generated with Inno Setup) with the exec maven plugin.
One question: Should I define a path for my file in my pom or in which destination the setup.iss has to be put for maven to find it?
Here is the code from my pom:
<profiles>
<profile>
<id>exec</id>
<activation>
<property>
<name>exec</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>de.audi.analysis.main.Main</mainClass>
<executable>ISCC.exe</executable>
<workingDirectory></workingDirectory>
<arguments>
<argument>firstsetup.iss</argument>
</arguments>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
The exec-maven-plugin is simply calling the iscc.exe with the arguments you provide. In this instance the plugin would execute iscc.exe firstsetup.iss
I believe it assumes the firstsetup.iss will be in the ${project.basedir} of the maven project (where the pom.xml is) or the workingDirectory if provided. A specific file path can be passed with argument as well.
<argument>${project.basedir}/<some-path>/firstsetup.iss</argument>
The problem was that i have to add all the dll to my solution. After adding all inno dll files it works fine and i get build success. Thank you for your Answer Adam. Here is my pom configuration:
<configuration>
<executable>src/main/resources/innosetup/ISCC.exe</executable>
<workingDirectory>src/main/resources/innosetup</workingDirectory>
<arguments>
<argument>audience-setup1.iss</argument>
</arguments>
</configuration>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
I am developing a java web application (No Spring).I wanted to use separate db for production and testing.I have two files in src/main/resources - env.properties and env.test.properties.
I have defined the profile in pom.xml as mentioned in https://maven.apache.org/guides/mini/guide-building-for-different-environments.html.
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<delete file="${project.build.outputDirectory}/environment.properties"/>
<copy file="src/main/resources/environment.test.properties"
tofile="${project.build.outputDirectory}/environment.properties"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>test</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
However, when I run test by maven test -Ptest, I see that my test is getting executed with the db from env.properties and then after completion of test , the profile switching happens.
I am also having a jebkins pipeline which builds tests and deploys.
Am I missing something here ? What is the correct way to read the properties from env.test.properties(activate the profile and run test) ?
Thanks a lot.
You're doing this the hard way.
Get rid of the profiles and move the file from src/main/resources/environment.test.properties to src/test/resources/environment.properties
Resources in src/test/resources/ will be found and loaded before those in src/main/resources when unit tests are being executed.