我正在用Maven创建一个多模块项目的estructure。父母的pom:
<?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>cat.base.gpt</groupId>
<artifactId>gpt</artifactId>
<version>0.0.1</version> <!-- application version -->
<packaging>pom</packaging>
<name>gpt</name>
<parent>
<groupId>cat.base.baseframe</groupId>
<artifactId>projecte-pare-baseframe</artifactId>
<version>0.0.11.a</version>
</parent>
<modules>
<module>gpt.domini</module>
<module>gpt.ui</module>
<module>gpt.logica</module>
<module>gpt.ejb</module>
<module>gpt.ear</module>
</modules>
<dependencies>
<!-- dependencies pel testeig TDD -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5-rc1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kubek2k</groupId>
<artifactId>springockito</artifactId>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<!-- A més, en el cas de provatures UI, s'ha d'afegir la següent dependència:-->
<dependency>
<groupId>cat.base.baseframe</groupId>
<artifactId>baseframe-test-swf</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
好的,第一个问题,我把所有依赖项都放在paren的pom上,这真的正确吗?
最有趣的部分是,我不知道如何编译grafic interfade项目(我称之为ui),最好是开战或创建并听取所有必要的(ui + logica + domini + ejb)对此我有点困惑,我使用已创建的项目进行工作。希望您能理解我的问题,我把剩下的pom放在眼里。ty。
pom's gpt.domini.
<?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>
<artifactId>gpt</artifactId>
<groupId>cat.base.gpt</groupId>
<version>0.0.1</version>
</parent>
<groupId>cat.base.gpt.domini</groupId>
<artifactId>gpt.domini</artifactId>
<packaging>jar</packaging>
<name>gpt.domini</name>
<description>Definició del model de dades i de la façana del servei</description>
</project>
pom的gpt.ear
<?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>
<artifactId>gpt</artifactId>
<groupId>cat.base.gpt</groupId>
<version>0.0.1</version>
</parent>
<groupId>cat.base.gtp.ear</groupId>
<artifactId>gpt.ear</artifactId>
<name>gpt.ear</name>
<packaging>ear</packaging>
<description>Paquet de l'aplicació J2EE</description>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}.domini</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}.ejb</artifactId>
<version>${project.parent.version}</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}.logica</artifactId>
<version>${project.parent.version}</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
pom的gpt.logica
<?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>
<artifactId>gpt</artifactId>
<groupId>cat.base.gpt</groupId>
<version>0.0.1</version>
</parent>
<groupId>cat.base.gtp.logica</groupId>
<artifactId>gpt.logica</artifactId>
<name>climbing.logica</name>
<packaging>jar</packaging>
<description>Implementació del servei</description>
<dependencies>
<!-- de moment nomes el domini -->
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}.domini</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
pom的gpt.ejb
<?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>
<artifactId>gpt</artifactId>
<groupId>cat.base.gpt</groupId>
<version>0.0.1</version>
</parent>
<groupId>cat.base.gtp.ejb</groupId>
<artifactId>gpt.ejb</artifactId>
<name>gpt.ejb</name>
<packaging>ejb</packaging>
<description>Publicació d'un servei en forma EJB</description>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}.domini</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}.logica</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}.logica</artifactId>
<version>${project.parent.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-annotations-ejb3</artifactId>
<version>4.2.2.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>2.5.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.client</groupId>
<artifactId>jbossall-client</artifactId>
<version>4.2.3.GA</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
pom的gpt.logica
<?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>
<artifactId>gpt</artifactId>
<groupId>cat.base.gpt</groupId>
<version>0.0.1</version>
</parent>
<groupId>cat.base.gtp.logica</groupId>
<artifactId>gpt.logica</artifactId>
<name>climbing.logica</name>
<packaging>jar</packaging>
<description>Implementació del servei</description>
<dependencies>
<!-- de moment nomes el domini -->
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}.domini</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
pom的gpt.ui
这是spring-rich.faces ..的所有依赖项,还是父母的pom更好的依赖项?包装像一场战争?或在模块耳内??ty。
尽管已经有了一个可以接受的答案,但我认为值得向您提供更多信息,因为在我看来,发问者和被接受的答案都被Maven中的不同概念弄得一团糟。
Maven中经常混淆两个概念。聚合(又称为多模块)POM和父POM是无关紧要的,尽管可以使用一个POM为这两个目的服务。
多模块项目旨在描述项目之间的聚合关系,以便我们可以将多个相关项目作为一个整体构建,而所有子项目都构建在同一反应堆中。父项目旨在提供共享的项目设置。它甚至可以存在于项目结构之外(例如,我可能有一个公司级的父POM)
我个人建议仅使用多模块POM声明项目的聚合(层次结构),并建议使用单独的父POM声明共享设置。
IE
my-proj // aggregation only
+ my-proj-parent // parent POM
+ my-proj-main
+ my-proj-web
+ my-proj-ear
同样,这是两个单独的概念。
可以将依赖项放在父POM中。当您将其放在此处时,这意味着继承的项目将具有这种依赖性。只要您知道自己在做什么,就没有对与错(我个人使用的是不同的方式,稍后将进行介绍)。
但是,是将共享的JAR放在EAR中并保持瘦的WAR,还是将普通的EAR带有“完整”的WAR与您的依赖关系无关。更多关于EAR的包装策略。因此,更改Maven依赖项的范围只是因为您要将项目打包为一场枯燥的战争,所以这种方法只是弄乱了整个Maven依赖项的概念。更可怕的是,在创建EAR时,您需要找出其包含的WAR的所有依赖性并将其逐个添加到EAR POM中,这无疑不是最佳解决方案
可惜的是,当前的Maven EAR插件仍然没有办法声明一个瘦小的战争包装策略。但是,有一些变通办法可以使您做到这一点,而又不会弄乱Maven依赖范围。http://maven.apache.org/plugins/maven-ear-plugin/examples/skinny-wars.html http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html
(更新:该瘦战争receipe似乎更新和解决方法的人似乎不见了http://docs.codehaus.org/display/MAVENUSER/Solving+the+Skinny+Wars+problem?focusedCommentId=212631587#comment-212631587这是将WAR类型的POM作为POM类型包括在内,因此我们无需再次在EAR中声明依赖项)
如前所述,将依赖项放在父级中没有对与错。但是,您应该知道,这种方式实际上意味着所有继承的项目都将具有这种依赖关系,这在大多数情况下是不正确的。
例如,我在下有一个foo-a
和foo-b
项目foo
,这两个项目都继承foo-parent
。假设foo-a正在使用,spring-core
而foo-b的整个逻辑与它无关,如果将spring-core作为依赖项放在foo-parent中,当您查看foo-b时,它不必要地具有不相关的依赖项spring-core 。
正确的方法是仅在父POM中包括依赖项(和其他设置),这些依赖项应在所有继承的项目之间共享。例如,与单元测试相关的依赖关系可能是一个不错的选择。集成测试的依赖关系可能是另一个示例。
但是,这并不意味着我们应该在每个项目中分别声明依赖项。最大的问题之一是这种方法将很难在整个项目中维护相同版本的依赖关系。
为了解决此问题,我的建议是dependencyManagement
在父POM中使用,该POM声明版本(可能还包括除范围之外的其他设置)。声明dependencyManagement不会在继承的POM中引入实际的依赖关系。它只是声明:“如果声明了这种依赖关系,这将是要使用的设置”。在每个继承的POM中,只需声明依赖项的组和工件(以及某些项目特定的设置),以便您可以遵循父POM中声明的版本。
也许有点难以理解,下面是一个示例:
富父母
<project>
<dependencyManagement> // dependency management doesn't bring actual dependency
<dependencies>
<dependency>
<groupId>org.springframework<groupId>
<artifactId>spring-core<artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate<groupId>
<artifactId>hibernate-core<artifactId>
<version>3.6</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies> // actual shared dependency
<dependency>
<groupId>junit<groupId>
<artifactId>junit<artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
.....
<project>
富
<project>
<dependencies>
<dependency> // note: no version declared
<groupId>org.springframework<groupId>
<artifactId>spring-core<artifactId>
</dependency>
// junit dependency is inherited
<dependencies>
<project>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句