Could anyone provide simple configuration of Jersey and Embedded Tomcat in:
1) pom.xml
2) main method
I was trying to find it in google search, but they propose to use grizzly, glassfish and etc.
Thanks a lot.
I would go for webapp-runner to run the web app. It deploys the maven generated war from /target into a built in tomcat container. This is how java applications gets deployed on Heroku.
pom plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>7.0.34.1</version>
<destFileName>webapp-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Dependency:
<dependency>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>7.0.34.1</version>
<scope>provided</scope>
</dependency>
to run the application after mvn clean package
java -jar target\dependency\webapp-runner.jar target\myapp.war
Related
UPDATE - July 2021:
While the accepted answer using the dependency plugin was the best solution at the time, the answer from #ltlBeBoy leverages the 'copyDependencies' support since added to liberty-maven-plugin. Using 'copyDependencies' is usually a better solution, since it is integrated into the "dev mode" loop and less verbose (at the expense of supporting fewer options than the dependency plugin).
ORIGINAL QUESTION
I need to copy derby.jar into Open Liberty shared directory
${project.build.directory}/liberty/wlp/usr/shared/resources/. I have the following setup in the pom.xml file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-derby-dependency</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>derby</includeArtifactIds>
<outputDirectory>${project.build.directory}/liberty/wlp/usr/shared/resources/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
and the part for configuring open liberty
<plugin>
<groupId>net.wasdev.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>${openliberty.maven.version}</version>
<executions>
<execution>
<id>package-server</id>
<phase>package</phase>
<goals>
<goal>create-server</goal>
<goal>install-apps</goal>
<goal>package-server</goal>
</goals>
<configuration>
<outputDirectory>target/wlp-package</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<assemblyArtifact>
<groupId>io.openliberty</groupId>
<artifactId>openliberty-runtime</artifactId>
<version>${openliberty.version}</version>
<type>zip</type>
</assemblyArtifact>
<configFile>src/main/liberty/config/server.xml</configFile>
<appArchive>${project.build.directory}/${final.name}.war</appArchive>
<packageFile>${project.build.directory}/${final.name}.jar</packageFile>
<include>runnable</include>
<serverName>${final.name}</serverName>
<installAppPackages>project</installAppPackages>
<configDirectory>${project.basedir}/src/main/liberty/server</configDirectory>
<bootstrapProperties>
<project.name>${final.name}</project.name>
<jwt.issuer>https://server.example.com</jwt.issuer>
</bootstrapProperties>
</configuration>
</plugin>
With this setup I have to execute mvn package goal twice. It looks like that when liberty-maven-plugin is executed the ${project.build.directory}/liberty/wlp/usr/shared/resources/ folder is removed if there is no liberty server under liberty/wlp/.
Maven LOG:
[INFO] --- maven-dependency-plugin:2.10:copy-dependencies (copy-derby-dependency) # account ---
[INFO] Copying derby-10.15.1.3.jar to /Users/anton/github/account/target/liberty/wlp/usr/shared/resources/derby-10.15.1.3.jar
and after it
[INFO] --- liberty-maven-plugin:2.2:create-server (package-server) # account ---
[INFO] CWWKM2110I: Uninstalling: /Users/anton/github/account/target/liberty/wlp.
Can someone please help me with this?
Here's an example from the Session Cache guide from OpenLiberty.io showing how this can be done. The example is getting a hazelcast.jar, but it could be used for any jar hosted in maven.
https://github.com/OpenLiberty/guide-sessions/blob/master/finish/pom.xml
<!-- package hazelcast.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>${hazelcast.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/liberty/wlp/usr/shared/resources</outputDirectory>
<destFileName>hazelcast.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/liberty/wlp/usr/shared/resources</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</plugin>
As already stated in my other answer, starting from version 3.3 of the Liberty Maven Plug-in there is a copyDependencies parameter:
pom.xml
<plugins>
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.3.4</version>
<configuration>
<!-- Usually best to add configuration at the plugin level rather than trying to configure particular executions -->
<copyDependencies>
<dependencyGroup>
<!-- Relative to server config directory -->
<location>lib/global/jdbc</location>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
</dependency>
</dependencyGroup>
</copyDependencies>
</configuration>
...
server.xml
...
<!-- Derby Library Configuration -->
<library id="derbyJDBCLib">
<fileset dir="${server.config.dir}/lib/global/jdbc" includes="derby*.jar"/>
</library>
...
See documentation for further details.
I have an executable jar file. I can start it properly using command java ${JAVA_OPTS} -jar.
I deployed it to internal maven repository and include it to spring boot app as an dependency. How can I execute that dependency as jar file? I want to create Schedule to execute it every day.
One of the possible option is unpack jar via maven plugin, update main class in spring-boot-maven-plugin and execute the command as mentioned below :
Unpack the jar :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>unpack</id>
<phase>compile</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.group</groupId>
<artifactId>artifact</artifactId>
<version>0.0.1</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Update Main class(add below tag in spring-boot-maven-plugin) in pom.xml : as you may be having multiple main classes in final jar.
<configuration><mainClass>any of the main class here</mainClass></configuration>
Invoke the Main class
java -cp final.jar -Dloader.main=<fullyqualifed_mainclass> org.springframework.boot.loader.PropertiesLauncher
By this you can invoke any of the main class from final jar.
I'm moving from Maven to Gradle,
In my maven code i used the "maven-dependency-plugin"
and i could not find an easy translation for the following:
so my question is how can i get my dependencies into a specific structure?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.group1</groupId>
<artifactId>artifact1</artifactId>
<version>1</version>
<type>swf</type>
<outputDirectory>/flex/output1</outputDirectory>
<destFileName>artifact1.swf</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.group2</groupId>
<artifactId>artifact2</artifactId>
<version>2</version>
<type>swf</type>
<outputDirectory>/flex/output2</outputDirectory>
<destFileName>artifact2.swf</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.group3</groupId>
<artifactId>artifact3</artifactId>
<version>3</version>
<type>swf</type>
<outputDirectory>/flex/output3</outputDirectory>
<destFileName>artifact3.swf</destFileName>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
so finding no equivalent in Gradle what i ended up doing is holding a map of artifact id to the new name (outputDirectory + destFileName) and after resolving the dependencies into a new special configuration which i called "Flex" and then renaming every dependencies from "flex" using the mapping.
For those looking for Maven-like dependency management features in Gradle, check out the Dependency Management Plugin. It provides familiar dependencyManagement blocks and BOM support.
Note that you don't need to use Spring in your project to use the plugin.
I have a Maven project which produces a jar file that is meant to be used in a web service. It has integration tests which use the jetty-maven-plugin to run.
In order to run the integration tests on the compiled jar file, I've had to create a dependency with <systemPath>${project.build.directory}/${project.build.finalName}.${project.packaging}</systemPath>. The integration tests run as I had hoped, using the compiled jar file and correctly creating the web-app out of the src/test directory.
So in terms of this projects build, this setup works very well.
The problem is that the POM file, which is deployed during the release process, still has the systemPath dependency. This means that projects which use the jar are reporting an error during the build. The error says that the jar file "must specify an absolute path". These builds don't fail, but the logs are cluttered and misleading.
I'm looking to remove this systemPath from the POM which is deployed to our Maven repository. How can we do this?
For reference, here is the relevant portion of the project's POM.
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.7.v20131107</version>
<configuration>
<webAppSourceDirectory>${project.basedir}/src/test/webapp</webAppSourceDirectory>
<classesDirectory>${project.build.testSourceDirectory}</classesDirectory>
<useTestClasspath>true</useTestClasspath>
</configuration>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<scope>system</scope>
<systemPath>${project.build.directory}/${project.build.finalName}.${project.packaging}</systemPath>
</dependency>
</dependencies>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Jetty's documentation regarding <classesDirectory> reads:
Location of your compiled classes for the webapp. [...]
So, this should be ${project.build.testOutputDirectory} rather than ${project.build.testSourceDirectory}, shouldn't it?
<useTestClasspath> isn't mentioned in Jetty's doc.
Is it possible to install the dependency and use <scope>provided? Since with that:
[the dependency] is only available on the compilation and test classpath, and is not transitive.
The solution was a slight modification from Gerold Broser's answer.
Here are the relevant sections:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.1.5.v20140505</version>
<configuration>
<webAppSourceDirectory>${project.basedir}/src/test/webapp</webAppSourceDirectory>
<classesDirectory>${project.build.testOutputDirectory}</classesDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
I have a module , while building this module i want to include some resources from an external jar into my module jar.
I tried to use maven-shade-plugin but I am not able to achieve it it.
Any help is appreciated.
Unpack your external resource into project target, after this unpacked resources will be included in generated artifact.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<type>jar</type>
<includes>*.xsb, *.properties</includes>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
For non-maven file use method from this answer https://stackoverflow.com/a/3264160/516167