Maven3 中的 Java 6 企业项目 (WAR)(模块)
我在 Maven3 中基于
- http://www.sonatype.com/books/mvnex-book/reference/multimodule-web-spring.html
- http://www.znetdevelopment.com/blogs/2009/02/18 /j2ee-project-structs
具有以下结构:
- EnterpriseProject (Super POM)
- ep-model(生成 JAR)
- ep-persist(生成 JAR)
- ep-service(生成 JAR)
- ep-ui(生成 JAR)
- ep-webapp(将它们放在一起并生成 WAR)
具有依赖关系 (->; ):
ep-webapp -> ep-ui -> ep-model
-> ep-service -> ep-model
-> ep-persist -> ep-model
当我运行企业项目目标“package”时,会在 EnterpriseProject\ep-webapp\target\ 中创建 war,并且该 war 包含 所有需要的库:ep-model、ep-persist、ep-service、ep-ui。
Q1)这个解决方案正确吗?
Q2)我应该如何添加额外的模块(如何设置依赖项)?
- ep-common (生成 JAR)
- ep-ws (网络服务;生成 JAR)
我应该只将 ep-common 依赖项添加到 ep-weapp pom (仅用于将 ep-common lib 添加到 war 中)还是在我使用 ep-common 的任何地方?
ep-webapp -> ep-ui -> ep-model
-> ep-service -> ep-model
-> ep-persist -> ep-model
-> ep-common
-> ep-ws
非常感谢您的提示
我目前的解决方案: EnterpriseProject Super pom:
<modelVersion>4.0.0</modelVersion>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Enterprise Project</name>
<modules>
<module>../ep-model</module>
<module>../ep-persist</module>
<module>../ep-service</module>
<module>../ep-ui</module>
<module>../ep-webapp</module>
</modules>
ep-webapp pom:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../ep/pom.xml</relativePath>
</parent>
<artifactId>ep-webapp</artifactId>
<packaging>war</packaging>
<name>webapp</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-ui</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
ep-ui pom:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../ep/pom.xml</relativePath>
</parent>
<artifactId>ep-ui</artifactId>
<packaging>jar</packaging>
<name>ui</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
ep-model pom:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../ep/pom.xml</relativePath>
</parent>
<artifactId>ep-model</artifactId>
<packaging>jar</packaging>
<name>model</name>
ep-service pom:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../ep/pom.xml</relativePath>
</parent>
<artifactId>ep-service</artifactId>
<packaging>jar</packaging>
<name>service</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-persist</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
ep-persist pom:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../ep/pom.xml</relativePath>
</parent>
<artifactId>ep-persist</artifactId>
<packaging>jar</packaging>
<name>persist</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-model</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
I have Java 6 Enterprise project (WAR) in Maven3 created base on
- http://www.sonatype.com/books/mvnex-book/reference/multimodule-web-spring.html
- http://www.znetdevelopment.com/blogs/2009/02/18/j2ee-project-structures
with this structure:
- EnterpriseProject (Super POM)
- ep-model (produces JAR)
- ep-persist (produces JAR)
- ep-service (produces JAR)
- ep-ui (produces JAR)
- ep-webapp (puts it all together and produces WAR)
with dependencies (->):
ep-webapp -> ep-ui -> ep-model
-> ep-service -> ep-model
-> ep-persist -> ep-model
When I run Enterprise Project goal "package", war is created in EnterpriseProject\ep-webapp\target\ and this war contains
all needed libraries: ep-model, ep-persist, ep-service, ep-ui.
Q1) Is this solutions right?
Q2) How should I add additional modules (how set dependencies)?
- ep-common (produces JAR)
- ep-ws (webservices; produces JAR)
Should I only add ep-common dependency into ep-weapp pom (just for adding ep-common lib to war) or everywhere where I use ep-common?
ep-webapp -> ep-ui -> ep-model
-> ep-service -> ep-model
-> ep-persist -> ep-model
-> ep-common
-> ep-ws
Thanks a lot for tips
My present solution:
EnterpriseProject Super pom:
<modelVersion>4.0.0</modelVersion>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Enterprise Project</name>
<modules>
<module>../ep-model</module>
<module>../ep-persist</module>
<module>../ep-service</module>
<module>../ep-ui</module>
<module>../ep-webapp</module>
</modules>
ep-webapp pom:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../ep/pom.xml</relativePath>
</parent>
<artifactId>ep-webapp</artifactId>
<packaging>war</packaging>
<name>webapp</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-ui</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
ep-ui pom:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../ep/pom.xml</relativePath>
</parent>
<artifactId>ep-ui</artifactId>
<packaging>jar</packaging>
<name>ui</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
ep-model pom:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../ep/pom.xml</relativePath>
</parent>
<artifactId>ep-model</artifactId>
<packaging>jar</packaging>
<name>model</name>
ep-service pom:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../ep/pom.xml</relativePath>
</parent>
<artifactId>ep-service</artifactId>
<packaging>jar</packaging>
<name>service</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-persist</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
ep-persist pom:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ep</groupId>
<artifactId>enterprise-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../ep/pom.xml</relativePath>
</parent>
<artifactId>ep-persist</artifactId>
<packaging>jar</packaging>
<name>persist</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ep-model</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对我来说,这似乎是一组结构良好的 POM。
至于 ep-commons,我猜它是所有模块通用的东西(通用类型、异常定义等)——如果是这样,你需要在任何使用它的地方引用它,否则 Maven将无法编译它,因为它根据依赖关系创建类路径。我理解您的担忧(您必须多次重复依赖项),但由于您使用变量
${project.groupId}
和${project.version}
,您不会冒在不同的依赖项目中引用同一模块的不同版本的风险。如果您是 Maven 纯粹主义者(我会冒着声称您可能是这样的风险),您可以将 ep-commons 添加到根 POM 的
部分,但这只会拯救您每个 POM 中一行(针对版本)。需要注意的是:如果您将来要使用发布插件,则“${}”引用必须替换为硬编码的组 ID 和版本字符串,但插件会自行处理。
至于 ep-ws,我不太确定那里有什么(从 WSDL 生成的 JAX-WS 类?)。如果仅此而已,则执行与 ep-commons 相同的操作。
Seems a well-structured set of POMs to me.
As for ep-commons, I'm guessing it's stuff common to all modules (common types, exceptions definitions and such) — if so, you need to reference it wherever you use it, otherwise Maven won't be able to compile it, as it creates classpath basing on dependencies. I understand your worry (that you have to repeat the dependency many times), but since you use variables
${project.groupId}
and${project.version}
, you are not running the risk of referencing different version of the same module in different dependent projects.If you are a Maven purist, and I'll risk a claim you might be, you could add the ep-commons to a
<dependencyManagement>
section of the root POM, but that will only save you one line in each POM (for version).One notice: if you're going to use the release plugin in future, the "${}" references will have to be replaced by hard-coded group id and version strings, but the plugin takes care of that itself.
As for ep-ws, I'm not quite sure what's there (JAX-WS classes generated from WSDLs?). If only that, then do the same as for ep-commons.
谢谢MaDa的明确答复。因此,如果我理解正确,我可以(如果我是纯粹主义者:-))将所有依赖项也添加到根 POM 中,并添加到 dependencyManagement 中,并从使用给定依赖项的子项中删除版本。
我还有最后一个关于 ep-ws 的问题。也许我会使用 SpringWS & JAXB(或 Castor)(因为我更喜欢自上而下的方法和手动工作,而无需通过工具生成类,并且我不知道 JAX-WS 是否可以实现)。 Q3 ep-ws 依赖于 ep-model 和 ep-service (传递性地依赖于 ep-persist),但通常不依赖于 ep-webapp,但我需要将此依赖项添加到 ep-webapp 中,只是为了将 ep-ws 库添加到 war 中,am'我说得对吗?
关于 dependencyManagement 此博客
Thank you MaDa for your clear answer. So if I understand correctly I can (if I'm purist :-)) add all dependencies also into root POM into dependencyManagement and remove version from I children where is given dependency used.
I have the last question about ep-ws. Probably I will use SpringWS & JAXB (or Castor) (because I prefer top-down approach and manual work without generating class by tool and I don't know if it is possible by JAX-WS). Q3 ep-ws depends on ep-model and ep-service (transitively on ep-persist), but generally not on ep-webapp but I need add this dependency into ep-webapp just for adding ep-ws library into war, am'I right?
About dependencyManagement this blog
所以我重新设计了我的项目,我希望这没问题:
EnterpriseProject super pom:
webapp pom:
通用pom:
模型pom:
持久pom:
服务pom:
ui pom:
ws pom:
So I reworked my project and I hope that this is quite ok:
EnterpriseProject super pom:
webapp pom:
common pom:
model pom:
persist pom:
service pom:
ui pom:
ws pom: