创建一个“应用程序客户端”在Java EE中使用Maven [英] Create an "Application Client" with Maven in Java EE

查看:163
本文介绍了创建一个“应用程序客户端”在Java EE中使用Maven的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试创建一个基于maven的企业应用程序,其中包含一个在GlassFish的应用程序客户端容器中运行的应用程序客户端。它应该适合作为Netbeans企业应用程序+企业应用程序客户端的项目模板,但使用maven而不是ant。





到目前为止,我有以下项目:


  • 汇编Maven项目

  • EAR-Module

  • EJB模块

  • WEB-Module(适用于耳内)
  • Swing Client Module


  • $ b

    程序集pom.xml如下所示:


    $ b

     < project xml ... 
    < modules>
    < module> shop-ear< / module>
    < module> shop-web< / module>
    < module> shop-ejb< / module>
    < module> shop-client< / module>
    < / modules>
    < / project>

    ear pom.xml包含

     < project ...> 
    < modelVersion> 4.0.0< / modelVersion>
    < parent>
    < artifactId>商店< / artifactId>
    < groupId> my.package.name< / groupId>
    < version> 1.0-SNAPSHOT< / version>
    < / parent>
    < groupId> ch.hslu.edu.enapp< / groupId>
    < artifactId>店铺耳朵< / artifactId>
    < version> 1.0-SNAPSHOT< / version>
    <包装>耳朵< /包装>
    <! - ... - >
    <依赖关系>
    < dependency>
    < groupId> my.package.name< / groupId>
    < artifactId> shop-ejb< / artifactId>
    < version> 1.0-SNAPSHOT< / version>
    < type> ejb< / type>
    < /依赖关系>
    < dependency>
    < groupId> my.package.name< / groupId>
    < artifactId> shop-web< / artifactId>
    < version> 1.0-SNAPSHOT< / version>
    < type> war< / type>
    < /依赖关系>
    < dependency>
    < groupId> my.package.name< / groupId>
    < artifactId> shop-client< / artifactId>
    < version> 1.0-SNAPSHOT< / version>
    < type> jar< / type>
    < /依赖关系>
    < /依赖关系>

    Swing Client pom.xml包含

    < pre class =lang-xml prettyprint-override> < project xmlns = ....>
    < modelVersion> 4.0.0< / modelVersion>
    < parent>
    < artifactId>商店< / artifactId>
    < groupId> my.package.name< / groupId>
    < version> 1.0-SNAPSHOT< / version>
    < / parent>

    < groupId> my.package.name< / groupId>
    < artifactId> shop-client< / artifactId>
    < version> 1.0-SNAPSHOT< / version>
    <包装> jar< / packaging>
    <名称> shop-client< / name>
    < build>
    < plugins>
    < plugin>
    < groupId> org.apache.maven.plugins< / groupId>
    < artifactId> maven-compiler-plugin< / artifactId>
    < version> 2.3.2< / version>
    <配置>
    < source> 1.6< / source>
    < target> 1.6< / target>
    < / configuration>
    < / plugin>
    < plugin>
    < groupId> org.apache.maven.plugins< / groupId>
    < artifactId> maven-jar-plugin< / artifactId>
    < version> 2.3.1< / version>
    <配置>
    <档案>
    < manifest>
    < mainClass> my.package.name.Main< / mainClass>
    < / manifest>
    < / archive>
    < / configuration>
    < / plugin>
    < / plugins>
    < / build>
    < repositories>
    < repository>
    < url> http://download.java.net/maven/2/< / url>
    < id> java.net< / id>
    < layout>预设< / layout>
    < name> java.net< / name>
    < / repository>
    < / repositories>
    <属性>
    < project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding>
    < / properties>

    <依赖关系>
    < dependency>
    < groupId> junit< / groupId>
    < artifactId> junit< / artifactId>
    < version> 3.8.1< / version>
    < scope> test< / scope>
    < /依赖关系>
    < dependency>
    < groupId> org.jdesktop< / groupId>
    < artifactId> beansbinding< / artifactId>
    < version> 1.2.1< / version>
    < type> jar< / type>
    < scope>编译< / scope>
    < /依赖关系>
    < /依赖关系>
    < / project>

    目前我在Swing Client和EJB模块之间没有依赖关系。我只想得到一个简单的Swing表单,并且使用了ACC表单GlassFish(v 3.1.1)。



    但这不起作用。 Swing客户端打包到耳朵文件中的lib文件夹中,我无法启动它。



    你知道一个教程或例子来完成这个任务吗?

    你的耳朵需要配置耳塞才行(可能你把它放进你的问题时就把它丢掉了) :

     < plugins> 
    < plugin>
    < groupId> org.apache.maven.plugins< / groupId>
    < artifactId> maven-ear-plugin< / artifactId>
    < version> 2.3.2< / version>
    <配置>
    < version> 6< / version>
    < generateApplicationXml> true< / generateApplicationXml>
    < defaultLibBundleDir> lib< / defaultLibBundleDir>
    <模块>
    < webModule>
    < groupId> com.foo< / groupId>
    < artifactId> shop-web< / artifactId>
    < contextRoot> webstuff< / contextRoot>
    < / webModule>
    < ejbModule>
    < groupId> com.foo< / groupId>
    < artifactId> shop-ejb< / artifactId>
    < classifier>单个< / classifier>
    < bundleFileName> shop-ejb.jar< / bundleFileName>
    < / ejbModule>
    < jarModule>
    < groupId> com.foo< / groupId>
    < artifactId> shop-client< / artifactId>
    < bundleDir> /< / bundleDir>
    < bundleFileName> shop-client.jar< / bundleFileName>
    < includeInApplicationXml> true< / includeInApplicationXml> <! - 我不记得这是否绝对必要 - >
    < / jarModule>
    < / modules>
    < / configuration>
    < / plugin>



    这会打包您的应用程序客户端jar文件夹之外的jar文件,并且会帮助你为你的war模块定义上下文根(没有另外一种方法可以找到)。 bundleFileName对于让URL启动客户端更有意义很重要。



    我不知道有一个教程能够将这一切放在一起,但是一些资源是:


    I am trying to create a maven based Enterprise Application with an Application Client which runs in the Application Client Container from GlassFish. It should fit togheter as the Project template from Netbeans "Enterprise Application" + "Enterprise Application Client" but with maven and not ant.

    Until now I have following projects

    • Assembly Maven Project
    • EAR-Module
    • EJB-Module
    • WEB-Module (works well with inside the ear)
    • Swing Client Module

    The Assembly pom.xml looks like:

        <project xml...
          <modules>
            <module>shop-ear</module>
            <module>shop-web</module>
            <module>shop-ejb</module>
            <module>shop-client</module>
          </modules>
        </project>
    

    The ear pom.xml contain

    <project ...>
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <artifactId>shop</artifactId>
        <groupId>my.package.name</groupId>
        <version>1.0-SNAPSHOT</version>
      </parent>
      <groupId>ch.hslu.edu.enapp</groupId>
      <artifactId>shop-ear</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>ear</packaging>
      <!-- ... -->
      <dependencies>
        <dependency>
            <groupId>my.package.name</groupId>
            <artifactId>shop-ejb</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>ejb</type>
        </dependency>
        <dependency>
            <groupId>my.package.name</groupId>
            <artifactId>shop-web</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>my.package.name</groupId>
            <artifactId>shop-client</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    

    And the Swing Client pom.xml contains

    <project xmlns=....>
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <artifactId>shop</artifactId>
            <groupId>my.package.name</groupId>
            <version>1.0-SNAPSHOT</version>
        </parent>
    
        <groupId>my.package.name</groupId>
        <artifactId>shop-client</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
        <name>shop-client</name>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.3.1</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>my.package.name.Main</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <repositories>
            <repository>
                <url>http://download.java.net/maven/2/</url>
                <id>java.net</id>
                <layout>default</layout>
                <name>java.net</name>
            </repository>
        </repositories>
        <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>
            <dependency>
                <groupId>org.jdesktop</groupId>
                <artifactId>beansbinding</artifactId>
                <version>1.2.1</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
        </dependencies>
    </project>
    

    Currently I have no dependencies between the Swing Client and the EJB Module. I just want to get a simple Swing form up and running out of the ACC form GlassFish (v 3.1.1).

    But this doesn't work. The Swing-Client is packed into the lib folder inside the ear-file and I can not start it.

    Do you know a tutorial or example which fulfill this task?

    解决方案

    Your ear pom needs to configure the ear plugin like (maybe you just left it out when you put it into your question?):

    <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <version>6</version>
                    <generateApplicationXml>true</generateApplicationXml>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                    <modules>
                        <webModule>
                            <groupId>com.foo</groupId>
                            <artifactId>shop-web</artifactId>
                            <contextRoot>webstuff</contextRoot>
                        </webModule>
                        <ejbModule>
                            <groupId>com.foo</groupId>
                            <artifactId>shop-ejb</artifactId>
                            <classifier>single</classifier>
                            <bundleFileName>shop-ejb.jar</bundleFileName>
                        </ejbModule>
                        <jarModule>
                            <groupId>com.foo</groupId>
                            <artifactId>shop-client</artifactId>
                            <bundleDir>/</bundleDir>
                            <bundleFileName>shop-client.jar</bundleFileName>
                            <includeInApplicationXml>true</includeInApplicationXml> <!-- i don't remember if this was absolutely necessary -->
                        </jarModule>
                    </modules>
              </configuration>
            </plugin>
    

    That will package your application client jar outside the lib folder, and will help you define the context roots for your war modules (there isn't another way that I could find). The bundleFileName was important to get the URL to launch the client to make more sense.

    I don't know of a single tutorial that puts this all together, but some resources are:

    这篇关于创建一个“应用程序客户端”在Java EE中使用Maven的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