1

我在我的构建中使用 maven-war-pluginpom.xml来生成一个与我的文件jar并行的文件。我的构建是在目标目录中创建和文件。并且只有文件安装到本地存储库。有没有办法将创建的文件也推送到本地存储库。下面是我的 pom.xml 的片段warjava web projectmavenwarjarwarjar

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>             
        <archive>
            <addMavenDescriptor>false</addMavenDescriptor>
            </archive>
            <archiveClasses>true</archiveClasses>
        <packagingExcludes>WEB-INF/lib/x*.jar</packagingExcludes>
        <webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml>
         <webResources>
        <resource>
          <directory>${project.basedir}\src\main\webapp</directory>
          <includes>
            <include>**/*.*</include>
          </includes>
        </resource>
            </webResources>
    </configuration>
</plugin>

提前致谢!

pom.xml 内容:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xyz</groupId>
    <artifactId>x</artifactId>
    <packaging>war</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <name>x</name>
    <url>http://maven.apache.org</url>
    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>             
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                        </archive>
                        <archiveClasses>true</archiveClasses>
                    <packagingExcludes>WEB-INF/lib/x*.jar</packagingExcludes>
                    <webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml>
                     <webResources>
                    <resource>
                      <directory>${project.basedir}\src\main\webapp</directory>
                      <includes>
                        <include>**/*.*</include>
                      </includes>
                    </resource>
                        </webResources>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

            <plugin>
              <groupId>com.googlecode.addjars-maven-plugin</groupId>
              <artifactId>addjars-maven-plugin</artifactId>
              <version>1.0.2</version>
              <executions>
                <execution>
                    <goals>
                        <goal>add-jars</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <directory>${project.basedir}/src/main/webapp/WEB-INF/lib</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
              </executions>
            </plugin>

        </plugins>
    </build>
</project>
4

1 回答 1

1

这不是使用 maven 的正确方法。Maven 完全是关于模块化的,因此有一个“一个项目 - 一个工件”规则(或推荐)。如果我无法说服您,另请参阅此博客:如何从一个项目创建两个 JAR(……以及为什么不应该这样做)。它是关于多个罐子的,但概念是相同的。

我认为您应该将您的工作重组为为 jar 提供一个单独的项目,而其他项目将其用作依赖项。

于 2014-11-04T12:46:34.913 回答