【问题标题】:Create an "Application Client" with Maven in Java EE在 Java EE 中使用 Maven 创建“应用程序客户端”
【发布时间】:2011-08-12 12:57:25
【问题描述】:

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

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

  • 组装 Maven 项目
  • EAR 模块
  • EJB 模块
  • WEB-Module(耳内效果很好)
  • Swing 客户端模块

Assembly 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 文件夹中,我无法启动它。

你知道完成这项任务的教程或示例吗?

【问题讨论】:

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


    【解决方案1】:

    你的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 非常重要。

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

    【讨论】:

      【解决方案2】:

      现在,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 应用客户端的支持。

      【讨论】:

      • 第二个链接坏了。
      猜你喜欢
      • 2013-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多