使用deploy命令在glassfish上部署maven项目

时间:2018-04-27 18:17:58

标签: java maven jsp java-ee glassfish

我有一个带有maven的java ee应用程序,当我构建项目然后部署在目标文件夹上生成的ear时,我尝试注册到应用程序,所以我必须调用一个locale EJB Session(ConfigUser),我得到以下内容错误:

javax.naming.NamingException: Lookup failed for 'java:global/myproject-ear/myproject-ejb-1.0/UserFacade!myproject.service.ConfigUser' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: myproject-ear] at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455) at javax.naming.InitialContext.lookup(InitialContext.java:411) at javax.naming.InitialContext.lookup(InitialContext.java:411) at org.apache.jsp.index_jsp._jspService(index_jsp.java:79) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111) at javax.servlet.http.HttpServlet.service(HttpServlet.java:770) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411) at  

我尝试使用命令call asadmin --host localhost --user admin deploy --force "C:\myproject\target\myproject-ear-1.0.ear"进行部署,我也尝试从glassfish管理控制台进行部署,但问题仍然存在。

我从netbeans部署时工作正常,知道项目是在pom文件中构建的,如下所示:

  <modules>
    <module>myproject-ear</module>
    <module>myproject-ejb</module>
    <module>myproject-web</module>
  </modules>

这是jsp页面:

Context c = new InitialContext();
ConfigUser configUser = (ConfigUser) c.lookup("java:global/myproject-ear/myproject-ejb-1.0/ConfigUser!myproject.service.ConfigUser");

1 个答案:

答案 0 :(得分:1)

由于这个问题没有答案,我正在回答我自己的问题,经过研究我找到了javax.naming.NamingException: Lookup failed问题的原因,我正在寻找的EJB ConfigUser是未正确映射到JNDI名称,因此在部署后我检查了服务器日志并且JNDI名称为:

java:global/myproject-ear-1.0/myproject-ejb-1.0/ConfigUser!myproject.service.ConfigUser

而不是:

java:global/myproject-ear/myproject-ejb-1.0/ConfigUser!myproject.service.ConfigUser