I have spring boot app and i want to run it as service. I am using tanuki wrapper to do so :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.8.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate-daemons</goal>
</goals>
</execution>
</executions>
<configuration>
<logsDirectory>logs</logsDirectory>
<daemons>
<daemon>
<id>DataCopier</id>
<wrapperMainClass>org.tanukisoftware.wrapper.WrapperSimpleApp</wrapperMainClass>
<mainClass>com.myProject.mainClass</mainClass>
<platforms>
<platform>jsw</platform>
</platforms>
</daemon>
</daemons>
</configuration>
</plugin>
However how do i run this? I included it as plugin. I tried to mvn install it to see if this generates something but it does not generate anything in target folder. How do i run this then?
Related
I have a pom file that correctly generates the grpc and protobuf source files I need in target/generated-sources when run from the command line. But when I build in vscode those directories are empty and references to the protobufs are undefined. Here's the section of my pom file that builds the grpc source.
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
I added the following based on what I read in other posts to prevent vscode/eclipse from removing the generated source directories
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/protobuf/grpc-java</source>
<source>/target/generated-sources/protobuf/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
When vs-code builds, the target generated-source directories are there, but there is no source in them. We had a similar problem with intellij but were able to work around it by running the maven command line build before opening intellij but that does not seem to work for vscode.
Use protoc-jar-maven-plugin instead.
Sample usage please view protoc-jar-maven-plugin.
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 have a maven project with one war and several ear projects. Each ear project requires a slightly different war/WEB-INF/web.xml. Each ear's pom.xml uses com.google.code.maven-replacer-plugin:replacer and org.codehaus.mojo:truezip-maven-plugin to replace tokens in the web.xml, and then place that new web.xml in the final <project>-app.ear/web.war/WEB-INF. This all works great with building and creating the final EAR artifacts.
The problem I'm having is that when I run (using Netbeans, but that shouldn't matter), the web.xml used for deployment (<project>/target/gfdeploy/first-app/web_war/WEB-INF/web.xml) is the tokenized version. I tried adding execution phases for deploy, but that doesn't work.
How can I ensure that the run deploy has the modified web.xml so I can test my app during development?
Here is the relevant parts of the ear pom.xml:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>package-replace</id>
<phase>package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
<execution>
<id>deploy-replace</id>
<phase>deploy</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.parent.basedir}/${web.xml}</file>
<outputFile>${project.build.directory}/${web.xml}</outputFile>
<replacements>
<replacement>
<token>#REALM_NAME#</token>
<value>${web.realm}</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>truezip-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>package-replace-web-xml</id>
<goals>
<goal>copy</goal>
</goals>
<phase>package</phase>
<configuration>
<files>
<file>
<source>${project.build.directory}/${web.xml}</source>
<outputDirectory>${project.build.directory}/${project.build.finalName}/${web.zip}/WEB-INF</outputDirectory>
</file>
</files>
</configuration>
</execution>
<execution>
<id>package-replace-web</id>
<goals>
<goal>copy</goal>
</goals>
<phase>package</phase>
<configuration>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}/${web.zip}</source>
<outputDirectory>${project.build.directory}/${project.build.finalName}.ear</outputDirectory>
</file>
</files>
</configuration>
</execution>
<execution>
<id>deploy-replace-web-xml</id>
<goals>
<goal>copy</goal>
</goals>
<phase>deploy</phase>
<configuration>
<files>
<file>
<source>${project.build.directory}/${web.xml}</source>
<outputDirectory>${project.build.directory}/gfdeploy/${project.artifactId}/web-${project.version}_war/WEB-INF</outputDirectory>
</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
I suggest you to keep your default src/main/webapp/WEB-INF/web.xml fully functional for running during development. Then, keep a similar file called src/main/webapp/WEB-INF/web-ear.xml with all the replacement preparation.
Wrap all your replacement plugin strategy inside a maven profile and targeted to the web-ear.xml file. Add to this profile a maven-war-plugin configuration that will use the alternative web-ear.xml file during build, instead of the default web.xml (check: http://maven.apache.org/plugins/maven-war-plugin/):
<profiles>
<profile>
<id>change-war-profile</id>
<build>
<plugins>
<!-- all your replacement plugins here -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src/main/webapp/WEB-INF/web-ear.xml</webXml>
</configuration>
</plugin>
<plugins>
</build>
</profile>
</profiles>
Make sure to activate this profile during the EAR maven build:
mvn package -Pchange-war-profile
you can run your war with the jetty-maven-plugin choosing the run-war goal.
That goal run the packaged war.
See: https://www.eclipse.org/jetty/documentation/9.4.x/jetty-maven-plugin.html#running-assembled-webapp-as-war
First of all, deploy phase (of the build lifecycle) means deployment a production ready artifact to the remote Maven repository (e.g., Nexus or Artifactory). Roughly speaking, artifact deploy can be treated as copying the artifact. Read the Introduction to the Build Lifecycle for more details.
Secondly, Apache Maven does not support application deploy to the application server out-of-the-box. However, there are several ways to do it, depending on the application server you use. Which one do you use?
Special plugin can be found for JBoss Application Server - jboss-as-maven-plugin. See usage example:
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.9.Final</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
...
</project>
Similar plugin can be found for GlassFish Server: glassfish-maven-plugin.
Also, if this is acceptable for you, you can perform 2-steps deploy from Netbeans:
Build the project: run mvn package with all your plugins are configured at package phase.
Deploy the project: run application on the app server from Netbeans if it is supported (See NetBeans Java EE Servers Support page).
Hope this helps.
In my maven project I use the pgp plugin to sign my jars. I need to do this only when deploying to remote repo, but not when installing to local repo. So I tried to set the phase to deploy.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
With that configuration maven first deploys to remote repo and theh signs my jars...
I read that plugins are executed in the order they are defined in POM file, so I tried to configure deploy-plugin after sign plugin, but that didnt have any effect
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
How can I achieve that sign plugin is not executed on install, but on deploy before artifacts are uploaded? I'm using maven3.
First i would suggest to update maven-gpg-plugin to an more up-to-date version cause this version 1.1 is of 2010..Apart from that i would suggest to keep the defaults of the plugins which means the binding of maven-deploy-plugin as the deploy life cycle and for the maven-gpg-plugin the verify life cycle phase which is not ideal if you have integration tests. In such cases it makes sense to define a profile which is activated only in release cases to prevent confusions with integration test.
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
<executions>
<execution>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
I have seen project putting the gpg-plugin in verify phase.
May I know what version of Maven you are using? I believe the plugin in same phase should run in order it is defined, after Maven 2.0.10 (or probably earlier). However as maven-deploy-plugin is default binding for deploy phase, I am not clear if the ordering will be in effect
I am trying to attach an exec process to a maven build. I want to build a secondary dependency (that is actually a Clojure project build with maven) every time I build the maven project.
Currently, I have the pom.xml below, but the exec process is just not running. The maven documentation is not that much help.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>compile-with-lein</id>
<phase>initialize</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>lein</executable>
<commandlineArgs>install</commandlineArgs>
<workingDirectory>../nrepl-clojure</workingDirectory>
</configuration>
</plugin>