Maven - Generate Jar and War

后端 未结 8 2034
轻奢々
轻奢々 2020-12-29 04:24

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

相关标签:
8条回答
  • 2020-12-29 05:04

    Try adding this into your build section:

    <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>
    
    0 讨论(0)
  • The best way to achieve this is by using Maven assembly plugin by this you can also control the final name of the jar :

    Add the following plugin in your 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>
    

    You can finally build the project with the command below:

    mvn clean package assembly:single install

    0 讨论(0)
提交回复
热议问题