I have a CXF WS project that I would use it in another project, I would consume this WS in a Web Project but I don\'t know how to generate Jar file.
Please have you
Add following to pom.xml of war project.
<attachClasses>true</attachClasses>
to configuration of war plugin
<groupId>com.yourorg.foobar</groupId>
<artifactId>hello-world</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>hello</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
</plugins>
</build>
Add following to pom.xml of the project where you want to import jar of war project
<classifier>classes</classifier>
to dependency import
<dependency>
<groupId>com.yourorg.foobar</groupId>
<artifactId>hello-world</artifactId>
<version>1.0</version>
<classifier>classes</classifier>
</dependency>
The maven-war-plugin supports creating a separate artifact that just contains the classes.
http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html
See the 'attachClasses' parameter. No need to add in the jar plugin or mess with the packaging. Just add the war plugin to pluginManagement and turn this on.
However, I fear this this isn't what you want. To consume a CXF web service, you need a client. To get a client, follow the instructions in the CXF samples for how to generate and use client stubs. You'll want a separate maven project for this.
This is a one way to achieve it, via property. By default it will generate a war file, and when you want the jar just set the property.
mvn install -Dp.type=jar
pom.xml
<properties>
<p.type>war</p.type>
</properties>
<packaging>${p.type}</packaging>
This should work:
<!-- Maven JAR plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>jar-services-provided</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Install the jar locally -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>
${project.build.directory}/${project.artifactId}-${project.version}.jar
</file>
</configuration>
</execution>
</executions>
</plugin>
Taken from this blog.
mvn package
unless your project's packaging is something besides jar
. Then you'd need to add an execution of the jar plugin, as described on the plugin's usage page and as the first answer showed. Better yet, if it's not a jar, divide it into two modules: one that's a jar containing your reusable code, and the other the thing that uses it.
Considering your maven project packaging to war
<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>com.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
add the following executions to maven-install-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<packaging>jar</packaging>
<file>${project.build.directory}\${artifactId}-${version}.jar</file>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>