如何maven jar-with-dependencies pom.xml覆盖

时间:2013-06-28 09:31:40

标签: java maven project pom.xml

我有一个pom.xml,它应该生成jar-with-dependencies并将所有外部和所有写入的类包含到我的jar文件中,它应该是可执行的(带有MainClass定义)。现在我的项目通过pom.xml从远程存储库获取它自己的<parent/>。我重写maven-assembly-plugin,但每次调用jar:jar时,我的jar都只包含我自己的类文件,而不是外部类。如果我运行assembly:single,我会得到所有外部类文件,但不是我自己的类。

父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>

    <organization>
        <name>123</name>
        <url>123.com</url>
    </organization>

    <groupId>com.test</groupId>
    <artifactId>build</artifactId>
    <version>1.0.0</version>
    <packaging>pom</packaging>


    <properties>
        <project.build.sourceEncoding>Cp1252</project.build.sourceEncoding>
        <compile.java.version>1.6</compile.java.version>
    </properties>


    <distributionManagement>
        <repository>
            <id>dsc-repository</id>
            <name>buildmaster-releases</name>
            <url>${repository.releases}</url>
        </repository>
        <snapshotRepository>
            <id>dsc-repository</id>
            <name>buildmaster-snapshots</name>
            <url>${repository.snapshots}</url>
        </snapshotRepository>
    </distributionManagement>

    <build>
        <finalName>${project.artifactId}</finalName>

        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>${compile.java.version}</source>
                    <target>${compile.java.version}</target>

                    <debug>true</debug>
                    <optimize>true</optimize>

                    <showDeprecation>true</showDeprecation>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                        <manifestEntries>
                            <Title>${project.artifactId}</Title>
                            <Version>${project.version}</Version>
                            <Vendor>${project.organization.name}</Vendor>

                            <Build-Timestamp>${env.BUILD_ID}</Build-Timestamp>
                            <Build-Number>${env.BUILD_NUMBER}</Build-Number>
                            <Build-Revision>${env.SVN_REVISION}</Build-Revision>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.4</version>
            </plugin>

            <plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <!-- disable java doc on release -->
                    <skip>true</skip>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.7</version>
            </plugin>

        </plugins>
    </build>

</project>

我没有机会改变这个pom.xml!

以下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>
    <artifactId>DSCTest2Certificate</artifactId>
    <version>0.9.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>com.dscsag</groupId>
        <artifactId>build</artifactId>
        <version>1.0.0</version>
    </parent>

    <properties>
        <compile.java.version>1.7</compile.java.version>
    </properties>

    <build>
        <plugins>
            <!-- <plugin> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> 
                <configuration> <archive> <addMavenDescriptor>false</addMavenDescriptor> 
                <manifest> <mainClass>com.dscsag.dsct2c.main.MainClass</mainClass> </manifest> 
                <manifestEntries> <splashscreen-image>com/dscsag/dsct2c/resources/icons/loader/splash_screen.png</splashscreen-image> 
                </manifestEntries> </archive> </configuration> </plugin> -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                        <manifest>
                            <mainClass>com.dscsag.dsct2c.main.MainClass</mainClass>
                        </manifest>
                        <manifestEntries>
                            <splashscreen-image>com/dscsag/dsct2c/resources/icons/loader/splash_screen.png</splashscreen-image>
                        </manifestEntries>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itextpdf</artifactId>
            <version>5.4.2</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.7.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.swinglabs.swingx</groupId>
            <artifactId>swingx-all</artifactId>
            <version>1.6.4</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>com.toedter</groupId>
            <artifactId>jcalendar</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>com.jgoodies</groupId>
            <artifactId>jgoodies-common</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>com.jgoodies</groupId>
            <artifactId>jgoodies-looks</artifactId>
            <version>2.5.2</version>
        </dependency>
        <dependency>
            <groupId>dsct2c.help</groupId>
            <artifactId>jreleaseinfo</artifactId>
            <version>1.3.0</version>
        </dependency>
        <dependency>
            <groupId>dsct2c.help</groupId>
            <artifactId>pdf_render</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
            <groupId>dsct2c.help</groupId>
            <artifactId>jh</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>dsct2c.help</groupId>
            <artifactId>hsviewer</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>dsct2c.help</groupId>
            <artifactId>dsct2c_help</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>

    <scm>
        <url>http://svnserver/svn_devel/plm/trunk/modules/DSCTest2Certificate</url>
        <connection>scm:svn:http://svnserver/svn_devel/plm/trunk/modules/DSCTest2Certificate</connection>
        <developerConnection>scm:svn:http://svnserver/svn_devel/plm/trunk/modules/DSCTest2Certificate</developerConnection>
    </scm>

</project>

如何解决我的问题?

2 个答案:

答案 0 :(得分:1)

如果您致电mvn jar:jarmvn assembly:single,那么您没有运行maven生命周期,这意味着配置部件将无法按预期运行。

你必须致电:

mvn package

而不是maven-jar-plugin以及你在pom.xml文件中定义的maven-assembly-plugin。

答案 1 :(得分:0)

我也很难找到这个答案。 我在这里发现了这个评论。我希望它有所帮助。

http://maven.apache.org/guides/mini/guide-configuring-plugins.html

注意:&lt;内部的配置处决&GT;标签与外面的标签不同&lt;处决&GT;因为它们不能从直接命令行调用中使用。相反,它们仅在调用它们绑定的生命周期阶段时应用。或者,如果您将配置部分移到执行部分之外,它将全局应用于插件的所有调用。

相关问题