带有“war”包装的Maven项目:如何使用maven-jar-plugin创建JAR?

时间:2016-01-18 11:00:53

标签: java maven jar maven-jar-plugin

我有一个Maven项目,它构建一个WAR(在Tomcat上运行的REST Web服务)。在pom.xml中我有

<packaging>war</packaging>

某些类在另一个单独的项目中使用。我使用maven-jar-plugin构建这些类,后续配置:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <finalName>models</finalName>
                <archive>
                    <addMavenDescriptor>false</addMavenDescriptor>
                </archive>
                <includes>
                    <include>com/initech/middleware/application/conversion/*</include>
                    <include>com/initech/middleware/error/*</include>
                    <!-- other includes removed for example brevity -->
                </includes>
                <excludes>
                    <!-- removed for example brevity -->
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <id>make-a-jar</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

目前,我通过将pom.xml中的“打包”选项从“war”手动更改为“jar”并运行

来创建JAR文件
mvn install

创建JAR文件并将其安装在我的本地存储库中。但是,我想这样做,而不必在每次构建JAR文件之前手动编辑pom.xml文件。我尝试过使用“-Dpackaging = jar”选项,但这没有帮助。

是否可以通过在命令行中运行maven来创建使用maven-jar-plugin配置的JAR文件,如果是,怎么做?

0 个答案:

没有答案
相关问题