【问题标题】:Maven 3.0.5 and IntelliJ 12 building two jar filesMaven 3.0.5 和 IntelliJ 12 构建两个 jar 文件
【发布时间】:2013-03-17 13:52:43
【问题描述】:

我正在使用带有 IntelliJ 12 的 Maven 3.0.5,并且我的 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>

抱歉格式化。

【问题讨论】:

  • 你的根项目是否有如下配置&lt;packaging&gt;jar&lt;/packaging&gt;?如果是这样,请将其更改为&lt;packaging&gt;pom&lt;/packaging&gt;
  • 谢谢!我认为这很完美。

标签: java jar intellij-idea maven-3


【解决方案1】:

pom reference page 中所述,您要链接到:

聚合(或多模块)

具有模块的项目称为多模块或聚合器项目。模块是这个 POM 列出的项目,并作为一个组执行。一个 pom 打包的项目可以通过将一组项目作为模块列出来聚合它们的构建,这些模块是这些项目的相对目录。

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

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

【讨论】:

    猜你喜欢
    • 2013-03-01
    • 1970-01-01
    • 2016-01-27
    • 2011-08-09
    • 2013-07-15
    • 2013-03-21
    • 2016-05-01
    • 2014-06-05
    • 1970-01-01
    相关资源
    最近更新 更多