25

我有一个 CXF WS 项目,我会在另一个项目中使用它,我会在 Web 项目中使用这个 WS,但我不知道如何生成 Jar 文件。

请问您有什么想法或例子吗?

谢谢

4

8 回答 8

34

maven-war-plugin 支持创建仅包含类的单独工件。

http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html

请参阅“attachClasses”参数。无需添加 jar 插件或弄乱包装。只需将战争插件添加到 pluginManagement 并打开它。

但是,我担心这不是您想要的。要使用 CXF Web 服务,您需要一个客户端。要获取客户端,请按照 CXF 示例中的说明了解如何生成和使用客户端存根。为此,您需要一个单独的 Maven 项目。

于 2012-06-02T15:13:28.180 回答
25

尝试将其添加到您的构建部分:

<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>
于 2012-06-02T14:37:55.653 回答
22

在 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>
于 2017-04-06T06:30:02.223 回答
11

这是通过属性实现它的一种方法。默认情况下它会生成一个war文件,当你想要jar时只需设置属性。

mvn install -Dp.type=jar

pom.xml

<properties>
   <p.type>war</p.type>
</properties>
<packaging>${p.type}</packaging>
于 2014-12-26T22:35:01.797 回答
6

这应该有效:

<!-- 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>

取自这个博客

于 2017-06-13T07:14:04.650 回答
3

考虑将您的 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>
于 2018-12-04T21:46:35.903 回答
2

mvn package除非您的项目的包装jar. 然后,您需要添加jar plugin的执行,如插件的使用页面所述以及第一个答案所示。更好的是,如果它不是 jar,则将其分成两个模块:一个是包含可重用代码的 jar,另一个是使用它的东西。

于 2012-06-02T14:57:14.103 回答
1

实现这一点的最佳方法是通过使用 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 组件:单次安装

于 2018-02-27T19:54:41.293 回答