2017-01-18 102 views
0

有一个Maven项目曾经有JAR包装类型。现在该项目已经发展,并且要求它被构建为EAR,包括JAR本身及其依赖项。从单个Maven项目构建EAR

这是否意味着我必须引入与EAR包装类型的第二个POM?是否可以从单个Maven项目构建JAR + EAR?这背后的原因是,我并不想从根本上重新组织我的存储库结构。

如果不可能,我想我需要以某种方式重新组织项目结构以使用Maven模块。在这种情况下,你会推荐什么(子)模块结构?

+0

一般来说,你可以但不是一个好主意......更好的做法是用耳朵包装创建一个模块,一个使用罐子包装和父母将所有这些结合在一起......分离关注点...... – khmarbaise

回答

1

您将需要3 POM,这里是一个工作示例;

POM 1是父

<?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.greg</groupId> 
    <artifactId>ear-example</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <name>ear-example</name> 
    <modules> 
    <module>example-jar</module> 
    <module>example-ear</module> 
    </modules> 

</project> 

POM 2是罐子或战争

<?xml version="1.0"?> 
<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>com.greg</groupId> 
    <artifactId>ear-example</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>example-jar</artifactId> 
    <packaging>jar</packaging> 

    <name>com.greg</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 
</project> 

POM 3是具有一个依赖于罐/战争

<?xml version="1.0"?> 
<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>com.greg</groupId> 
    <artifactId>ear-example</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>example-ear</artifactId> 
    <packaging>ear</packaging> 

    <dependencies> 
    <dependency> 
     <groupId>com.greg</groupId> 
     <artifactId>example-jar</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
    <plugin> 
     <artifactId>maven-ear-plugin</artifactId> 
     <version>2.10.1</version> 
     <configuration> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 

</project> 
0

我想你可以使用Maven插件战争产生一个战争文件每次生成项目

<build> 
<plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-ear-plugin</artifactId> 
    <version>2.3.2</version> 
    <!-- configuring the ear plugin --> 
    <configuration> 
     <modules> 
     <!-- all your modles --> 
     </modules> 
    </configuration> 
    </plugin> 
</plugins>