maven 最终的WAR文件,包括Cargo插件JAR

zbdgwd5y  于 2023-06-29  发布在  Maven
关注(0)|答案(1)|浏览(120)

我是新的Maven和货物插件和有一个有趣的问题。CargoJAR与WAR文件一起打包。可能,我漏说了什么。

  • Apache Maven 3.8.6
  • Eclipse IDE 2023-03(4.27.0)
  • Maven插件(m2 e)(1.6.0.20230118-0812)(已安装Maven)

Libraries > Maven Dependencies下有大量的JAR文件(应用程序需要的和Cargo插件使用的)。比我能在这里展示的更多。
这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<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>my-group-id</groupId>
   <artifactId>my-artifact-id</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>war</packaging>

   <properties>
      <maven.test.skip>true</maven.test.skip>

      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <maven.compiler.source>17</maven.compiler.source>
      <maven.compiler.target>17</maven.compiler.target>

      <servlet-api.version>6.0.0</servlet-api.version>

      <jersey.version>3.1.2</jersey.version>

      <cargo.maven3.plugin.version>1.10.7</cargo.maven3.plugin.version>

      <!-- build > pluginManagement > plugins -->
      <maven.clean.plugin.version>3.2.0</maven.clean.plugin.version>
      <maven.resources.plugin.version>3.3.1</maven.resources.plugin.version>
      <maven.compiler.plugin.version>3.11.0</maven.compiler.plugin.version>
      <maven.surefire.plugin.version>3.1.2</maven.surefire.plugin.version>
      <maven.war.plugin.version>3.3.2</maven.war.plugin.version>
      <maven.install.plugin.version>3.1.1</maven.install.plugin.version>
      <maven.deploy.plugin.version>3.1.1</maven.deploy.plugin.version>
   </properties>

   <dependencyManagement>
      <dependencies>
         <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>${jersey.version}</version>
            <type>pom</type>
            <scope>import</scope>
         </dependency>
      </dependencies>
    </dependencyManagement>

   <dependencies>
      <!-- JAKARTA SERVLET -->
      <!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
      <dependency>
          <groupId>jakarta.servlet</groupId>
          <artifactId>jakarta.servlet-api</artifactId>
          <version>${servlet-api.version}</version>
          <scope>provided</scope>
      </dependency>
 
      <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet -->
      <dependency>
         <groupId>org.glassfish.jersey.containers</groupId>
         <artifactId>jersey-container-servlet</artifactId>
      </dependency>
      <dependency>
         <groupId>org.glassfish.jersey.inject</groupId>
         <artifactId>jersey-hk2</artifactId>
      </dependency>

      <!-- CARGO (TOMCAT) -->
      <!-- https://mvnrepository.com/artifact/org.codehaus.cargo/cargo-maven3-plugin -->
      <dependency>
         <groupId>org.codehaus.cargo</groupId>
         <artifactId>cargo-maven3-plugin</artifactId>
         <version>${cargo.maven3.plugin.version}</version>
      </dependency>

      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.11</version>
         <scope>test</scope>
      </dependency>
   </dependencies>

   <build>
      <finalName>restful-ex02</finalName>
      <plugins>
         <!-- CARGO -->
         <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven3-plugin</artifactId>
            <version>${cargo.maven3.plugin.version}</version>
            <configuration>
               <container>
                  <containerId>tomcat10x</containerId>
                  <type>installed</type>
                  <home>${env.CATALINA_HOME}</home>
               </container>
               <configuration>
                  <type>existing</type>
                  <home>${env.CATALINA_HOME}</home>
               </configuration>
               <deployables>
                  <deployable>
                     <groupId>${project.groupId}</groupId>
                     <artifactId>${project.artifactId}</artifactId>
                     <type>war</type>
                  </deployable>
               </deployables>
            </configuration>
         </plugin>

      </plugins>
      <!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <pluginManagement>
         <plugins>
            <plugin>
               <artifactId>maven-clean-plugin</artifactId>
               <version>${maven.clean.plugin.version}</version>
            </plugin>
            <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
            <plugin>
               <artifactId>maven-resources-plugin</artifactId>
               <version>${maven.resources.plugin.version}</version>
            </plugin>
            <plugin>
               <artifactId>maven-compiler-plugin</artifactId>
               <version>${maven.compiler.plugin.version}</version>
            </plugin>
            <plugin>
               <artifactId>maven-surefire-plugin</artifactId>
               <version>${maven.surefire.plugin.version}</version>
            </plugin>
            <plugin>
               <artifactId>maven-war-plugin</artifactId>
               <version>${maven.war.plugin.version}</version>
            </plugin>
            <plugin>
               <artifactId>maven-install-plugin</artifactId>
               <version>${maven.install.plugin.version}</version>
            </plugin>
            <plugin>
               <artifactId>maven-deploy-plugin</artifactId>
               <version>${maven.deploy.plugin.version}</version>
            </plugin>
         </plugins>
      </pluginManagement>
   </build>
</project>

任何关于如何解决这个问题的指示将不胜感激。TIA。
顺便说一句,没有名为“cargo-maven 3-plugin”的标签:-(

bq3bfh9z

bq3bfh9z1#

将Cargo插件从build > plugins移动到build > pluginManagement
现在WAR文件只包含它的依赖项。

相关问题