创建一个具有依赖关系的罐子 [英] creating a jar-with-dependencies

查看:76
本文介绍了创建一个具有依赖关系的罐子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在mvn 3.0.3中创建一个jar-with-dependencies.我已经在一个项目中成功完成了此任务(仅使用mvn install),并创建了完整的jar-wth-dependencies.我将相关的POM代码块(其他人写的<plugins>...</plugins>!)复制到了当前项目中(不同之处在于它具有程序集).它创建普通快照jar(jumbo-converters-compchem-gaussian-0.3-SNAPSHOT.jar),但不创建jar-with-dependencies.我应该如何修改POM?

I am creating a jar-with-dependencies in mvn 3.0.3. I have successfully done this in one project (using just mvn install) and created a complete jar-wth-dependencies. I copied the relevant chunk of POM code (<plugins>...</plugins>, which someone else wrote!) to the current project (which differs in that it has assemblies). It creates the normal snapshot jar (jumbo-converters-compchem-gaussian-0.3-SNAPSHOT.jar) but no jar-with-dependencies. How should I amend the POM?

<?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>cml</groupId>
    <artifactId>jumbo-converters</artifactId>
    <version>0.3-SNAPSHOT</version>
    <relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>jumbo-converters-compchem-gaussian</artifactId>
<name>jumbo-converters-compchem-gaussian</name>

<dependencies>
    <dependency>
        <groupId>${jumbo.groupId}</groupId>
        <artifactId>jumbo</artifactId>
    </dependency>
    <dependency>
        <groupId>cml</groupId>
        <artifactId>jumbo-converters-core</artifactId>
    </dependency>
    <dependency>
        <groupId>cml</groupId>
        <artifactId>jumbo-converters-compchem-common</artifactId>
        <version>0.3-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>cml</groupId>
        <artifactId>jumbo-converters-templates</artifactId>
        <version>0.3-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>cml</groupId>
        <artifactId>jumbo-converters-testutils</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>cml</groupId>
        <artifactId>jumbo-converters-compchem-testutils</artifactId>
        <scope>test</scope>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>org.xmlcml.cml.converters.compchem.gaussian.GaussianLogXML2CompchemConverter</mainClass>
                    </manifest>
                </archive>
                <excludes>
                    <exclude>.hgsub</exclude>
                    <exclude>**/.hg/</exclude>
                    <exclude>**/.project</exclude>
                    <exclude>**/external/</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>org.xmlcml.cml.converters.compchem.gaussian.GaussianLogXML2CompchemConverter</mainClass>
                    </manifest>
                </archive>
                <excludes>
                    <exclude>.hgsub</exclude>
                    <exclude>**/.hg/</exclude>
                    <exclude>**/.project</exclude>
                    <exclude>**/external/</exclude>
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

推荐答案

首先, 使用Maven依赖插件来检索/存储依赖(更多信息,请此处)到您的项目文件夹. 例如:说出lib文件夹.

First, Use maven dependency plugin to retrieve/store the dependencies (more info here) to your project folder. Ex: Say lib folder.

现在将这个lib文件夹标记为"Resources"文件夹. 喜欢,

Now mark this lib folder as a "Resources" folder. Like,

<resources>
  <resource>
    <directory>lib</directory>
    <targetPath>lib</targetPath>
  </resource>
</resources>

现在mvn install应该在最终工件中包含依赖项. (将Shinchan的评论复制到此处,以便将其格式化:

Now mvn install should include the dependencies in your final artifact. (copying Shinchan's comment to here so it can be formatted:

简单地将其添加到ur pom.

Simple add this to ur pom.

<build>
    <resources>
        <resource>
            <directory>lib</directory>
            <targetPath>lib</targetPath>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
            <executions>
                <execution>

                    <phase>install</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build> 

这篇关于创建一个具有依赖关系的罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