JNDI NameNotFoundException after Tomcat 8 upgrade - java

I upgraded from Tomcat 8.0.18 to 8.0.23 and all of the sudden I have a JNDI issue. I looked at the changelogs, Tomcat 8 Changelogs, and I see three JNDI changes, though none strike me as something that would break a previously working configuration.
JNDI related changes were made for bugs 49785, 57587, and an entry under 8.0.19 under "Other".
I am receiving this exception when I start up Tomcat with 8.0.23:
javax.naming.NameNotFoundException: Name [jdbc/MyCluster] is not bound in this Context. Unable to find [jdbc].
In my web application I have a resource link defined:
<Context>
<ResourceLink name="jdbc/MyCluster" global="jdbc/MyCluster" auth="Container" type="javax.sql.DataSource" />
</Context>
I have Tomcat configured with:
<Resource name="jdbc/MyCluster" global="jdbc/MyCluster" ......./>
I am stumped... I cannot figure out what makes my code break after my upgrade from 18 to 23 :(

Just in case anyone was curious about how upgrading from Tomcat 8.0.18 to 8.0.24 could really cause JNDI to screw up, the answer lies in ANT.
ANT Copy documentation
Myself and some other engineers had no idea that ANT Copy does nothing if the file you are trying to overwrite has a newer timestamp... who knew copy had such a complicated condition!?! I believe this is why me and multiple people never looked at the documentation, it is such an unexpected behavior.
Anyways, by upgrading to the newer version of Tomcat my context.xml that contained the resourcelink jdbc/MyCluster was failing to overwrite the newer and more recent timestamp of Tomcat's default context.xml! Once the overwrite flag is set to true, JNDI works again :)

Related

WebSphere7 : java.lang.NoSuchMethodError: javax/persistence/spi/PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;

Hello everyone long story short,i'm using hibernate in my project,i try to deploy my project on WebSphere but it's giving me the error you see in the question title
,as you see in my jars there is no trace of a lower version of jpa 2.0
jars included in my project
but i know that all servers have a version of jpa,and websphere 7 is using 1.0 that i found among it's jars,here is a picture of it,
WebSphere 7 jars
if anyone please knows how to resolve this problem or found this problem before i will be so thankful,thank you in advance, i will leave the full stack trace for more infos :
Caused by: java.lang.NoSuchMethodError: javax/persistence/spi/PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;
at org.hibernate.ejb.util.LogHelper.logPersistenceUnitInfo(LogHelper.java:39)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:516)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
... 61 more
I had a similar problem deploying my application with jpa 2.1 in Websphere 7.
If is the same problem, you have to tell Websphere to use Hibernate persistance provider instead of Default Persistance provide.
I wrote a guide with the solution that worked for me in this answer:
https://stackoverflow.com/a/38505479/6503002
EDIT: (Explain step 1 and 2 of the guide)
Step 1: To create a folder you have to access to server machine (through ssh) and create it in the file system (e.g. /usr/sharedHibernate assuming your server runs on linux). Then copy hibernate libraries in the folder you created (from your local machine to the server, with Filezilla or WinScp or Putty).
Step 2: In Websphere console on the left you have Environment section that contains Shared Libraries subsection:
Here create a new shared library, give it the name you want and in classpath textarea insert the path of the folder you created before (e.g. /usr/sharedHibernate)

javax.naming.NameNotFoundException when trying to lookup resource declared in context.xml

I am deploying a WAR to JBoss EAP 7. In my WAR's META-INF/context.xml file I have the following:
<Context unloadDelay="500000">
<Resource name="jdbc/sybase/somedb"
auth="Container"
type="javax.sql.DataSource"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sybase://localhost:12501/somedb"
username="username" password="secret"
validationQuery="select 1"
maxActive="2" maxIdle="0" maxWait="-1"/>
...
From my Java code I try to obtain the DataSource doing a:
InitialContext cxt = new InitialContext();
DataSource ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/sybase/somedb" );
The exact above code works and the name is found in the context when I deploy to Tomcat 8 but not when I deploy to JBoss EAP 7. In the latter case I get:
Caused by: javax.naming.NameNotFoundException: comp/env/jdbc/sybase/somedb -- service jboss.naming.context.java.comp.env.jdbc.sybase.somedb
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:235)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
What am I doing wrong and how can I fix the above problem?
Your META-INF/context.xml file is a Tomcat deployment descriptor (not defined by the Java EE specification) so it is not seen or parsed by JBoss EAP 7.
There are many alternatives to this including the solution to is there a standard way to define a JDBC Datasource for Java EE containers.
If you were to ask RedHat support they would likely recommend that you create the datasource using server administration tools such as the admin console or jboss-cli.sh. This decouples your application from the datasource definition so that you can specify environment specific settings (such as pool sizes and hostnames) without repackaging your WAR.file. This method also requires you to deploy the JDBC driver jar separately from your application.

Multiple Deployments of JaxRS App in TomEE causing DuplicateDeploymentIdException

