maven-assembly-plugin在classpath之前

时间:2015-01-20 22:33:32

标签: java maven-assembly-plugin

我有一个模块,我正在使用maven-assembly-plugin创建一个带有依赖项的可执行jar。当我运行install时,插件会在jar名称和所有jar内容之前添加项目名称(“nearby”),即:

$ jar -tvf vicinity-confirm-assets.jar | more
     0 Tue Jan 20 17:18:10 EST 2015 META-INF/
   213 Tue Jan 20 17:18:08 EST 2015 META-INF/MANIFEST.MF
     0 Tue Jan 20 17:18:10 EST 2015 vicinity/
     0 Thu Nov 13 20:52:16 EST 2014 vicinity/META-INF/
   134 Thu Nov 13 20:52:14 EST 2014 vicinity/META-INF/MANIFEST.MF
     0 Thu Nov 13 20:52:06 EST 2014 vicinity/org/
     0 Thu Nov 13 20:52:10 EST 2014 vicinity/org/boon/
     0 Thu Nov 13 20:52:10 EST 2014 vicinity/org/boon/cache/
     0 Thu Nov 13 20:52:10 EST 2014 vicinity/org/boon/collections/
     0 Thu Nov 13 20:52:10 EST 2014 vicinity/org/boon/concurrent/
    ...
     0 Tue Jan 20 17:17:50 EST 2015 vicinity/META-INF/maven/com.thingy.webapp/confirmassets/
  2208 Tue Jan 20 17:17:44 EST 2015 vicinity/META-INF/maven/com.thingy.webapp/confirmassets/pom.xml
   127 Tue Jan 20 16:25:22 EST 2015 vicinity/META-INF/maven/com.thingy.webapp/confirmassets/pom.properties

这是插件xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.thingy.webapp.confirmassets.ToolbarResourcesUrlTester</mainClass>
                    </manifest>
                </archive>
                <descriptors>
                    <descriptor>src/main/resources/dist.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这里是dist.xml:

<?xml version='1.0' encoding='UTF-8'?>
<assembly>
    <id>confirm-assets</id>
    <formats>
        <format>jar</format>
    </formats>

    <dependencySets>
        <dependencySet>
            <scope>runtime</scope>
            <unpack>true</unpack>
            <unpackOptions>
                <excludes>
                    <exclude>**/LICENSE*</exclude>
                    <exclude>**/README*</exclude>
                </excludes>
            </unpackOptions>
        </dependencySet>
    </dependencySets>

    <fileSets>
        <fileSet>
            <directory>${project.build.outputDirectory}</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>src/main/resources/META-INF/services</directory>
            <outputDirectory>META-INF/services</outputDirectory>
        </fileSet>
    </fileSets>    
</assembly>

ETA:“附近”前置来自父母pom <build><finalName>vicinity</finalName>...</build>。但是将它添加到jar中包含的每个文件和依赖项都没有意义。我尝试用模块的pom中的空<finalName></finalName>标记覆盖,但后来我得到了一个破折号。我如何完全摆脱这一点,只是在jar中包含正确命名的内容?

另外:我遇到的问题是,当我尝试从命令行运行我的主类时,我得到:

 $ java -jar vicinity-confirm-assets.jar 
Error: Could not find or load main class com.thingy.webapp.confirmassets.ToolbarResourcesUrlTester

此外,还有两个MANIFEST.MF文件。

$ jar -tvf vicinity-confirm-assets.jar | grep MANI
   213 Tue Jan 20 18:07:26 EST 2015 META-INF/MANIFEST.MF
   134 Thu Nov 13 20:52:14 EST 2014 vicinity/META-INF/MANIFEST.MF

第一个:

Manifest-Version: 1.0
Built-By: barclaydunn
Build-Jdk: 1.6.0_65
Created-By: Apache Maven 3.1.1
Main-Class: com.thingy.webapp.confirmassets.ToolbarResourcesUrlTest
 er
Archiver-Version: Plexus Archiver

第二个:

Manifest-Version: 1.0
Built-By: slandelle
Build-Jdk: 1.7.0_65
Created-By: Apache Maven 3.2.2
Archiver-Version: Plexus Archiver

我猜测有两个因为,并且前置来自,这是一个子模块的事实。第二个来自父母pom,我猜。

我是否尝试做一些不能/不应该做的事情?

1 个答案:

答案 0 :(得分:0)

如果其他人遇到此问题,我发现您可以控制基础目录是否包含在dist.xml中的<includeBaseDirectory>false</includeBaseDirectory>

<?xml version='1.0' encoding='UTF-8'?>
<assembly>
    <id>confirm-assets</id>
    <formats>
        <format>jar</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>
    ...

有关详细信息,请参阅http://maven.apache.org/plugins/maven-assembly-plugin/advanced-descriptor-topics.html#Using_an_Alternative_Assembly_Base_Directory