Spring app on Tomcat doesnt find class in weblogic.jar - java

I'm trying to deploy an app on tomcat 7 that uses spring 3.1.1 and weblogic 10.3, but I keep getting a NoClassDef exception:
java.lang.NoClassDefFoundError: Could not initialize class weblogic.jndi.Environment at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506) ~[spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
I've double checked and and the weblogic jar is present on WEB-INF/lib and it does contain said class:
jar tf WEB-INF/lib/weblogic.jar | grep /Environment.class
weblogic/cluster/messaging/internal/Environment.class
weblogic/jndi/Environment.class
org/mozilla/javascript/tools/shell/Environment.class
this happens when a spring bean factory tries to build this bean on my root-context.xml
<beans:bean
id="jmsConnectionFactory"
class="org.springframework.jndi.JndiObjectFactoryBean"
p:jndiTemplate-ref="jndiTemplate"
p:jndiName="weblogic.jms.ConnectionFactory" />
I thought it might be some classpath issue, but I have been playing around with the MANIFEST.MF of the webapp and this problematic jars(spring & weblogic) for a while now, without any luck.
Any ideas on what can be causing this?

I believe using weblogic.jar directly in the classpath does not work. You need to create wlfullclient.jar and put it in WEB-INF/lib.
Follow the instructions given here: http://middlewaremagic.com/weblogic/?p=558

Related

Failed to import bean definitions from URL location [classpath:applicationContext-core.xml]

I'm working on a java project with spring on eclipse using Maven, and running on a Tomcat server v6.0. Everything was working fine since yesterday morning.
Here his my problem : I'm building my project, I got a build success. Then I start my Tomcat server and got this error :
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:applicationContext- core.xml]
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext-core.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext-core.xml] cannot be opened because it does not exist
I found out similar problem on some website but none of them give me a solution that worked for me.
It seems that eclipse isn't able to find applicationContext-core.xml when I'm doing this :
<import resource="classpath:applicationContext-core.xml" />
However, I do have the needed jar file nad-core-0.0.1-SNAPSHOT.jar in WEB-INF/lib containing applicationContext-core.xml.
I even tried to add it manually to the classpath but I was still having the same problem.
I keep on looking for a solution, when suddendly it work again once after restarting Eclipse and building while Eclipse was still updating indexes and my project was having this strange status Hg status pending instead of default. Surprised by this result I decide to build again my project after restarting Eclipse and I got the error again and I enable to make it work again. It's quite annoying...
This looks to be a really random problem.
Thanks a lot for your help :)
As you've not specified you web application structure. I assume you've a simple web application at hand with the following structures
webapp
WEB-INF/classes/applicationContext.xml
WEB-INF/lib/nad-core-0.0.1-SNAPSHOT.jar/applicationContext-core.xml
Application context.xml refers to the applicationContext-core.xml file using the import tag. I did encounter a similar situation in my web application, here're the check lists that you should go through and may be one of them can apply to your situation.
Check the generated snapshot jar file for the applicationContext-core.xml file and make sure it is in the root directory of the jar. As silly as it sounds, this was the root cause of the issue I faced in my deployment.
Make sure your Maven Pom.xml file is configured to include this XML file from the resources folder. You can use the resource tags in the build phase of Maven to package them within the jar file itself.
You can try removing the import tag from application context.xml file and instead load both of them from Spring's webapplication context itself.
Add a context loader listener class from spring org.springframework.web.context.ContextLoaderListener
Add context-param contextConfigLocation with value classpath:applicationContext-core.xml,classpath:applicationContext.xml. Spring has the ability to dynamically sort out the dependencies before initiating the bean factory.
Hope this check list helps.
I get pretty much the same config, six years later, I got the same error.
I also restart Eclipse, and it solved the issue.

NoClassDefFoundError: Could not initialize class org.apache.axis2.description.AxisService

