将EJB模块打包为EAR或JAR?

时间:2017-11-06 23:57:37

标签: jar glassfish ejb war ear

这个hello world EJB是否应该作为EARJAR进行部署?

thufir@dur:~/NetBeansProjects/EJBModule1$ 
thufir@dur:~/NetBeansProjects/EJBModule1$ cat src/java/net/bounceme/dur/ejb/NewSessionBean.java 
package net.bounceme.dur.ejb;

import java.util.logging.Logger;
import javax.ejb.Stateless;

@Stateless(name = "FooBean", mappedName = "ejb/FooBean")
public class NewSessionBean implements NewSessionBeanRemote {

    private final static Logger log = Logger.getLogger(NewSessionBean.class.getName());

    @Override
    public void sayHello() {
        log.info("hi");
    }

}
thufir@dur:~/NetBeansProjects/EJBModule1$ 

部署:

thufir@dur:~/NetBeansProjects/EJBModule1$ 
thufir@dur:~/NetBeansProjects/EJBModule1$ asadmin list-applications
Nothing to list.
No applications are deployed to this target server.
Command list-applications executed successfully.
thufir@dur:~/NetBeansProjects/EJBModule1$ 
thufir@dur:~/NetBeansProjects/EJBModule1$ ant -p
Buildfile: /home/thufir/NetBeansProjects/EJBModule1/build.xml
Builds, tests, and runs the project EJBModule1.
Main targets:

 -profile-pre72         Profile a J2EE project in the IDE.
 clean                  Clean build products.
 compile                Compile project.
 debug                  Debug project in IDE.
 default                Build whole project.
 dist                   Build distribution (JAR).
 dist-directory-deploy  Build distribution (JAR) - if directory deployment is not supported.
 dist-ear               Build distribution (JAR) to be packaged into an EAR.
 javadoc                Build Javadoc.
 profile                Profile a J2EE project in the IDE.
 run                    Deploy to server.
 test                   Run unit tests.
 test-single            Run single unit test.
 test-single-method     Run single unit test.
Default target: default
thufir@dur:~/NetBeansProjects/EJBModule1$ 
thufir@dur:~/NetBeansProjects/EJBModule1$ ant run
Buildfile: /home/thufir/NetBeansProjects/EJBModule1/build.xml

-pre-init:

-init-private:

-init-userdir:

-init-user:

-init-project:

-init-macrodef-property:

-do-init:

-post-init:

-init-check:

-init-ap-cmdline-properties:

-init-macrodef-javac-with-processors:

-init-macrodef-javac-without-processors:

-init-macrodef-javac:

-init-macrodef-test-impl:

-init-macrodef-junit-init:

-init-macrodef-junit-single:

-init-test-properties:

-init-macrodef-junit-batch:

-init-macrodef-junit:

-init-macrodef-junit-impl:

-init-macrodef-testng:

-init-macrodef-testng-impl:

-init-macrodef-test:

-init-macrodef-junit-debug:

-init-macrodef-junit-debug-batch:

-init-macrodef-junit-debug-impl:

-init-macrodef-test-debug-junit:

-init-macrodef-testng-debug:

-init-macrodef-testng-debug-impl:

-init-macrodef-test-debug-testng:

-init-macrodef-test-debug:

-init-macrodef-java:

-init-debug-args:

-init-macrodef-nbjpda:

-init-macrodef-debug:

-init-taskdefs:

-init-ap-cmdline-supported:

-init-ap-cmdline:

init:

-init-cos:

-init-deploy:

-deps-module-jar:

-deps-ear-jar:

deps-jar:

-pre-pre-compile:

-pre-compile:

-copy-meta-inf:

-do-compile:

-post-compile:

compile:

-library-inclusion-in-archive-weblogic:

-library-inclusion-in-archive-by-user:

library-inclusion-in-archive:

-pre-dist:

-do-tmp-dist-without-manifest:

-do-tmp-dist-with-manifest:

-do-dist-directory-deploy:

-post-dist:

dist-directory-deploy:

pre-run-deploy:

-pre-nbmodule-run-deploy:

-run-deploy-nb:

-init-deploy-ant:

-init-cl-deployment-env:

-parse-glassfish-web:

-parse-sun-web:

-no-parse-sun-web:

-add-resources:

-deploy-ant:

-deploy-without-pw:
     [echo] Deploying dist/EJBModule1.jar
      [get] Getting: http://localhost:4848/__asadmin/deploy?path=/home/thufir/NetBeansProjects/EJBModule1/dist/EJBModule1.jar&force=true&name=EJBModule1
      [get] To: /tmp/gfv3945180939
   [delete] Deleting: /tmp/gfv3945180939

-deploy-with-pw:

-run-deploy-am:

-post-nbmodule-run-deploy:

post-run-deploy:

-do-update-breakpoints:

run-deploy:

run:

BUILD SUCCESSFUL
Total time: 1 second
thufir@dur:~/NetBeansProjects/EJBModule1$ 
thufir@dur:~/NetBeansProjects/EJBModule1$ asadmin list-applications
EJBModule1  <ejb>  
Command list-applications executed successfully.
thufir@dur:~/NetBeansProjects/EJBModule1$ 
thufir@dur:~/NetBeansProjects/EJBModule1$ cat src/java/net/bounceme/dur/ejb/NewSessionBean.java 
package net.bounceme.dur.ejb;

import java.util.logging.Logger;
import javax.ejb.Stateless;

@Stateless(name = "FooBean", mappedName = "ejb/FooBean")
public class NewSessionBean implements NewSessionBeanRemote {

    private final static Logger log = Logger.getLogger(NewSessionBean.class.getName());

    @Override
    public void sayHello() {
        log.info("hi");
    }

}
thufir@dur:~/NetBeansProjects/EJBModule1$ 

它只是一个&#34;模块&#34 ;;根据我的理解,这意味着没有网络组件(WAR文件)。但它可以仍然是EAR ......或者不是吗?

(构建文件/ etc都是Netbeans的默认值。)

1 个答案:

答案 0 :(得分:1)

Ear用于捆绑Jar模块和war模块togeather。 因此,当您的企业应用程序具有:

时,Ear模块是有意义的
  • 多个Jar模块
  • 多个战争模块
  • 多个Jar和战争模块。

此外,在上面的设置中还有类路径含义。

如果我的应用程序只有一个jar模块或war模块,我会直接部署它。