NamingException for JNDI resource in Eclipse but runs fine in Tomcat

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

NamingException for JNDI resource in Eclipse but runs fine in Tomcat

deepak
I am facing a strange problem with the JNDI configuration when I try to run a Maven project in Eclipse but it runs fine when I create a WAR and deploy it directly on tomcat. I am using Bitronix and I have made all configurations as per: http://docs.codehaus.org/display/BTM/Tomcat. Following are the technologies I am using in the project:

- Java 1.6
- Tomcat 7
- Eclipse Juno
- BTM: 2.1.4

This is the console log I get in Eclipse:
INFO: Bitronix Transaction Manager version 2.1.4
Jun 13, 2014 5:26:59 PM bitronix.tm.Configuration buildServerIdArray
INFO: JVM unique ID: <tomcat-btm-node0>
Jun 13, 2014 5:26:59 PM bitronix.tm.resource.ResourceLoader init
INFO: reading resources configuration from P:\Documents\Softwares\Eclipse_Tomcat\apache-tomcat-7.0.54-windows-x86\apache-tomcat-7.0.54/conf/resources.properties
Jun 13, 2014 5:27:00 PM bitronix.tm.recovery.Recoverer run
INFO: recovery committed 0 dangling transaction(s) and rolled back 0 aborted transaction(s) on 1 resource(s) [jdbc/petr] (restricted to serverId 'tomcat-btm-node0')
Jun 13, 2014 5:27:00 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jun 13, 2014 5:27:00 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.54
Jun 13, 2014 5:27:03 PM org.apache.tomcat.websocket.server.WsSci onStartup
INFO: JSR 356 WebSocket (Java WebSocket 1.0) support is not available when running on Java 6. To suppress this message, run Tomcat on Java 7, remove the WebSocket JARs from $CATALINA_HOME/lib or add the WebSocket JARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available.
Jun 13, 2014 5:27:14 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(P:\Documents\Eclipse_Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\PETR\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Jun 13, 2014 5:27:15 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(P:\Documents\Eclipse_Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\PETR\WEB-INF\lib\jboss-el-api_2.2_spec-1.0.0.Final.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
Jun 13, 2014 5:27:15 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(P:\Documents\Eclipse_Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\PETR\WEB-INF\lib\jboss-servlet-api_3.0_spec-1.0.0.Final.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/P:/Documents/Softwares/Eclipse_Tomcat/apache-tomcat-7.0.54-windows-x86/apache-tomcat-7.0.54/lib/slf4j-jdk14-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/P:/Documents/Eclipse_Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/PETR/WEB-INF/lib/slf4j-jdk14-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/P:/Documents/Eclipse_Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/PETR/WEB-INF/lib/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Jun 13, 2014 5:28:42 PM org.apache.catalina.core.NamingContextListener addResource
WARNING: Failed to register in JMX: javax.naming.NamingException: no resource registered with uniqueName 'jdbc/petr', available resources: []


This is context.xml entry in Eclipse:
<Context>
      <WatchedResource>WEB-INF/web.xml</WatchedResource>

        <Transaction factory="bitronix.tm.BitronixUserTransactionObjectFactory"/>

        <Resource auth="Container" factory="bitronix.tm.resource.ResourceObjectFactory" name="jdbc/petr" type="javax.sql.DataSource" uniqueName="jdbc/petr"/>

        <Realm className="org.apache.catalina.realm.DataSourceRealm" dataSourceName="jdbc/petr" localDataSource="true" roleNameCol="role_name" userCredCol="user_pass" userNameCol="user_name" userRoleTable="gpd_users_roles" userTable="gpd_users"/>
</Context>

I have defined the Listeners in server.xml:
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
 
  <Listener className="org.apache.catalina.core.JasperListener"/>
 
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="bitronix.tm.integration.tomcat55.BTMLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>

I have also defined a context.xml file inside META-INF folder with the database name:
<?xml version='1.0' encoding='utf-8'?>
<Context>
    <Resource name="jdbc/petr" auth="Container" type="javax.sql.DataSource"
        factory="bitronix.tm.resource.ResourceObjectFactory" uniqueName="jdbc/petr" />
</Context>

This is how my btm-config.properties inside Tomcat/conf looks like:
bitronix.tm.serverId=tomcat-btm-node0
bitronix.tm.journal.disk.logPart1Filename=${btm.root}/work/btm1.tlog
bitronix.tm.journal.disk.logPart2Filename=${btm.root}/work/btm2.tlog
bitronix.tm.resource.configuration=${btm.root}/conf/resources.properties

This is how my resources.properties inside Tomcat/conf looks like:
resource.ds1.className=bitronix.tm.resource.jdbc.lrc.LrcXADataSource
resource.ds1.uniqueName=jdbc/petr
resource.ds1.minPoolSize=0
resource.ds1.maxPoolSize=10
resource.ds1.driverProperties.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
resource.ds1.driverProperties.url=jdbc:sqlserver://98.97.95.94:1433;databaseName=appDB
resource.ds1.driverProperties.user=appAdmin
resource.ds1.driverProperties.password=ain564ytr
resource.ds1.allowLocalTransactions=true

The following JARs have been copied to Tomcat/lib:
btm-2.1.4.jar
btm-tomcat55-lifecycle-2.1.4.jar
slf4j-api-1.7.6.jar
slf4j-jdk14-1.6.4.jar
sqljdbc4.jar
jta-1.1.jar

%CATALINA_HOME% is set to:
P:\Documents\Softwares\Eclipse_Tomcat\apache-tomcat-7.0.54-windows-x86\apache-tomcat-7.0.54

Following is how my Tomcat/bin/setenv.bat file looks like:
set CATALINA_OPTS=-Dbtm.root=%CATALINA_HOME% -Dbitronix.tm.configuration=%CATALINA_HOME%\conf\btm-config.properties

When I start the application in Eclipse I pass the following command line args:
-Dcatalina.base="P:\Documents\Eclipse_Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0" -Dcatalina.home="P:\Documents\Softwares\Eclipse_Tomcat\apache-tomcat-7.0.54-windows-x86\apache-tomcat-7.0.54" -Dwtp.deploy="P:\Documents\Eclipse_Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps" -Djava.endorsed.dirs="P:\Documents\Softwares\Eclipse_Tomcat\apache-tomcat-7.0.54-windows-x86\apache-tomcat-7.0.54\endorsed" -Dbtm.root="P:\Documents\Softwares\Eclipse_Tomcat\apache-tomcat-7.0.54-windows-x86\apache-tomcat-7.0.54" -Dbitronix.tm.configuration="P:\Documents\Softwares\Eclipse_Tomcat\apache-tomcat-7.0.54-windows-x86\apache-tomcat-7.0.54\conf\btm-config.properties"

Am I still missing something ? Please please help me as I am not able to resolve this from last 1 week :(.



 
Reply | Threaded
Open this post in threaded view
|

Re: NamingException for JNDI resource in Eclipse but runs fine in Tomcat

deepak
Problem resolved. Switched from Eclipse Juno to Eclipse Kepler.

Thank you all them who tried to read through this as help me. Good day !!