java - Maven 3.0.5 和 IntelliJ 12 构建两个 jar 文件

标签 java jar intellij-idea maven-3

我正在使用 Maven 3.0.5 和 IntelliJ 12,并且我的 pom 文件设置为构建具有依赖项的 jar。现在效果很好,但我的问题是这样的。如何告诉 pom 文件只构建一个 jar?现在我得到了一个带有依赖项的 jar,这是我想要的,但我也得到了另一个没有依赖项的 jar,我最终只是手动删除它。我在这里查看:http://maven.apache.org/pom.html看起来打包将默认构建一个 jar,即使我没有指定它,并且在 pom 的我的部分中我告诉 Maven 构建另一个 jar 文件。我可以在我的 pom 中更改什么来仅构建一个具有依赖项的 jar ?

<?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.xyz.program.test</groupId>
    <artifactId>xyz-program-test</artifactId>
    <packaging>jar</packaging>
    <version>1.2</version>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.31.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>2.31.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-htmlunit-driver</artifactId>
            <version>2.31.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-firefox-driver</artifactId>
                <version>2.31.0</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.seleniumhq.selenium</groupId>
                        <artifactId>selenium-remote-driver</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.setup.test.Setup</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

对格式表示歉意。

最佳答案

pom reference page 中所写您正在链接到:

Aggregation (or Multi-Module)

A project with modules is known as a multimodule, or aggregator project. Modules are projects that this POM lists, and are executed as a group. An pom packaged project may aggregate the build of a set of projects by listing them as modules, which are relative directories to those projects.

为了让“pom 打包项目”标记您的根项目 - 请注意打包中的 pom:

<groupId>com.xyz.program.test</groupId>
<artifactId>xyz-program-test</artifactId>
<packaging>pom</packaging>

关于java - Maven 3.0.5 和 IntelliJ 12 构建两个 jar 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15461503/

相关文章:

java - 如何在单个适配器中使用两个 Viewholder

java - 如何在运行时从文件夹或 JAR 加载类?

java - 如何使第三方 .jar 可用于我的 .jsp 页面?

intellij-idea - Intellij 在 TestNG 中运行一项测试

intellij-idea - 子类方法的搜索用法

java - 有没有一种方法可以使用 mockito 测试此类方法

java - 为什么我的代码没有在调试控制台中打印?

java - 抽象构造函数java

Spring Boot 应用程序在没有 -Djava.net.preferIPv4Stack=true 和 -Djava.net.preferIPv4Addresses 参数的情况下监听 IPv6

command-line - 如何使用不同的文件夹启动intellij idea终端?