2

我正在尝试为 Java 项目生成一个 jar,然后使用 maven-assembly-plugin 压缩 jar 文件和 lib 目录,但它不包含 zip 文件中的项目 jar。无论我尝试什么都有一些问题。有没有人有类似的例子?

4

2 回答 2

2

尝试这个

pom.xml

...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                    <descriptors>
                        <descriptor>src/assembly/assembly.xml</descriptor>
                    </descriptors>
                </configuration>
            </plugin>
...

程序集.xml

<assembly>
    <id>assembly</id>
    <formats>
        <format>zip</format>
    </formats>
    <dependencySets>
        <dependencySet>
            <useProjectArtifact>false</useProjectArtifact>
            <outputDirectory>/lib</outputDirectory>
            <unpack>false</unpack>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>
于 2013-08-08T10:07:52.203 回答
0

我有一个例子,它创建了一个里面有一个罐子的吃模块。看看也许可以帮助你。

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>cat.base.gpt</groupId>
    <artifactId>gpt</artifactId>
    <version>0.0.1</version>
  </parent>

  <artifactId>gpt.ear</artifactId>
  <name>gpt.ear</name>
  <packaging>ear</packaging>
  <description>Paquet de l'aplicació J2EE</description>

  <dependencies>
  <!-- 
  dependencies definides al pom-pare é sncessari especificar el type
  ja que per defecte type=jar 
   -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>gpt.domini</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>gpt.ejb</artifactId>
            <type>ejb</type>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>gpt.logica</artifactId>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>gpt.ui</artifactId>
            <type>war</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <configuration>
                    <description>GPT</description>
                    <displayName>Gestió posicions tributarias</displayName>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <version>1.4</version>
                    <skinnyWars>true</skinnyWars>
                    <generateApplicationXml>true</generateApplicationXml>
                    <modules>
                        <ejbModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.parent.artifactId}.ejb</artifactId>
                            <bundleFileName>${project.parent.artifactId}-ejb.jar</bundleFileName>
                        </ejbModule>
                        <jarModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>gpt.logica</artifactId>
                            <includeInApplicationXml>true</includeInApplicationXml>
                        </jarModule>                        
                        <webModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>gpt.ui</artifactId>
                            <contextRoot>/gpt</contextRoot>
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <configuration>
                    <excludeScope>runtime</excludeScope>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
于 2013-08-08T09:55:58.607 回答