- This topic has 10 replies, 3 voices, and was last updated 21 years ago by
Scott Anderson.
-
AuthorPosts
-
tuMemberI’m trying to use JNDI datasource with JBoss 3.2.4 in MyEclipse. I got this javax.naming.NameNotFoundException: MySqlDS not bound
Then I tried looking up “MySqlDS”, “java:MySqlDS”,”java:/MySqlDS” and they all fail in the same problem.
I’ve tried build the same project in Lomboz and without any problem at all. I really like to know why this isn’t work in MyEclipse. Can anyone help me?This is what I have…
MyEclipse 3.7.2 with eclipse 3.0M8
JBoss 3.2.4
J2sdk1.4.2_03
MySql 4.0This is my client code…
public class SessionStatelessClient {
public static void main(String[] args) {
// Begin test MySqlDS connection
Connection con = null ;
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
“org.jnp.interfaces.NamingContextFactory”);
env.put(Context.PROVIDER_URL, “localhost:1099”);
env.put(“java.naming.factory.url.pkgs”,
“org.jboss.naming:org.jnp.interfaces”);
Context jndiCntx = new InitialContext(env);
System.out.println(“Looking up java:/MySqlDS”);
//Error at the following line
DataSource ds = (javax.sql.DataSource)jndiCntx.lookup (“java:/MySqlDS”);
System.out.println(“Found datasource. Connecting to java:/MySqlDS”);
con = ds.getConnection();
if (null != con) {
System.out.println(“Connection successful!”);
}
} catch (Exception ex) {
System.out.println(“getConnection failed.”);
ex.printStackTrace();
} finally {
//close the Connection
try {
if (con!=null) con.close() ;
} catch(SQLException sqle) {
con = null ;
}
}
// End test MySqlDS connection
}
}Here is my ejb-jar.xml
<!– Session Beans –>
<session >
<description><![CDATA[GDPAccessStateless EJB]]></description>
<display-name>GDPAccessStateless</display-name>
<ejb-name>GDPAccessStateless</ejb-name>
<home>com.gdp.interfaces.GDPAccessStatelessHome</home>
<remote>com.gdp.interfaces.GDPAccessStateless</remote>
<ejb-class>com.gdp.ejb.GDPAccessStatelessSession</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type><resource-ref >
<res-ref-name>jdbc/MySqlDS</res-ref-name>
<res-type>javax.sql.Datasource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</session>Here is my jboss.xml
<enterprise-beans>
<session>
<ejb-name>GDPAccessStateless</ejb-name>
<jndi-name>GDPAccessStateless</jndi-name>
<resource-ref>
<res-ref-name>jdbc/MySqlDS</res-ref-name>
<jndi-name>java:/MySqlDS</jndi-name>
</resource-ref>
</session>
</enterprise-beans>
<resource-managers>
<resource-manager>
<res-name>jdbc/MySqlDS</res-name>
<res-jndi-name>java:/MySqlDS</res-jndi-name>
</resource-manager>
</resource-managers>
Riyad KallaMemberMyEclipse only run’s your application server, it doesn’t do anything sneaky. Also you seem to be accessing your JNDI context incorrectly. Take for example a context named “MySqlDS”, you would access this context (from code) using the following context string:
java:comp/env/MySqlDS
Please give that a try and see if it works.
tuMemberNo, it said javax.naming.NameNotFoundException: comp not bound…
No matter what I put in here, it comes back JNDI not bound. Any ideas?
Scott AndersonParticipantAnother reason why the binding might not be happening is that you didn’t put the appropriate MySQL cleint jar files on your JBoss classpath. Did you append the appropriate Jars at Window > Preferences > MyEclipse > Application Servers > JBoss > Paths? To diagnose it, I’d set up the project and run it completely outside of Eclipse, launching JBoss from the commandline. That will remove one variable and let us know if it’s a JBoss configuration problem or a MyEclipse configuration problem. Once you have it running externally, it’s simply a matter of configuration to get MyEclipse to launch the server exactly the same way.
tuMemberIs mysql-connector-java-3.0.11-stable-bin.jar the appropriate client jar? I put this under my C:\myj2ee\jboss-3.2.4RC1\server\default\lib. And I’m sure it connects with correct JNDI name in JBoss by the following log…
23:52:37,801 INFO [MySqlDS] Bound connection factory for resource adapter for ConnectionManager ‘jboss.jca:service=LocalTxCM,name=MySqlDS to JNDI name ‘java:/MySqlDS’
23:52:37,801 INFO [TxConnectionManager] Started jboss.jca:service=LocalTxCM,name=MySqlDSI just put this jar under JBoss classpath in MyEclipse, still got the same error. What other jar files do I need to configure in JBoss classpath? Also, under the project Build Path > Libraries, I have
-JRE System Library [j2sdk1.4.2_03]
-J@EE 1.3 Library Container
-jbossall-client.jar
Do I need to put more jars in library?
Scott AndersonParticipantFrom that is sounds like the startup of JBoss configuration is fine. Isn’t there a way to view the JNDI tree using the JBoss administration console? If so, I look and see if you MySQL datasource is there or not. Did you configure your JBoss mysql service config file to add the JNDI service you’re trying to look up? A tutorial on how to do that is here:
http://home.zonnet.nl/rhjlie/developer/jboss.htm#install_jboss_3.0.4_mysql_3.23
tuMemberYes, I’ve already done that. From http://localhost:8080/jmx-console/index.jsp.
Under jboss.jca
jboss.jca
name=DefaultDS,service=LocalTxCM
name=DefaultDS,service=ManagedConnectionFactory
name=DefaultDS,service=ManagedConnectionPool
name=JBoss JDBC XATransaction ResourceAdapter,service=RARDeployment
name=JBoss LocalTransaction JDBC Wrapper,service=RARDeployment
name=JMS Adapter,service=RARDeployment
name=JmsXA,service=ManagedConnectionFactory
name=JmsXA,service=ManagedConnectionPool
name=JmsXA,service=TxCM
name=MySqlDS,service=LocalTxCM
name=MySqlDS,service=ManagedConnectionFactory
name=MySqlDS,service=ManagedConnectionPool
name=SybaseDB,service=LocalTxCM
name=SybaseDB,service=ManagedConnectionFactory
name=SybaseDB,service=ManagedConnectionPool
service=CachedConnectionManager
service=ConnectionFactoryDeployer
service=RARDeployerUnder jboss
service=JNDIViewEjb Module: MyGDP.jar
java:comp namespace of the GDPAccessStateless bean:
+ env (class: org.jnp.interfaces.NamingContext)java: Namespace
+ XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
+ DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
+ SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
+ DefaultJMSProvider (class: org.jboss.jms.jndi.JBossMQProvider)
+ MySqlDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
+ comp (class: javax.naming.Context)
+ JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
+ ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
+ jaas (class: javax.naming.Context)
| + JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
| + jbossmq (class: org.jboss.security.plugins.SecurityDomainContext)
| + HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
+ timedCacheFactory (class: javax.naming.Context)
Failed to lookup: timedCacheFactory, errmsg=null
+ SybaseDB (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
+ TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
+ Mail (class: javax.mail.Session)
+ StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
+ TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
+ TransactionManager (class: org.jboss.tm.TxManager)
tuMemberUnder my project, I have this structure. (I’d like to make sure these are generated correctly from MyEclipse.)
-src
-com.gdp.client
-SessionStatelessClient.java
-com.gdp.dao
-GDPAccessDAOImpl.java
-com.gdp.ejb
-GDPAccessStateless.java
-GDPAccessStatelessSession.java
-com.gdp.interfaces
-GDPAccessDAO.java
-GDPAccessStateless.java
-GDPAccessStatelessHome.java
-GDPAccessStatelessUtil.java
-META-INF
-ejb-jar.xml
-jaws.xml
-jboss.xmlI’ve tried jboss 3.2.4 and jboss 3.2.3, all have the same error. I don’t understand why it works with Lomboz tool but not MyEclipse. It must be some setups missing…
Scott AndersonParticipantThe structure looks ok. However, since it looks like you’re using XDoclet to do the generation of your EJB of the interfaces, this thread may help in case there’s a problem with the names generated by XDoclet:
https://www.genuitec.com/forums/topic/jndi-name-problems-closed/&highlight=xdoclet+ejb+jndi
tuMemberI think the problem I had was JBoss binds the DataSource in the “java:” namespace which only available inside the VM. And the reason I can’t access from the client program is because it is running in another VM. so I create a DataSource…
com.mysql.jdbc.jdbc2.optional.MysqlDataSource ds = new com.mysql.jdbc.jdbc2.optional.MysqlDataSource();
ds.setServerName(“localhost”) ;
ds.setPort(3306) ;
ds.setDatabaseName(“jbossdb”) ;
ds.setUser(“mysql”) ;
ds.setPassword(“mysql”) ;
// Then bind the name and the DataSource object together
ctx.bind(“mysql”, ds) ;
// Get a connection
con = ds.getConnection();I didn’t add @ejb.util generate = “physical”…I don’t have problem with the name of EJB, DAO can see MySqlDS.
this.jdbcFactory = (DataSource) c.lookup(“java:/MySqlDS”);Thank you for your help.
I do have another question about using ‘Run XDoclet’ to generate jBoss.xml and jaws.xml. I always get a x in front of
<?xml version=”1.0″ encoding=”UTF-8″?>, until I manually change DOCTYPE DTD version 2.4 to version 3.0jboss.xml Change
<!DOCTYPE jboss PUBLIC “-//JBoss//DTD JBOSS 2.4//EN” “http://www.jboss.org/j2ee/dtd/jboss_2_4.dtd”>
To
<!DOCTYPE jboss PUBLIC “-//JBoss//DTD JBOSS 3.0//EN” “http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd”>jaws.xml Change
<!DOCTYPE jaws PUBLIC “-//JBoss//DTD JBOSS 2.4//EN” “http://www.jboss.org/j2ee/dtd/jboss_2_4.dtd”>
To
<!DOCTYPE jaws PUBLIC “-//JBoss//DTD JAWS 3.0//EN” “http://www.jboss.org/j2ee/dtd/jaws_3_0.dtd”>How do I change the version? from XDoclet? or from Jboss?
Again, I’m using jboss 3.2.4
Scott AndersonParticipantYou can change the version in the properties of the JBoss XDoclet task. Open up your XDoclet properties, select the JBoss task and set version to 3.0 or 3.1. The default is 2.4. Full XDoclet documentation is available in the MyEclipse User Guide in the help system and here:
http://myeclipseide.com/enterpriseworkbench/help/topic/com.genuitec.myeclipse.doc/html/reference/xdoclet-doc/index.html -
AuthorPosts