2013-02-16 81 views
0

我是新来创造之间的战争和罐子之间的沟通和沟通...战争与内耳之间的沟通

我有两个战争具有完全独立的功能。 现在我必须创建一个耳朵,其中两个应用程序必须在相同的功能上工作, 它被包含在一个jar中。但要求是我不能在两个包含Pom.xml的jar中使用该jar,所有3个都在单耳下。这可能吗? 我已经测试了两次独立战争的耳朵,它现在工作正常,上面如何实现我没有得到这个。
我使用Maven和Jboss7.1.1。
我通过链接像MessageHandler in JAR/WAR/EARhttps://stackoverflow.com/questions/1796255/tell-me-a-clear-differnece-between-ear-war-and-jar,但不知道上述问题。

回答

0
Hi got the solution >> here it is.. this is a pom.xml of ear project 


<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>Test</groupId> 
    <artifactId>Test</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>ear</packaging> 

<dependencies> 
    <!--Dependency for jar--> 
    <dependency> 
     <groupId>com.jar</groupId> 
     <artifactId>com.jar</artifactId> 
     <version>1.0</version> 
     <type>war</type> 
    </dependency> 
    <!--Dependency for war1--> 
    <dependency> 
     <groupId>com.war2</groupId> 
     <artifactId>com.war2</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
     <type>war</type> 
    </dependency>  
    <!--Dependency for war2--> 
    <dependency> 
     <groupId>com.war1</groupId> 
     <artifactId>com.war1</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
     <type>war</type> 
    </dependency> 
</dependencies> 

<build> 
    <finalName>Project</finalName> 
    <plugins> 
     <plugin> 
      <artifactId>maven-ear-plugin</artifactId> 
      <version>2.8</version> 
      <configuration> 
       <finalName>MyEarFile</finalName> 
       <version>5</version> 
       <modules> 
        <!--Webmodule for war1--> 
        <webModule> 
         <groupId>com.war1</groupId> 
         <artifactId>com.war1</artifactId> 
         <uri>war1.war</uri> 
         <bundleFileName>war1.war</bundleFileName> 
        </webModule> 

        <!--Webmodule for war2--> 
        <webModule> 
         <groupId>com.war2</groupId> 
         <artifactId>com.war2</artifactId> 
         <uri>war2.war</uri> 
         <bundleFileName>war2.war</bundleFileName> 
        </webModule> 
       </modules> 
      </configuration> 
     </plugin> 
    </plugins> 
    </build> 
</project> 




Note:: groupId and artifactId metioned here must match with groupId and artifactId mentioned in the project's pom.xml. 
Also dependency of jar must be present in this i.e. ear's pom.xml and not in both app's pom.xml. 
At time of maven install it automatically refers to jar's contents.. 
0

你可以将多个战争和罐子放入耳朵,他们可以共享同一个类加载器。这意味着所有的课程都可以从所有的罐子/战争中获得。即好像所有的类/资源都在一个档案中而没有子包装。

我假设这是你所说的“战争与罐子之间的沟通”。

编辑:检查Making an EAR with Maven作为构建耳朵的pom.xml的示例。在这个例子中,有一个罐子和一个战争,但你可以有任何数量的战争/罐子。

+0

感谢您的回复我是新来this.http://stackoverflow.com/questions/5337784/separate-same-jars-in-different-war-of-a-ear我想是这样这是两个应用程序访问相同的jar。但我没有得到如何使用'maven'来完成这项工作。 – vg123 2013-02-16 11:16:02

+0

也一旦依赖的应用程序,从pom.xml中删除,那么它不会创建战争,然后如何通过从耳朵提供参考jar来创建战争? – vg123 2013-02-16 11:24:34

+0

如果我理解你的问题,那么你只需参考构建耳朵的pom中的罐子/战争。 – 2013-02-16 11:40:41