我如何使这个Maven POM有两个配置文件,唯一区别在于mainClass程序集

时间:2017-02-17 13:20:42

标签: java maven

我希望使用以下方法构建两个程序集:

<mainClass>com.jthink.songkong.cmdline.SongKong</mainClass>

和另一个使用:

<mainClass>com.jthink.songkong.cmdline.SongKong2</mainClass>

我知道我需要使用配置文件,但到目前为止我的尝试没有任何效果,使用mvn选项运行-P并不会产生任何不同,无论我输入真实的个人资料名称还是制作起来没有效果。目前还不清楚如何做到这一点,所以我刚刚发布了我原来的POM没有尝试失败,完全替代POM会有所帮助。

<?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>com.jthink</groupId>
    <artifactId>songkong</artifactId>
    <version>4.6</version>
    <repositories>
        <repository>
            <id>jaudiotagger-repository</id>
            <url>https://dl.bintray.com/ijabz/maven</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>net.jthink</groupId>
            <artifactId>jaudiotagger</artifactId>
            <version>2.2.6-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.com4j</groupId>
                    <artifactId>maven-com4j-plugin</artifactId>
                    <version>2.1</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.jvnet.com4j</groupId>
                <artifactId>maven-com4j-plugin</artifactId>
                <version>2.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <compilerVersion>1.8</compilerVersion>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.jthink.songkong.cmdline.SongKong</mainClass>
                            <packageName>com.jthink.songkong</packageName>
                            <addClasspath>true</addClasspath>
                        </manifest>
                        <manifestEntries>
                            <Class-Path>../lang/</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <descriptors>
                        <descriptor>assembly.xml</descriptor>
                    </descriptors>
                    <archive>
                        <manifest>
                            <mainClass>com.jthink.songkong.cmdline.SongKong</mainClass>
                            <packageName>com.jthink.songkong</packageName>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

根据关联问题进行更新

所以我已经创建了两个执行,每个执行都有不同的MainClass值,它没有任何区别,仍然只是创建单个songkong-4.6-jar-with-dependencies.jar与Manfest.mf中引用的第一个类文件文件。

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <id>make-assembly-1</id>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                            <descriptors>
                                <descriptor>assembly.xml</descriptor>
                            </descriptors>
                            <archive>
                                <manifest>
                                    <mainClass>com.jthink.songkong.cmdline.SongKong</mainClass>
                                    <packageName>com.jthink.songkong</packageName>
                                    <addClasspath>true</addClasspath>
                                </manifest>
                            </archive>
                        </configuration>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>make-assembly-2</id>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies2</descriptorRef>
                            </descriptorRefs>
                            <descriptors>
                                <descriptor>assembly.xml</descriptor>
                            </descriptors>
                            <archive>
                                <manifest>
                                    <mainClass>com.jthink.songkong.cmdline.SongKong2</mainClass>
                                    <packageName>com.jthink.songkong</packageName>
                                    <addClasspath>true</addClasspath>
                                </manifest>
                            </archive>
                        </configuration>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

0 个答案:

没有答案