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

发布于 2024-11-29 06:56:42 字数 4953 浏览 1 评论 0 原文

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

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

  • Assembly Maven Project
  • EAR-Module
  • EJB-Module
  • WEB-Module (与耳朵内部配合良好)
  • Swing Client Module

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 客户端 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 文件内的lib 文件夹中,但我无法启动它。

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何处潇湘 2024-12-06 06:56:42

您的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 文件夹之外,并帮助您定义 war 模块的上下文根(我找不到其他方法)。 BundleFileName 对于获取启动客户端的 URL 来说很重要,这样更有意义。

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

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:

绻影浮沉 2024-12-06 06:56:42

现在,应用程序客户端有了官方 Maven 支持

http://maven.apache.org/插件/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 应用程序的支持客户也是如此。

Now, there is official maven support for app clients

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 will add support for maven app clients too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文