I'm trying to deploy multiple instances of our service on our staging server, all on the same TomEE instance. They all have different context paths (platform_foo, platform_bar).
I'm getting an exception:
Caused by: org.apache.openejb.DuplicateDeploymentIdException: Application cannot be deployed as it contains deployment-ids which are in use: app: /var/www/apache-tomee-jaxrs-1.6.0/webapps/platform_foo
UsersService
SessionsService
My openejb-jar.xml:
<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
<pojo-deployment class-name="jaxrs-application">
<properties>
cxf.jaxrs.providers = <redacted>
</properties>
</pojo-deployment>
</openejb-jar>
I tried everything from setting an ID on the web-app element in web.xml, to setting the deployment-id in the openejb-jar.xml. Nothing seems to work.
Looks like someone has answered a similar question that I just didn't search for hard enough.
Tomcat / "Application cannot be deployed as it contains deployment-ids" error
Just deploy in another folder that webapp. I had same issue in tomEE and solved with this

java.lang.NoClassDefFoundError: HttpSessionListener

I am trying to deploy a war that i didnt write and i am getting this error in my logs:
java.lang.NoClassDefFoundError: HttpSessionListener
i know that HttpSessionListener lives in servlet-api.jar which is found in the lib dir of tomcat(my app server).
I tried including servlet-api.jar in the war's WEB-INF/lib folder, but the logs yelled at me for doing that:
INFO: validateJarFile(/home/test/apache-tomcat-6.0.18/webapps/test/WEB-INF/lib/servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
the internets claim that you dont have to include that class in your lib folder.
edit:
i removed the offending listener (which was causing the problem above) from web.xml because it didnt look very important. this revealed more errors:
java.lang.Error: Unresolved compilation problem:
The type javax.servlet.FilterChain cannot be resolved. It is indirectly referenced from required .class files
what am i missing?
Though the question is too old will tell about a possible problem nowadays. As per the Tomcat 10 download page:
Users of Tomcat 10 onwards should be aware that, ..., the primary package for all implemented APIs has changed from javax.* to jakarta.*. This will almost certainly require code changes to enable applications to migrate from Tomcat 9 and earlier to Tomcat 10 and later.
So use Tomcat 9 instead of 10.
#BalusC's explanation sounds more plausible than mine ...
Some other possible explanations / things to check:
The servlet-api.jar is not in $CATALINA_HOME/lib, or for some reason doesn't contain the class. (I know you said you "know" it's there, but you didn't specifically say you checked it.)
Something else is broken which caused the first attempted load of HttpSessionListener to fail with an uncaught exception during static initialization. (This is kind of implausible, since HttpSessionListener is an interface. But it is worth checking the logs for earlier class loading errors ... just in case.)
The missing class might be named foo.bar.HttpSessionListener rather than javax.servlet.http.HttpSessionListener. This is likely to show up in the nested stack trace.
If something in the WAR you are deploying is creating its own classloader, it is possible that is is doing this incorrectly and the HttpSessionListener class is not on the classloader's effective classpath.
EDIT
If you are now seeing unresolved compilation errors reported in the logs, you should be suspecting the WAR file and the process used to build it. Specifically, it sounds like the WAR includes classes that had Java compilation errors!
(Or maybe this is a problem compiling JSPs ... but that would show up in the logs too.)
As per its javadoc that class was introduced in Servlet API version 2.3.
If you're receiving this error, then it can have basically three causes:
Your web.xml is declared as Servlet 2.2 or lower (or incorrectly declared; Tomcat may fall back to least compatibility modus). Since you're using Java EE 5 and thus Servlet 2.5, the web.xml should then be declared like as:
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="YourWebAppID" version="2.5">
Your servletcontainer doesn't support Servlet 2.3 at all and will fall back to least compatibilty modus. But this can be excluded since Tomcat 6 should support Servlet 2.5.
You actually have another Servlet API JAR file of an ancient version in the classpath which is taking precedence in classloading. Since you already excluded WEB-INF/lib the next places to look would be JRE/lib and JRE/lib/ext folders.
Update: as per your edit, FilterChain was also introduced in Servlet API version 2.3.
1 + 1 = ... :)
java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener for this NoClassDefFoundError on HttpSessionListener , ServletListener , ServletContextListener, etc. can be caused by a custom classloader like Sysdeo DevLoader (when using it with Eclipse) in you Context definition in the Tomcat’s server.xml file.
<Loader classname="org.apache.catalina.loader.DevLoader"
reloadable="true" debug="1" />
there.....insted of this use...
<Loader classname="org.apache.catalina.loader.DevLoader"
reloadable="true"
debug="1" useSystemClassLoaderAsParent="false"/>
and add DevLoader.jar to ur class path

java.lang.illegalstatexception Application was not properly initialized

I am getting the following error when deploying an application on JBoss 4.2.1
7:05:59,673 ERROR [Application Name]StandardWrapper.Throwable
java.lang.IllegalStateException: Application was not properly initialized at
startup, could not find Factory: javax.faces.context.FacesContextFactory
I browsed the net and I found many posts which suggested to add an entry in web.xml but that entry was already there. And all the required libraries are there in web-inf.
So any solutions anybody ?
Ensure that your classpath is clean (i.e. no duplicate different versioned classes/JAR files, keep in mind that JBoss ships with builtin JSF libraries!) and that your web.xml is declared as at least Servlet 2.3.

Categories

Resources