Java 从单个Maven项目构建EAR
有一个Maven项目,它使用JAR打包类型。现在项目已经发展,需要将其构建为EAR,包括JAR本身及其依赖项 这是否意味着我必须推出第二款带耳包装的POM?可以从单个Maven项目构建JAR+EAR吗?这背后的原因是我真的不想彻底重组我的存储库结构Java 从单个Maven项目构建EAR,java,maven,ear,maven-ear-plugin,Java,Maven,Ear,Maven Ear Plugin,有一个Maven项目,它使用JAR打包类型。现在项目已经发展,需要将其构建为EAR,包括JAR本身及其依赖项 这是否意味着我必须推出第二款带耳包装的POM?可以从单个Maven项目构建JAR+EAR吗?这背后的原因是我真的不想彻底重组我的存储库结构 如果不可能,我想我需要以某种方式重新组织项目结构,以利用Maven模块。在这种情况下,您会推荐什么(子)模块结构?我认为您可以在每次构建项目时使用maven war插件生成单个war文件 <build> <plugins>
如果不可能,我想我需要以某种方式重新组织项目结构,以利用Maven模块。在这种情况下,您会推荐什么(子)模块结构?我认为您可以在每次构建项目时使用maven war插件生成单个war文件
<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>
org.apache.maven.plugins
maven耳朵插件
2.3.2
您将需要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>
4.0.0
com.greg
4.0.0
com.greg
耳朵示例
1.0-快照
示例耳
耳朵
com.greg
示例罐
${project.version}
maven耳朵插件
2.10.1
一般来说,你可以,但这不是一个好主意……最好是创建一个带有ear包装的模块,一个带有jar包装和父级的模块,将所有组件绑定在一起……分离关注点。。。
<?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>
<?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>