我有,我会用它在另一个项目CXF WS项目,我会消耗这个WS在Web项目,但我不知道如何生成jar文件。
请你有什么想法或一个例子吗?
谢谢
我有,我会用它在另一个项目CXF WS项目,我会消耗这个WS在Web项目,但我不知道如何生成jar文件。
请你有什么想法或一个例子吗?
谢谢
Maven的战争,插件支持创建一个单独的神器,只是包含的类。
http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html
见“attachClasses”参数。 无需在罐子插件或乱用包装增加。 就在战争插件添加到pluginManagement并打开这个上。
不过,我担心这个,这不是你想要的。 消耗CXF Web服务,您需要一个客户端。 为了得到一个客户端,请按照有关如何生成和使用客户端存根CXF样品中的说明。 你会想这个独立的Maven项目。
尝试添加该到编译部分:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>make-a-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
添加下列战争项目的pom.xml。
<attachClasses>true</attachClasses>
战争插件的配置
<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>
添加以下到您想要导入战项目的罐子项目的pom.xml
<classifier>classes</classifier>
到依赖进口
<dependency>
<groupId>com.yourorg.foobar</groupId>
<artifactId>hello-world</artifactId>
<version>1.0</version>
<classifier>classes</classifier>
</dependency>
这是为了实现它,通过属性的一种方式。 默认情况下,它会生成一个war文件,当你想要的只是罐子设置属性。
mvn install -Dp.type=jar
的pom.xml
<properties>
<p.type>war</p.type>
</properties>
<packaging>${p.type}</packaging>
这应该工作:
<!-- 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>
来自这个博客 。
mvn package
,除非你的项目的包装是,除了一些jar
。 然后,你需要添加一个执行了的罐子插件 ,作为上描述的插件的使用页面 ,并作为第一个答案显示。 更妙的是,如果它不是一个罐子,将其划分为两个模块:一个是包含您的可重用的代码一个罐子,以及其他使用它的东西。
实现这一目标的最佳方式是使用Maven Assembly插件通过这个,你还可以控制JAR的最终名称:
添加下面的插件在你的pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<finalName>${artifactId}-${version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
assembly.xml:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>model</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
你终于可以建立与下面的命令的项目:
MVN清洁封装组件:安装单
考虑到你的Maven项目包装战争
<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>
添加以下处决Maven的安装,插件
<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>