1

我正在尝试使用应用程序客户端创建一个基于 Maven 的企业应用程序,该应用程序客户端在 GlassFish 的应用程序客户端容器中运行。它应该适合作为 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>

耳朵 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 客户端和 EJB 模块之间没有依赖关系。我只想获得一个简单的 Swing 表单,并从 ACC 表单 GlassFish (v 3.1.1) 中运行出来。

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

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

4

2 回答 2

2

您的 ear pom 需要像这样配置 ear 插件(也许您在将其放入问题时将其遗漏了?):

<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 文件夹之外,并将帮助您定义战争模块的上下文根(我找不到其他方法)。bundleFileName 对于让 URL 启动客户端更有意义很重要。

我不知道有一个教程可以将所有这些放在一起,但是一些资源是:

于 2011-08-15T20:23:26.080 回答
1

现在,对应用程序客户端有官方的 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 应用程序客户端的支持。

于 2011-09-10T10:45:53.900 回答