-
1. Re: Need to configure JNDI
waynebaylor Oct 27, 2007 11:47 PM (in response to new_to_jboss_4)have you tried setting up HA-JNDI?
-
2. Re: Need to configure JNDI
new_to_jboss_4 Oct 29, 2007 2:08 PM (in response to new_to_jboss_4)Thats exactly I need to know how to?
-
3. Re: Need to configure JNDI
waynebaylor Oct 30, 2007 8:42 AM (in response to new_to_jboss_4)have a look at this: http://docs.jboss.com/jbossas/guides/clusteringguide/r2/en/html_single/
in the process of setting up clustering you will also enable HA-JNDI. when starting a jboss instance you can use the -g flag to specify a cluster group name. JNDI lookups are slightly different too, HA-JNDI uses port 1100 by default. If you are passing properties to a lookup context you will also have the option of using the cluster group name instead of an IP/port.
hope that helps -
4. Re: Need to configure JNDI
new_to_jboss_4 Oct 30, 2007 12:40 PM (in response to new_to_jboss_4)I have been going through that documentation. I tried configuring the jndi.properties but the server crashed. The clustering is already in role with apache managing it for now. So I need to remove the clustering from apache and specify jboss to do it for me using the -g flag? Also wud i need to change this 1100 port(in the cluster-service.xml) to 8080(jboss admin) or 8009(apache managed instance) ?
Is it necessary to pass properties to lookup context and if yes then where?
Thanks a lot for all the help!!! -
5. Re: Need to configure JNDI
new_to_jboss_4 Oct 30, 2007 12:40 PM (in response to new_to_jboss_4)I have been going through that documentation. I tried configuring the jndi.properties but the server crashed. The clustering is already in role with apache managing it for now. So I need to remove the clustering from apache and specify jboss to do it for me using the -g flag? Also wud i need to change this 1100 port(in the cluster-service.xml) to 8080(jboss admin) or 8009(apache managed instance) ?
Is it necessary to pass properties to lookup context and if yes then where?
Thanks a lot for all the help!!! -
6. Re: Need to configure JNDI
waynebaylor Oct 31, 2007 9:45 AM (in response to new_to_jboss_4)i just copied cluster-service.xml to my deploy dir, you can get in the server/all/deploy dir. if you look about halfway down it you'll see the HA-JNDI specific stuff.
once that was deployed, i restarted jboss with something likeC:\> run.bat -b 0.0.0.0 -g myGroupName
the -b tells jboss which ip to bind to (0.0.0.0 means 'i don't know just figure it out'). the -g tells jboss which cluster group to join, the default group is DefaultPartition ( you can replace myGroupName with whatever you want).
you can use an application client to test this. just use the following to get a Context and then perfom a lookup.Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces"); p.put(Context.PROVIDER_URL, "localhost:1100"); // HA-JNDI port. return new InitialContext(p);
you can also pass a list of URLsp.put(Context.PROVIDER_URL, "server1:1100,server2:1100,server3:1100,server4:1100");
instead of specifying the servers in the group, you can just specify the groupp.put("jnp.partitionName", "myGroupName");
hope this helps -
7. Re: Need to configure JNDI
new_to_jboss_4 Nov 28, 2007 5:26 PM (in response to new_to_jboss_4)here's what i have a sample application to test the jboss jndi..
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.naming.Context;
import java.util.Hashtable;
import javax.sql.DataSource;
class test {
public static void main(String[] args) throws SQLException {
Connection con = null;
PreparedStatement stmt = null;
String query = "SELECT sysdate FROM DUAL";
try {
//con = Database.connectWeblogic();
con = connectJboss();
stmt = con.prepareStatement(query);
stmt.execute();
ResultSet rs = stmt.getResultSet();
while(rs.next()){
System.out.println(rs.getString(1));
}
}catch(SQLException e){
e.printStackTrace();
//System.err.println(e.getMessage());
throw new SQLException("Fault: Couldn't Fetch Fields");
}finally {
//Database.disconnect(con);
}
}
public static Connection connectJboss() throws SQLException {
Context ctx = null;
//Hashtable<String, String> ht = new Hashtable<String, String>();
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
ht.put(Context.PROVIDER_URL, "fb-linux1.corp.adobe.com:8080");
Connection con = null;
try {
ctx = new InitialContext(ht);
DataSource ds = (DataSource) ctx.lookup("WTSN");
con = ds.getConnection();
} catch (Exception e) {
e.printStackTrace();
// System.out.println (e.getMessage());
throw new SQLException("Database connection failed");
}
return con;
}
}
i get this error...
java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory not found in [file:/usr/share/java/libgcj-3.4.3.jar, file:./, core:/]
at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.5.0.0)
at _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
at javax.naming.spi.NamingManager.getInitialContext(java.util.Hashtable) (/usr/lib/libgcj.so.5.0.0)
at javax.naming.InitialContext.getDefaultInitCtx() (/usr/lib/libgcj.so.5.0.0)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at javax.naming.InitialContext.lookup(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at test.connectJboss() (Unknown Source)
at test.main(java.lang.String[]) (Unknown Source)
java.sql.SQLException: Database connection failed
at test.connectJboss() (Unknown Source)
at test.main(java.lang.String[]) (Unknown Source)
Exception in thread "main" java.sql.SQLException: Fault: Couldn't Fetch Fields
at test.main(java.lang.String[]) (Unknown Source)
-----------------
Pls advice how to rectify this!!! -
8. Re: Need to configure JNDI
jaikiran Nov 29, 2007 2:10 AM (in response to new_to_jboss_4)Do you have JBoss related jar files in the client application's classpath? I usually place the jbossall-client.jar (which can be found in the %JBOSS_HOME%/client folder) in the client's classpath. This has all the required JBoss classes.
-
9. Re: Need to configure JNDI
new_to_jboss_4 Nov 29, 2007 10:56 PM (in response to new_to_jboss_4)hi,
i tried putting that file in the classpath too,
i use java -classpath.. may be i am not using the correct way. I still get that error! -
10. Re: Need to configure JNDI
jaikiran Nov 30, 2007 5:06 AM (in response to new_to_jboss_4)Post the command that you use to run your java client.