Maven EAR 插件模块

huangapple go评论68阅读模式
英文:

Maven EAR Plugin Modules

问题

构建一个使用Maven的Java EE应用程序,可以使用以下配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <version>3.0.2</version>
    <configuration>
        <modules>
            <webModule>
               [..]
            </webModule>
            <ejbModule>
                [..]
            </ejbModule>
            <jarModule>
                [..]
            </jarModule>
        </modules>
    </configuration>
</plugin>

我理解Web模块与其他模块的打包方式不同,例如,位于ear的根目录,并将其自身的依赖项打包到WEB-INF/lib目录下。

那么Jar模块和EJB模块有什么不同呢?它们彼此之间有什么区别?
以及将Jar定义为普通依赖项和/或将其定义为jarModuleejbModule之间有什么区别?

更准确地说,以下设置之间有什么区别:

1. 将EJB模块定义为ejbModule

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <modules>
                        <webModule>
                            [..]
                        </webModule>
                        <ejbModule>
                             <groupId>org.example</groupId>
                             <artifactId>helloworld-model</artifactId>
                            <version>1.0-SNAPSHOT</version>
                        </ejbModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<dependencies>
    
</dependencies>

2. 将EJB模块定义为依赖项

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <modules>
                        <webModule>
                            [..]
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<dependencies>
    <dependency>
        <groupId>org.example</groupId>
        <artifactId>helloworld-model</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

3. 将EJB/Jar定义为jarModule

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <modules>
                        <webModule>
                            [..]
                        </webModule>
                        <jarModule>
                            <groupId>org.example</groupId>
                             <artifactId>helloworld-model</artifactId>
                            <version>1.0-SNAPSHOT</version>
                        </jarModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

4. 将EJB/Jar定义为依赖项

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <modules>
                        <webModule>
                            [..]
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<dependencies>
    <dependency>
        <groupId>org.example</groupId>
        <artifactId>helloworld-model</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>
英文:

To build a Java EE application with Maven, one can use the following configuration:

            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-ear-plugin&lt;/artifactId&gt;
                &lt;version&gt;3.0.2&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;modules&gt;
                        &lt;webModule&gt;
                           [..]
                        &lt;/webModule&gt;
                        &lt;ejbModule&gt;
                            [..]
                        &lt;/ejbModule&gt;
                        &lt;jarModule&gt;
                            [..]
                        &lt;/jarModule&gt;
                    &lt;/modules&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;

I understand that the web module is packaged differently from other modules, that is, for example, being located at the root of the ear and having packed it's own dependencies to WEB-INF/lib.

But what about jar and ejb modules? How are they different from each other?
And what is the difference of defining a jar as a normal dependency and/or defining it as a jarModule or ejbModule?

Beeing more precise, what is the difference between the following setups:

1. ejb module defined as ejbModule

&lt;build&gt;
    &lt;pluginManagement&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-ear-plugin&lt;/artifactId&gt;
                &lt;version&gt;3.0.2&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;modules&gt;
                        &lt;webModule&gt;
                            [..]
                        &lt;/webModule&gt;
                        &lt;ejbModule&gt;
                             &lt;groupId&gt;org.example&lt;/groupId&gt;
                             &lt;artifactId&gt;helloworld-model&lt;/artifactId&gt;
                            &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
                        &lt;/ejbModule&gt;
                    &lt;/modules&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/pluginManagement&gt;
&lt;/build&gt;


&lt;dependencies&gt;
    
&lt;/dependencies&gt;

2. ejb module defined as dependency

&lt;build&gt;
    &lt;pluginManagement&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-ear-plugin&lt;/artifactId&gt;
                &lt;version&gt;3.0.2&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;modules&gt;
                        &lt;webModule&gt;
                            [..]
                        &lt;/webModule&gt;
                    &lt;/modules&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/pluginManagement&gt;
&lt;/build&gt;


&lt;dependencies&gt;
    &lt;depdendency&gt;
        &lt;groupId&gt;org.example&lt;/groupId&gt;
        &lt;artifactId&gt;helloworld-model&lt;/artifactId&gt;
        &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;

3. ejb/jar defined as jarModule

&lt;build&gt;
    &lt;pluginManagement&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-ear-plugin&lt;/artifactId&gt;
                &lt;version&gt;3.0.2&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;modules&gt;
                        &lt;webModule&gt;
                            [..]
                        &lt;/webModule&gt;
                        &lt;jarModule&gt;
                            &lt;groupId&gt;org.example&lt;/groupId&gt;
                             &lt;artifactId&gt;helloworld-model&lt;/artifactId&gt;
                            &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
                        &lt;/jarModule&gt;
                    &lt;/modules&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/pluginManagement&gt;
&lt;/build&gt;

4. ejb/jar defined as dependency

&lt;build&gt;
    &lt;pluginManagement&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-ear-plugin&lt;/artifactId&gt;
                &lt;version&gt;3.0.2&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;modules&gt;
                        &lt;webModule&gt;
                            [..]
                        &lt;/webModule&gt;
                    &lt;/modules&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/pluginManagement&gt;
&lt;/build&gt;


&lt;dependencies&gt;
    &lt;depdendency&gt;
        &lt;groupId&gt;org.example&lt;/groupId&gt;
        &lt;artifactId&gt;helloworld-model&lt;/artifactId&gt;
        &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;

答案1

得分: 1

回答你问题的一部分:

EJB(Enterprise JavaBeans)的构件放在EAR(Enterprise Archive)的主目录中,而JAR(Java Archive)的构件放在lib目录中。

英文:

To answer a part of your question:

EJB artifacts go to the main directory of the EAR, while JAR artifacts go to the lib dir.

huangapple
  • 本文由 发表于 2020年10月1日 17:28:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/64152553.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定