While running the application I was getting the following errors.
java.lang.NoClassDefFoundError: Could not initialize class org.apache.axis2.description.AxisService
AxisService class is in axis2-kernel-1.6.2.jar file. Some of the classes from this jar are working fine without any issues, but some classes are throwing NoClassDefFoundError from this jar file at runtime. AxisService class is present in axis2-kernel-1.6.2.jar, even it throws error.
This is working fine in local machine. But error getting in Oracle r12 server.I have already set the class path for the jar file.
I am Using Java version is 1.6 and Apache axis2.1.6.2.
Had the same issue. I had included only jars that I needed to compile the application.
When I included everything from \axis2-1.6.2\lib\ folder, this exception were gone.
I had a similar problem using Tomcat and Axis2 and after a week finding out the error I realized there was a axis configuration problem. especifically my aplication can't instantiate the class which accedded to persistence layer. I include this parameter line:
<parameter name="ServiceTCCL">composite</parameter>
in services.xml file which is used by axis2 to work.
For more information see the comments in http://wso2.com/node/1131

NoClassDefFoundError in Websphere -- JARs are present

I have a simple Spring MVC application that looks up some user details from an LDAP server and prints out a simple HTML page using a JSP. The application works fine on Tomcat 6. It uses Spring LDAP 1.3.1 and LDAPTemplate to do the LDAP lookups.
However, when I deploy this application WAR to Websphere 7, the app doesn't run -- Websphere returns a 500 Internal server error. Looking at Websphere's log file, I see
[14/12/10 14:50:09:169 GMT] 00000022 DispatcherSer E org.springframework.web.servlet.FrameworkServlet initServletBean Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.ldap.core.support.LdapContextSource] for bean with name 'contextSource' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org.springframework.beans.factory.InitializingBean
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1253)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1319)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:885)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
My web-inf\lib directory has all the JAR files, including org.springframework.beans-3.0.5.RELEASE.jar, which contains InitializingBean. I'm therefore not sure why Websphere is reporting the class as missing.
Contents of my web-inf\lib:
aopalliance.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
commons-pool-1.5.4.jar
jstl-api-1.2.jar
jstl-impl-1.2.jar
ldapbp-1.0.jar
org.springframework.aop-3.0.5.RELEASE.jar
org.springframework.asm-3.0.5.RELEASE.jar
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
org.springframework.jdbc-3.0.5.RELEASE.jar
org.springframework.oxm-3.0.5.RELEASE.jar
org.springframework.transaction-3.0.5.RELEASE.jar
org.springframework.web-3.0.5.RELEASE.jar
org.springframework.web.servlet-3.0.5.RELEASE.jar
spring-ldap-1.3.1.RELEASE-all.jar
And here's the definition of the contextSource bean which Websphere is having trouble loading (the username/password is valid and works with Tomcat):
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldaps://moo.example.com:1300/" />
<property name="userDn" value="CN=foo,OU=baz,DC=bar,DC=blat,DC=org" />
<property name="password" value="*******" />
</bean>
I'd be very glad if someone could point out why this isn't working on Websphere. I'm not too sure about class-loading rules in Websphere and would appreciate any advice on this.
Turn on Class Loading trace. This would tell you what classes are loaded and from which Jar. As Sajan mentioned chances are that there are duplicate jars in the classpath and the classloader that you expect has not loaded this class (and a parent class loader has likely loaded a class).
NoClassDefFoundError (NCDFE) does mean it could not locate the class that it is looking for. Errors in static initialization would explicitly turn out as a "java.lang.ExceptionInInitializerError" (EIIE)
"
Both NCDFE and EIIE extend from Linkage error.
In general all these errors can easily be troubleshooted by turning on the class loading for the Server. Also use the Class Loader Viewer available in the admin console to aid in your troubleshooting activities.
HTH
Manglu
This is a sticky and common exception. Remember, that NoClassDefFoundError doesn't mean the class was not found, rather it means:
NoClassDefFoundError: The given class
could be found, but something went
wrong when initializing it (an
interface it implemented could not be
found, something went wrong in a
static initializer etc.).
From here.
Please check that you don't have the same class in any other possible jar
Please check if you have added the dependencies in pom.xml file.

How to use jaxb 2 in a web application within Oracle Application Server

