使用Java EE中的Maven创建“应用程序客户端”

时间:2011-08-12 12:57:26

标签: netbeans maven glassfish java-ee-6 application-client

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

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

  • 装配Maven项目
  • EAR-模块
  • EJB-模块
  • WEB-Module(适用于耳内)
  • Swing客户端模块

程序集pom.xml看起来像:

    <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>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>

Swing Client pom.xml包含

<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>

目前,我在Swing Client和EJB Module之间没有依赖关系。我只是希望得到一个简单的Swing表格并用完ACC表格GlassFish(v 3.1.1)。

但这不起作用。 Swing-Client被打包到ear-file里面的lib文件夹中,我无法启动它。

您是否知道完成此任务的教程或示例?

2 个答案:

答案 0 :(得分:2)

你的耳塞需要配置耳塞(也许你把它放进你的问题时就把它留了?):

<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>

这会将您的应用程序客户端jar打包到lib文件夹之外,并将帮助您定义war模块的上下文根(没有其他方法可以找到)。 bundleFileName对于获取启动客户端的URL以使其更有意义非常重要。

我不知道将这些全部放在一起的单一教程,但有些资源是:

答案 1 :(得分:1)

现在,有对app客户端的官方maven支持

http://maven.apache.org/plugins/maven-acr-plugin/ http://maven.apache.org/plugins/maven-ear-plugin/examples/using-app-client.html

http://web.anahata-it.com/2011/09/09/java-jee-desktop-maven-enterprise-application-client/

NetBeans 7.1也将为maven app客户端添加支持。