我有一个 CXF WS 项目,我会在另一个项目中使用它,我会在 Web 项目中使用这个 WS,但我不知道如何生成 Jar 文件。
请问您有什么想法或例子吗?
谢谢
我有一个 CXF WS 项目,我会在另一个项目中使用它,我会在 Web 项目中使用这个 WS,但我不知道如何生成 Jar 文件。
请问您有什么想法或例子吗?
谢谢
maven-war-plugin 支持创建仅包含类的单独工件。
http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html
请参阅“attachClasses”参数。无需添加 jar 插件或弄乱包装。只需将战争插件添加到 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>
在 war 项目的 pom.xml 中添加以下内容。
<attachClasses>true</attachClasses>
配置war插件
<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>
在要导入 jar of war 项目的项目的 pom.xml 中添加以下内容
<classifier>classes</classifier>
依赖导入
<dependency>
<groupId>com.yourorg.foobar</groupId>
<artifactId>hello-world</artifactId>
<version>1.0</version>
<classifier>classes</classifier>
</dependency>
这是通过属性实现它的一种方法。默认情况下它会生成一个war文件,当你想要jar时只需设置属性。
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>
取自这个博客。
考虑将您的 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-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>
mvn package
除非您的项目的包装是jar
. 然后,您需要添加jar plugin的执行,如插件的使用页面所述以及第一个答案所示。更好的是,如果它不是 jar,则将其分成两个模块:一个是包含可重用代码的 jar,另一个是使用它的东西。
实现这一点的最佳方法是通过使用 Maven 程序集插件,您还可以控制 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>
组装.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 clean package 组件:单次安装