I have an application that is running Jaxb 2.1.12. I am running JDK 1.5 and OC4J 10.1.3.4.0. When I try to use the portion of my application that is using Jaxb, I get the following error:
Unable to locate jaxb.properties for package
I narrowed this down to the xml.jar that comes with OC4J. It contains Jaxb 1.0 classes. I can fix this error by adding the following to the orion-application.xml file:
<imported-shared-libraries>
<remove-inherited name="oracle.xml"/>
</imported-shared-libraries>
The problem is that I am deploying the WAR file to OC4J by using the admin_client.jar utility. I do not have an EAR to put the orion-application.xml file in, so I decided to try adding the orion-web.xml file to the WAR's WEB-INF directory and setting the search-local-classes-first property to true:
<?xml version="1.0"?>
<orion-web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-web-10_0.xsd" deployment-version="10.1.3.4.0"
jsp-cache-directory="./persistence"
jsp-cache-tlds="standard"
simple-jsp-mapping="false"
temporary-directory="./temp"
schema-major-version="10" schema-minor-version="0" >
<web-app-class-loader search-local-classes-first="true" />
<web-app>
</web-app>
</orion-web-app>
This causes the application to not deploy at all. I get an error saying that the Spring configuration files cannot be parsed. I would like to use search-local-classes-first. How can I use this property? Also is there a way that I can deploy the orion-application.xml file with the WAR file?
09/11/16 13:26:01 WARNING: DeployerRunnable.run Unexpected exception parsing XML document from Servl
etContext resource [/WEB-INF/applicationContext-acegi-security.xml]; nested exception is java.lang.C
lassCastException: oracle.xml.jaxp.JXDocumentBuilderFactoryoracle.oc4j.admin.internal.DeployerExcept
ion: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationCon
text-acegi-security.xml]; nested exception is java.lang.ClassCastException: oracle.xml.jaxp.JXDocume
ntBuilderFactory
at oracle.oc4j.admin.internal.DeployerBase.execute(DeployerBase.java:126)
at oracle.oc4j.admin.jmx.server.mbeans.deploy.OC4JDeployerRunnable.doRun(OC4JDeployerRunnabl
e.java:52)
at oracle.oc4j.admin.jmx.server.mbeans.deploy.DeployerRunnable.run(DeployerRunnable.java:81)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledE
xecutor.java:303)
at java.lang.Thread.run(Thread.java:595)
Note: I do not get this error with Java 1.6 and I believe that is because 1.6 comes packaged with Jaxb 2.
If creating a ear file solves the problem, I recomend you go this way. Also, when you deploy a war file, the container creates an ear for you. Check in the applications directory of the oc4j's install dir for the ear file.
In the documentation for "search-local-classes-first" I saw the following line:
In accordance with the servlet specification, search-local-classes-first functionality cannot be used in loading classes in java. or javax.* packages.*
Since, JAXB2 is included in JDK 1.6 and is now under javax.*, maybe the appserver ignores the classes/library even though it is present in the WEB-INF/lib directory. Try putting the JAXB jars in your $JRE_HOME/lib directory. If it is picked up, then you can try modifying the startup scripts for your appserver to include the JAXB jars in the primordial classpath.
The solution is a bit of a hack :). Here's a link with steps for doing the same thing for Apache CXF.
Replacing JAXB with JAXB2.0 in OC4j

spring enabled web application

Hello gud fellas in my quest of learning spring, i created a web application with netbeans 6.7 in windows xp sp2.i've noticed some and have few question about that.
1 my applicationContext.xml config file is in WEB-INF and my test class cannot find it.i had a copy of it in source package under default package and i can be found.Isn't WEB-INF part of the classpath?
1.1 where should it normally reside in this case?
2 i've tried to use the SpringJUnit4ClassRunner class but couldn't find the library any where.how to add spring-test jar to my project in netbeans?
i've never tried it but i'ld like to know how to enable quartz in this project.From my understanding quartz comes with spring(correct me if i'm wrong).How to enable it
those are my worries for now.thanks for reading.
WEB-INF is not in the application classpath, no, but WEB-INF/classes is.

Categories