I have created a EJB package with Glassfish V 4.0 and postgre sql as server and DB respectively. Glassfish and postgre are installed remotely.
I have created a connection pool and JNDI
Let me know if any more details is required
When i run my class file it gives me following error
Dec 17, 2013 10:47:16 AM com.sun.enterprise.connectors.ActiveRAFactory
createActiveResourceAdapter
SEVERE: RAR6001 : Class Not found : com.sun.gjc.spi.ResourceAdapterImpl
Dec 17, 2013 10:47:16 AM com.sun.enterprise.connectors.ActiveRAFactory
createActiveResourceAdapter
SEVERE:
com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Error in creating
active RAR
at com.sun.enterprise.connectors.ActiveRAFactory.createActiveResourceAdapter(ActiveRAFactory.java:111)
at com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl.createActiveResourceAdapter(ResourceAdapterAdminServiceImpl.java:210)
at com.sun.enterprise.connectors.ConnectorRuntime.createActiveResourceAdapter(ConnectorRuntime.java:427)
at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance(ConnectorObjectFactory.java:107)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:527)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:487)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at sg.edu.astar.taxi360.dao.impl.DBConnection.<clinit>(DBConnection.java:24)
at sg.edu.astar.taxi360.dao.dummy.main(dummy.java:22)
Caused by: java.lang.ClassNotFoundException: com.sun.gjc.spi.ResourceAdapterImpl
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.sun.enterprise.connectors.ActiveRAFactory.createActiveResourceAdapter(ActiveRAFactory.java:102)
... 10 more
My class file which has main method
public static void main(String args[])
{
dummy p = new dummy();
PreparedStatement stmt = null;
String sql="";
try(Connection connection = DBConnection.getConnection();)
{
sql = "INSERT INTO databasename.request (requestId)" +
"VALUES (?)";
stmt = connection.prepareStatement(sql);
stmt.setString(1, "1324");
stmt.executeQuery();
}
catch(Exception ex){
}
}
DBConnection class file contains following details
public class DBConnection {
private static DataSource ds;
static {
try {
InitialContext ctx = new InitialContext();
ds = (DataSource) ctx.lookup("jdbc/databasename");
} catch (NamingException ex) {
Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE,null,ex);
}
}
public static Connection getConnection() {
Connection connection = null;
try {
connection = ds.getConnection();
} catch (SQLException ex) {
Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
}
return connection;
}
}
Thanks in advance
I resolved this by adding
glassfish-embedded-all
to mypom.xml
: