I have the following maven parent project with several modules
<parent>
<artifactId>ppdf-3party-demo</artifactId>
<groupId>edu.i2r</groupId>
<version>1.0</version>
</parent>
<groupId>edu.i2r</groupId>
<artifactId>ppdf-3party-demo-client</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>ppdf-3party-demo-client</name>
<modules>
<module>demo-client-app</module>
<module>demo-client-model</module>
<module>demo-client-persist</module>
<module>demo-client-swing</module>
<module>demo-client-encryptservice</module>
</modules>
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat</artifactId>
<version>7.0.35</version>
<type>zip</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/bin-package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>distro-assembly</id>
<!-- <phase>package</phase> -->
<!-- <goals> -->
<!-- <goal>single</goal> -->
<!-- </goals> -->
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>unpack-tomcat</id>
<phase>process-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat</artifactId>
<version>7.0.35</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>
[2.4,)
</versionRange>
<goals>
<goal>unpack</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Inside demo-client-persist I have a dependency on spring-jdbc
<parent>
<groupId>edu.i2r</groupId>
<artifactId>ppdf-3party-demo-client</artifactId>
<version>1.0</version>
</parent>
<artifactId>demo-client-persist</artifactId>
<name>demo-client-persist</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>edu.i2r</groupId>
<artifactId>demo-client-model</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>edu.i2r</groupId>
<artifactId>ppdf-demo-common</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
Finally, I have the following assembly descriptor
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
Running mvn assembly:assembly, the output directory seemed to work, as dependencies are copied to the lib directory. However, just the spring-jdbc jar wasn't there.
Did i miss out anything?
There might be an error during the build at the very beginning saying that as a result of this error transitive dependencies have been disabled.
Some warnings may be ignored when you run mvn assembly:assembly.
## [WARNING] Invalid POM for ${group}:${artifact}:${type}:${version}, transitive dependencies (if any) will not be available, enable debug logging for more details
##
You can run maven with option '-X' to see the details. And in my case, the problem is solved by removing the _remote.repositories file in the local maven cache (~/.m2)
You may want to have a look at this post: "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository
Related
I have a maven multi-module project and one of the sub-modules requires proprietary libraries to compile, specifically I am downloading the latest version of intellij-idea Community Edition in a zip file from its official page.
My first approach was to download using a travis-ci script for linux and on windows using appveyor, but since I want to integrate it with sonatype-deepshield I must control the process entirely from maven.
The whole process should consist of:
zip download
zip decompression
dependency registration in maven local repository (currently I don't do this since I use scope system and I don't know any other way)
reference dependencies
compilation
This is my pom so far:
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.javapro</groupId>
<artifactId>regextester-pom</artifactId>
<version>1.0.3</version>
</parent>
<artifactId>regextester-idea</artifactId>
<packaging>jar</packaging>
<name>regextester Client for Idea</name>
<properties>
<!-- Plugin meta information -->
<vendor.url>http://www.javapro.org</vendor.url>
<vendor.email>myemail#gmail.com</vendor.email>
<vendor.name>Ruslan López Carro - Java PRO</vendor.name>
<!-- IntelliJ distribution related properties-->
<intellij.version>13.0.2</intellij.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ij.plugin>true</ij.plugin>
<INTELLIJ_HOME>C:/Users/javatlacati/.IntelliJIdea2019.3/system/plugins-sandbox</INTELLIJ_HOME>
<idea.systemPath>${project.basedir}/lib</idea.systemPath>
<project.mainclass>org.javapro.regextester.MyToolWindowFactory</project.mainclass>
<exec.java.bin>${java.home}/bin/java</exec.java.bin>
<exec.debug.arg>-Ddebug=false</exec.debug.arg>
<springloaded.javaagent>-Djavaagent=false</springloaded.javaagent>
<dependency.plugin.version>2.3</dependency.plugin.version>
<comipler.plugin.version>2.5.1</comipler.plugin.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<exec.debug.arg>-Ddebug=false</exec.debug.arg>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>regextester-js</artifactId>
<version>${project.version}</version>
</dependency>
<!--idea dependencies-->
<dependency>
<groupId>com.jetbrains</groupId>
<artifactId>util</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${idea.systemPath}/lib/util.jar</systemPath>
</dependency>
<dependency>
<groupId>com.jetbrains</groupId>
<artifactId>platform-core-ui</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${idea.systemPath}/lib/platform-core-ui.jar</systemPath>
</dependency>
<dependency>
<groupId>com.jetbrains</groupId>
<artifactId>openapi</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${idea.systemPath}/lib/openapi.jar</systemPath>
</dependency>
<dependency>
<groupId>com.jetbrains</groupId>
<artifactId>platform</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${idea.systemPath}/lib/platform-api.jar</systemPath>
</dependency>
<dependency>
<groupId>com.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${idea.systemPath}/lib/annotations.jar</systemPath>
</dependency>
<!--javafx-->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>14</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>jar</id>
<phase>prepare-package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>unpack</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
</execution>
<execution>
<id>copy</id>
<phase>process-classes</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.3.RELEASE</version>
<type>jar</type>
<overWrite>false</overWrite>
<destFileName>springloaded.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<type>zip</type>
<classifier>webpages</classifier>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/classes/org/javapro/regextester</outputDirectory>
<includes>*/**</includes>
<includeGroupIds>${project.groupId}</includeGroupIds>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>${project.mainclass}</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>install-idea-dependencies</id>
<phase>validate</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://www.jetbrains.com/intellij-repository/releases/com/jetbrains/intellij/idea/ideaIC/${env.VERSION}/ideaIC-${env.VERSION}.zip</url>
<unpack>true</unpack>
<outputDirectory>${project.basedir}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.codehaus.mojo</groupId>-->
<!-- <artifactId>wagon-maven-plugin</artifactId>-->
<!-- <version>2.0.0</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>downloadIC</id>-->
<!-- <phase>validate</phase>-->
<!-- <goals><goal>download-single</goal></goals>-->
<!-- <configuration>-->
<!-- <url>https://www.jetbrains.com/intellij-repository/releases/com/jetbrains/intellij/idea/ideaIC/${env.VERSION}/</url>-->
<!-- <fromFile>ideaIC-${env.VERSION}.zip</fromFile>-->
<!-- <toFile>${project.basedir}/lib/ideaIC-${env.VERSION}.zip</toFile>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <artifactId>maven-antrun-plugin</artifactId>-->
<!-- <version>1.8</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>prepare</id>-->
<!-- <phase>validate</phase>-->
<!-- <configuration>-->
<!-- <tasks>-->
<!-- <echo message="unzipping file ${project.basedir}/lib/ideaIC-${env.VERSION}.zip to ${project.basedir}/lib" />-->
<!-- <unzip src="${project.basedir}/lib/ideaIC-${env.VERSION}.zip" dest="${project.basedir}/lib"/>-->
<!-- </tasks>-->
<!-- </configuration>-->
<!-- <goals>-->
<!-- <goal>run</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
</plugins>
</build>
</project>
It works perfectly on Linux, but on Windows, it works only if the download was already in the maven cache or in the local repository, but not in a clean installation.
As you can appreciate I've tried with download-maven-plugin, maven-antrun-plugin and wagon-maven-plugin without success.
I think the fundamental problem with your approach is that dependencies are always resolved at the very beginning of the Maven run. So when you run
mvn clean install
Then first the dependencies are resolved and then subsequent steps are run. So if copy or resolve a dependency during the build, it cannot be found if it was not already there at the beginning.
So if you want to solve this problem with Maven, you need at least two separate Maven runs.
That said, I do not understand yet why you cannot construct a pipeline (I don't know travis-ci, but it is probably similar to Jenkins) that first unpacks and downloads the dependencies and then calls mvn clean install. But I do not know sonatype-deepshield and cannot judge on this.
How can I pack switchyard application with has dependencies to my another project with Maven? Currently I'm trying to make things work as explained here
official dock.
But with no result, on startup of application in log file I see
Caused by: java.lang.NoClassDefFoundError: com/aspiderngi/common/switchyard/InventoryRequest
Caused by: java.lang.ClassNotFoundException: com.aspiderngi.common.switchyard.InventoryRequest from...
Is it possible to achieve anyways?
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.switchyard</groupId>
<version>0.0.1-SNAPSHOT</version>
<name>com.example.switchyard:sy-example</name>
<artifactId>sy-example</artifactId>
<properties>
<switchyard.version>2.0.0.Final</switchyard.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<packaging>war</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-bom</artifactId>
<version>${switchyard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.aspiderngi</groupId>
<artifactId>artifacts-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-camel</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-camel-jms</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-api</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-transform</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-validate</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-test-mixin-cdi</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-bean</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-plugin</artifactId>
<version>${switchyard.version}</version>
<executions>
<execution>
<goals>
<goal>configure</goal>
</goals>
</execution>
</executions>
<configuration>
<scannerClassNames>
<param>org.switchyard.transform.config.model.TransformSwitchYardScanner</param>
</scannerClassNames>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<packagingExcludes>
WEB-INF/lib/*.jar,
WEB-INF/classes/META-INF/switchyard.xml
</packagingExcludes>
<webResources>
<resource>
<directory>target/classes/META-INF</directory>
<targetPath>WEB-INF</targetPath>
<includes>
<include>switchyard.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
You can use Maven Shade plugin:
https://maven.apache.org/plugins/maven-shade-plugin/
example:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>jackofall</shadedClassifierName> <!-- Any name that makes sense -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
Please try this out. The dependent project must have its own pom.xml(child)
Include this child pom to the parent pom. And include the below code in the parent pom.xml
This would directly deploy the application in the server
From project root in cmd execute the below commands:
1. mvn clean
2. mvn dependency:resolve
3. mvn install
if you are using Eclipse, use maven update. then Run As maven install
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<debug>true</debug>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-plugin</artifactId>
<version>${switchyard.version}</version>
<executions>
<execution>
<goals>
<goal>configure</goal>
</goals>
</execution>
</executions>
<configuration>
<scannerClassNames>
<param>org.switchyard.transform.config.model.TransformSwitchYardScanner</param>
</scannerClassNames>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
if you are using Bean then include
<scannerClassNames>
<param>org.switchyard.transform.config.model.BeanSwitchYardScanner</param>
</scannerClassNames>
While running the executing the maven main class using below command:
mvn exec:java -Dexec.mainClass="com.xoxo.amqtest.SubscriberDriver"
I assumed that all the jars must be picked up from the maven repo. But instead it throws below exception.
java.lang.NoClassDefFoundError: com/xoxo/infra/protectedpkg/ProtectedPackageLoadException
This maven project runs fine in eclipse. Is there any way to specify maven to pick all the dependencies from maven repo instead of adding all the dependencies like below
java -cp ./:./target/amq-subscriber-1.0.0-SNAPSHOT-jar-with-dependencies.jar:/x/home/stvu/.m2/repository/com/xoxo/submodule/infra-jsse-2.0.1.jar com.xoxo.amqtest.SubscriberDriver
Edit:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xoxox.infra</groupId>
<artifactId>infra-parent</artifactId>
<version>13.2.3</version>
<relativePath />
</parent>
<groupId>com.xoxox.amqtest</groupId>
<artifactId>amqsubscriber</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>amq_sub_test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.xoxox.infra</groupId>
<artifactId>infra</artifactId>
</dependency>
<dependency>
<groupId>com.xoxox.kernel</groupId>
<artifactId>KernelDAL</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.11</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit-addons</groupId>
<artifactId>junit-addons</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
com.xoxox.infra.maven.plugins
</groupId>
<artifactId>
infra-codegenerator-maven-plugin
</artifactId>
<versionRange>
[13.3.0,)
</versionRange>
<goals>
<goal>generate-code</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I've done this in the past using exec-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>execute-your-main</id>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.xoxo.amqtest.SubscriberDriver</mainClass>
<arguments>
<argument>ADD_YOUR_ARGUMENTS_IF_NEEDED</argument>
</arguments>
</configuration>
</execution>
</plugin>
take look at appassembler plugin.
http://mojo.codehaus.org/appassembler/appassembler-maven-plugin/
Configuration will look like
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
<configuration>
<programs>
<program>
<mainClass>fun.Tester</mainClass>
<id>app</id>
</program>
</programs>
</configuration>
</plugin>
it will create directory name 'appassembler' in you target directory which will have all dependent jars and executable according to platform in 'bin' directory
I just started to write my first Jax-RS webservice and since yesterday I try to figure out how I can start a test server automatically if I build the project using maven. If I run the following commands without trying to execute some tests, everything works fine:
mvn clean install
export PORT=5000
java -cp target/classes:"target/dependency/*" net.avedo.spozz.Spozz
The service is then available at localhost:5000/services/users. But if I try to start a server and run test automatically by using the pom.xml I attached at the end of this post, I get an error:
testHasUser(net.avedo.spozz.models.UserTest): Connection refused
Which corresponds to this piece of code:
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://localhost:5000/services/users/1") ;
response = httpClient.execute(httpGet) ;
So, I am not sure what is wrong here. I think the server is started under the wrong uri, but as I am not telled where the test server is started, I cannot verify this. I need to know what I need to add or change in the pom.xml file, in order to run the test server to run the tests for the project. As it may help, here is my project structure:
|-pom.xml
|-src
|---main
|-----java
|-------net
|---------avedo
|-----------spozz
|-------------Spozz.java
|-------------models
|---------------User.java
|-------------services
|---------------UserResource.java
|-----resources
|-----webapp
|-------index.html
|-------WEB-INF
|---------web.xml
|---test
|-----java
|-------net
|---------avedo
|-----------spozz
|-------------models
|---------------UserTest.java
|-----resources
|-target
|---classes
|-----net
|-------avedo
|---------spozz
|-----------Spozz.class
|-----------models
|-------------User.class
|-----------services
|-------------UserResource$1.class
|-------------UserResource$2.class
|-------------UserResource.class
|---test-classes
|-----net
|-------avedo
|---------spozz
|-----------models
|-------------UserTest.class
My old pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.avedo.spozz</groupId>
<artifactId>Spozz-Service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spozz REST Webservice</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Jetty -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>7.6.0.v20120127</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>7.6.0.v20120127</version>
</dependency>
<!-- Jersey -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.8</version>
</dependency>
<!-- jUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<!-- Apache Commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>5000</stopPort>
</configuration>
<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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals><goal>copy-dependencies</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- M2Eclipse Compatibility -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[2.4,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
\\EDIT (1):
I updated my pom.xml to use a newer version of jetty, but now I am getting new errors:
2014-03-06 11:51:29.126:WARN:oejuc.AbstractLifeCycle:FAILED org.eclipse.jetty.servlet.ServletHandler#66cbe14a:
java.lang.NoClassDefFoundError: org/eclipse/jetty/servlet/FilterMapping
Furthermore the port problem pops up again:
Error binding monitor port 8080: java.net.BindException: Address already in use
2014-03-06 11:51:24.909:INFO:oejs.Server:jetty-8.1.14.v20131031
2014-03-06 11:51:25.245:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp requires one, please configure one.
2014-03-06 11:51:26.839:WARN:oejsh.RequestLogHandler:!RequestLog
2014-03-06 11:51:26.847:INFO:oejs.AbstractConnector:Started SelectChannelConnector#0.0.0.0:28080
My updated pom.xml
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.avedo.spozz</groupId>
<artifactId>Spozz-Webservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>9.1.0.v20131115</jetty.version>
<jersey.version>1.8</jersey.version>
<junit.version>4.11</junit.version>
<apache.commons.version>1.3.2</apache.commons.version>
<apache.http.version>4.3.2</apache.http.version>
<jsp.version>2.5</jsp.version>
<maven.compiler.plugin.version>2.5.1</maven.compiler.plugin.version>
<sql.maven.plugin.version>1.5</sql.maven.plugin.version>
<postgresql.jdbc.version>9.1-901.jdbc4</postgresql.jdbc.version>
</properties>
<dependencies>
<!-- Jetty -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jsp</artifactId>
<version>${jetty.version}</version>
<type>pom</type>
<exclusions>
<exclusion>
<artifactId>org.eclipse.jdt.core</artifactId>
<groupId>org.eclipse.jetty.orbit</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- Jersey -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- jUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- Apache Commons -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${apache.commons.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache.http.version}</version>
<scope>test</scope>
</dependency>
<!-- PostgreSQL -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.jdbc.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.14.v20131031</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>8080</stopPort>
<stopWait>10</stopWait>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>28080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>test-compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>${sql.maven.plugin.version}</version>
<dependencies>
<!-- Specify the dependent jdbc driver here -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.jdbc.version}</version>
</dependency>
</dependencies>
<!-- Common configuration shared by all executions -->
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432:spozz_db</url>
<username>postgres</username>
<password>root</password>
<!-- You can comment out username/password configurations and have
maven to look them up in your settings.xml using ${settingsKey} -->
<settingsKey>sensibleKey</settingsKey>
<!-- All executions are ignored if -Dmaven.test.skip=true -->
<skip>${maven.test.skip}</skip>
</configuration>
<executions>
<execution>
<id>drop-schema-before-test-if-any</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<!-- Need another database to drop the targeted one -->
<url>jdbc:postgresql://localhost:5432:postgres</url>
<autocommit>true</autocommit>
<sqlCommand>DROP SCHEMA spozz CASCADE</sqlCommand>
<!-- Ignore error when database is not available -->
<onError>continue</onError>
</configuration>
</execution>
<execution>
<id>create-schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>src/main/sql/spozz-schema.sql</srcFile>
</srcFiles>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dbunit-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<dependencies>
<!-- Specify the dependent jdbc driver here -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.jdbc.version}</version>
</dependency>
</dependencies>
<!-- Common configuration shared by all executions -->
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432:spozz_db</url>
<username>postgres</username>
<password>root</password>
<!-- You can comment out username/password configurations and have maven
to look them up in your settings.xml using ${settingsKey} -->
<settingsKey>sensibleKey</settingsKey>
<!-- All executions are ignored if -Dmaven.test.skip=true -->
<skip>${maven.test.skip}</skip>
</configuration>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>operation</goal>
</goals>
<!-- Specific configurations -->
<configuration>
<type>CLEAN_INSERT</type>
<src>src/test/resources/spozz_db_testdata.xml</src>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals><goal>copy-dependencies</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- M2Eclipse Compatibility -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[2.4,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
If these are regular tests, which are executed in the test phase, then the fact that you're starting jetty in the pre-integration-test is your problem. You should be running it in the test-compile phase.
I get the Eclipse error below when starting my application in Tomcat (via Run As > Run on Server.) I'm using the DataNucleus Eclipse Plugin and have it set up to Enable Auto-Enhancement.
Publishing failed with multiple errors
Resource is out of sync with the file system: '/myproject/target/classes/com/mysite/models/Inventory.class'.
Resource is out of sync with the file system: '/myproject/target/classes/com/mysite/models/Product.class'.
I understand I can manually trigger refresh on that project every time I want to run the project on server. Are there ways to overcome that inconvenience?
Note: I also understand Eclipse can be configured to refresh on access, using native hooks, or using polling. However, that triggers multiple unnecessary runs of datanucleus:enhance. Additionally, the problem is compounded when Tomcat is configured to automatically publish when resources change or after a build event.
For reference, relevant excerpts of my pom.xml are below
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<packaging>war</packaging>
<properties>
<datanucleus.core.version>3.2.12</datanucleus.core.version>
<datanucleus.api.version>3.0.1</datanucleus.api.version>
</properties>
<dependencies>
<!-- Database See http://www.datanucleus.org/products/datanucleus/jdo/maven.html -->
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>${datanucleus.api.version}</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>${datanucleus.core.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>[3.2.0, 3.2.99)</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>[3.2.0, 3.2.99)</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- JDO Enhancer See http://www.datanucleus.org/products/datanucleus/jdo/guides/eclipse.html -->
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>3.3.0-release</version>
<configuration>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>${datanucleus.core.version}</version>
</dependency>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>${datanucleus.api.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.datanucleus
</groupId>
<artifactId>
datanucleus-maven-plugin
</artifactId>
<versionRange>
[3.3.0-release,)
</versionRange>
<goals>
<goal>enhance</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>