1

我希望标题不会令人困惑。我正在开发一个用于 JSF 项目的库。该库将打包为 JAR。该项目目前设置为战争,我可以使用 jar:jar 目标创建 JAR。拥有 WAR 项目使我能够自动部署更改并立即运行它们,而 JAR 项目需要 2 个构建:一个用于 JAR 本身的构建,一个用于使用此 jar 的测试 webapp。

但是,由于项目设置为 WAR,因此部署到我的本地 maven 存储库的工件也是 WAR,但 JAR 是所需的工件。有没有办法创建满足此要求的设置?

只是为了澄清:我知道常见的方法是拥有一个 JAR 项目和一个依赖于 JAR 的单独的 WAR 项目。我不想使用此设置,因为当需要构建 2 个工件时会对周转时间产生负面影响。

对此有任何提示或经验吗?

这是我当前的 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>mygroupid</groupId>
<artifactId>myartifact</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>mylibrary</name>

<licenses>
    <license>
        <name>The Apache Software License, Version 2.0</name>
        <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        <distribution>repo</distribution>
        <comments>A business-friendly OSS license</comments>
    </license>
</licenses>

<properties>
    <netbeans.compile.on.save>all</netbeans.compile.on.save>
    <org-netbeans-modules-projectapi.jsf_2e_language>Facelets</org-netbeans-modules-projectapi.jsf_2e_language>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <netbeans.hint.deploy.server>Tomcat</netbeans.hint.deploy.server>
</properties>

<dependencies>
    <!-- my dependencies -->
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>                
        </plugin>
    </plugins>
    <resources> 
        <resource> 
            <directory>src/main/resources/</directory> 
            <targetPath>META-INF</targetPath> 
        </resource> 
    </resources>         
</build>

</project>
4

1 回答 1

2

使您的项目成为具有父 pom.xml 和两个子项目的多模块项目:jar 和 war。将所有 java 源代码放在 jar 项目中,并让您的 war 项目依赖于兄弟 jar 项目。然后您可以mvn package从父 pom 模块运行并一步构建所有内容。

另请参阅:将多模块项目从 Maven 构建到一个 war 文件中

于 2013-05-26T12:33:40.260 回答