javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jboss.naming.remote.client.InitialContextFactory from classloader ModuleClassLoader for Module "deployment.omega.war:main" from Service Module Loader
Thanks to this link, the solution is quite simple, only put the INITIAL_CONTEXT_FACTORY to org.jboss.as.naming.InitialContextFactory.
One additional note, put the JNDI name with prefix java:/ or java:jboss/.
Hi , i want to lookup jdbc datasource from java standalone app
BalasHapus//
public static void main(String[] args) throws SQLException {
DataSource cname = null;
Context context = null;
try {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
context = new InitialContext(properties);
cname = (DataSource) context.lookup("java:jboss/datasources/dream");
Connection connection = cname.getConnection();
System.out.println("connection-----masum : "+ connection.isClosed());
} catch (NamingException e) {
e.printStackTrace();
}
}
Error :
//
public static void main(String[] args) throws SQLException {
DataSource cname = null;
Context context = null;
try {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
context = new InitialContext(properties);
cname = (DataSource) context.lookup("java:jboss/datasources/dream");
Connection connection = cname.getConnection();
System.out.println("connection-----masum : "+ connection.isClosed());
} catch (NamingException e) {
e.printStackTrace();
}
}
Do you mean your standalone app need to lookup the datasource in jboss using JNDI? Or do you want to create a datasource in your standalone app?
Hapus