Deploying maven project on glassfish using deploy command - java

I have a java ee application with maven, when i build the project then deploy the ear generated on target folder, i try to signup to the application so i have to call a locale EJB Session (ConfigUser) , i get the following error:
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
I tried deploying using the command call asadmin --host localhost --user admin deploy --force "C:\myproject\target\myproject-ear-1.0.ear", i also tried deploying from glassfish administration console, but the problem persist.
It works fine when i deploy from netbeans, knowing that the project is structured in the pom file like this:
<modules>
<module>myproject-ear</module>
<module>myproject-ejb</module>
<module>myproject-web</module>
</modules>
This is the jsp page :
Context c = new InitialContext();
ConfigUser configUser = (ConfigUser) c.lookup("java:global/myproject-ear/myproject-ejb-1.0/ConfigUser!myproject.service.ConfigUser");

Since there was no answer to this problem, i'm answering my own question, after research i've found the reason to the javax.naming.NamingException: Lookup failed problem, the EJB ConfigUser that i was looking for was not correctly mapped to the JNDI name, so after the deploy i checked the server log and the JNDI name was :
java:global/myproject-ear-1.0/myproject-ejb-1.0/ConfigUser!myproject.service.ConfigUser
instead of :
java:global/myproject-ear/myproject-ejb-1.0/ConfigUser!myproject.service.ConfigUser

Related

Getting runtime error while trying to connect mysql from java

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module "deployment.Sample.war:main" from Service Module Loader].
The above one is my error message.
I have included mysql-connector-java-5.1.35-bin.jar in my class path and it is shown in the libraries as well.
I am using JBoss AS 7.1.0.Final server to run it. How to resolve this error?

java.sql.SQLException: No suitable driver found jdbc:oracle:thin

I am trying to deploy a spring based web application in my local tomcat server. Below are my application details:
Spring based web application (war)
Tomcat 6 server
Java 1.6
Oracle DB
Below are by jdbc configuration:
Configuration for tomcat settings only.
javax.persistence.jdbc.drive=oracle.jdbc.OracleDriver javax.persistence.jdbc.url=jdbc:oracle:thin:#coursesdev.cvbaybp20ew7.eu-west-1.rds.amazonaws.com:1521:DEVCRS
javax.persistence.jdbc.user=test
javax.persistence.jdbc.password=test
I have also added ojdbc6.jar,ojdbc14.jar in my /lib folder
I deployed my war file without any issues. But when my application tries to connect to db it throws the error:"java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:#coursesdev.cvbaybp20ew7.eu-west"
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:#coursesdev.cvbaybp20ew7.eu-west-1.rds.amazonaws.com:1521:DEVCRS
Error Code: 0
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:517)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:294)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:272)
at org.springframework.orm.jpa.JpaTransactionManager.createEntityManagerForTransaction(JpaTransactionManager.java:445)
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:366)
... 81 more
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:#coursesdev.cvbaybp20ew7.eu-west-1.rds.amazonaws.com:1521:DEVCRS
Error Code: 0
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:319)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:109)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connectInternal(DatasourceAccessor.java:330)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.connectInternal(DatabaseAccessor.java:293)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connect(DatasourceAccessor.java:418)
at org.eclipse.persistence.sessions.server.ConnectionPool.buildConnection(ConnectionPool.java:216)
at org.eclipse.persistence.sessions.server.ConnectionPool.startUp(ConnectionPool.java:504)
at org.eclipse.persistence.sessions.server.ServerSession.connect(ServerSession.java:484)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:208)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
... 87 more
Caused by: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:#coursesdev.cvbaybp20ew7.eu-west-1.rds.amazonaws.com:1521:DEVCRS
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:98)
... 97 more
I have seen a lot of post with the similar issue but am not sure what i am missing though.
This error is depends on your building structure. Adding jar file to your lib folder is not gonna do anything.
You should add the jar file to your classpath.
If you are building your project by IDE, lets say eclipse, you should add it to .classpath file. If you are using Idea you should add it to your .iml file and etc.
If you are building your project by ant you should add jar address to your build.xml file.
I suppose you are not using maven.

Using EJB3 And Struts 2 Together

As I know, we can use ejb3 and struts 1 in Netbeans under JBoss.
But when i use ejb3 and struts 2, they got error when i deploy in JBoss 6.1.0.
I'm using Netbeans 7.2.1
I try to deploy separate components and they OK, no error.
But if I add module ejb and war to, they have problems.
Error:
15:48:38,023 ERROR [org.apache.struts2.dispatcher.Dispatcher] Dispatcher initialization failed: Unable to load configuration. - bean - vfs:/D:/javaKHANH/JavaKit_t.Khanh/jboss-6.1.0.Final/server/default/deploy/EJB3EntityStruts2Combine.ear/lib/struts2-convention-plugin-2.3.15.3.jar/struts-plugin.xml:32:155
Caused by: Unable to load bean: type:org.apache.struts2.convention.ActionConfigBuilder class:org.apache.struts2.convention.PackageBasedActionConfigBuilder - bean - vfs:/D:/javaKHANH/JavaKit_t.Khanh/jboss-6.1.0.Final/server/default/deploy/EJB3EntityStruts2Combine.ear/lib/struts2-convention-plugin-2.3.15.3.jar/struts-plugin.xml:32:155
Caused by: java.lang.ClassNotFoundException: org.apache.struts2.StrutsException from BaseClassLoader#162f61f{vfs:///D:/javaKHANH/JavaKit_t.Khanh/jboss-6.1.0.Final/server/default/deploy/EJB3EntityStruts2Combine.ear}
Caused by: java.lang.NoClassDefFoundError: org/apache/struts2/StrutsException
at java.lang.Class.getDeclaredConstructors0(Native Method) [:1.7.0_25]
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483) [:1.7.0_25]
at java.lang.Class.getDeclaredConstructors(Class.java:1891) [:1.7.0_25]
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:235) [:2.3.15.3]
15:48:38,115 ERROR [org.apache.catalina.core.StandardContext] Error filterStart
15:48:38,116 ERROR [org.apache.catalina.core.StandardContext] Context [/Struts2War] startup failed due to previous errors
15:48:38,122 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Start: name=jboss.web.deployment:war=/Struts2War state=Create mode=Manual requiredState=Installed: org.jboss.deployers.spi.DeploymentException: URL file:/D:/javaKHANH/JavaKit_t.Khanh/jboss-6.1.0.Final/server/default/tmp/vfs/automount3affa1740d934a8/Struts2War.war-667258e36d105fd7/ deployment failed
DEPLOYMENTS IN ERROR: Name -> Error
vfs:///D:/javaKHANH/JavaKit_t.Khanh/jboss-6.1.0.Final/server/default/deploy/EJB3EntityStruts2Combine.ear -> org.jboss.deployers.spi.DeploymentException: URL file:/D:/javaKHANH/JavaKit_t.Khanh/jboss-6.1.0.Final/server/default/tmp/vfs/automount3affa1740d934a8/Struts2War.war-667258e36d105fd7/ deployment failed
DEPLOYMENTS IN ERROR:
Deployment "vfs:///D:/javaKHANH/JavaKit_t.Khanh/jboss-6.1.0.Final/server/default/deploy/EJB3EntityStruts2Combine.ear" is in error due to the following reason(s): org.jboss.deployers.spi.DeploymentException: URL file:/D:/javaKHANH/JavaKit_t.Khanh/jboss-6.1.0.Final/server/default/tmp/vfs/automount3affa1740d934a8/Struts2War.war-667258e36d105fd7/ deployment failed
I'm currently using EJB 3.1 in an EAR with multiple Struts2 WARs deployed on JBoss EAP 6 (JBss AS 7). They works great.
If you are using Maven (if you are not, I suggest you to give it a try, instead of building complex ANT scripts that you will need to rewrite for your next project), be sure to create and deploy the project in the right way. If you are starting it now, use an archetype.
Since you are using Java EE and JBoss, I suggest the jboss-javaee6-webapp Maven Archetype.
I've used it too. Then use an Struts Archetype for the war, and substitute it to the one generated by the JBoss archetype, or modify it manually.

javaURLContextFactory ClassNotFound

We are trying to get InitialContext using a listener in web.xml of our application and getting below error:
SEVERE: Unable to init UserDataCachejavax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is
java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:17)
This class is present in catalina.jar.
Java version used is jdk1.6.0_02
Tomcat version is tomcat 7
Please let us know if any one has faced this error or is it related to security manager on server?

JNDI lookup fails in Glassfish

I am working on a web project using maven.When I run the server on net-beans 6.8,the build is succes,but when deploying to server I am getting lookup failed exception.Please find the server log in the following url http://pastie.org/1997218. Let me know What I have missed here. The stack trace for the error is
SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
java.lang.RuntimeException: javax.naming.NamingException: Lookup failed for 'jdbc/deliver' in SerialContext [Root exception is javax.naming.NameNotFoundException: deliver not found]
at org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init> (PersistenceUnitInfoImpl.java:111)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:130)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:96)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:121)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:644)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:296)
...
As it seems your production server is missing the database resource jdbc/deliver your application needs. You have configured it properly for your test instance in NetBeans. Have a look at the Services tab in NetBeans and make sure you have a similar database set up on your server.

Categories