Class loading issue with Eclipse RAP and WebLogic 12.2.1.3 - weblogic12c

Whilst deploying an Eclipse RAP war file on WebLogic 12.2.1.3, we are encountering the following error;
java.lang.LinkageError: loader constraint violation: loader previously initiated loading for a different type with name "org/aopalliance/aop/Advice"
After performing some analysis we identified the issue is due to WebLogic 12.2.1.3 shipping with org.glassfish.hk2.external.aopalliance-repackaged.jar within oracle_common\modules, and this conflicts with com.springsource.org.aopalliance_1.0.0.jar, within the WEB-INF\plugins directory of our WAR file.
We have tried a few things to remediate this, but with no luck so far;
Removed org.glassfish.hk2.external.aopalliance-repackaged.jar from oracle_common\modules (WebLogic deploys but then shuts itself down)
Remove com.springsource.org.aopalliance_1.0.0.jar from the WAR file (WebLogic starts, but does not deploy the bundles within the WAR file)
Updated weblogic.xml in the WAR file with;
<container-descriptor>
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<prefer-application-packages>
<package-name>org.aopalliance.*</package-name>
</prefer-application-packages>
</container-descriptor>
Copied com.springsource.org.aopalliance_1.0.0.jar to the WEB-INF\lib folder of the WAR, with the above weblogic.xml change
Any suggestions of other changes we could try would be much appreciated.
Many Thanks
Mike

try updating the launch.ini in your war file, setting the values for osgi.parentClassloader and osgi.contextClassLoaderParent to ext :-
osgi.parentClassloader=ext
osgi.contextClassLoaderParent=ext
Cheers
Rod

Related

org.springframework.aop.framework.AopConfigException Error in WebLogic 12c

I am in the process of upgrading WebLogic Server 11g (10.3.6.0) to 12c (12.2.1.3.0).
I installed the war file without a problem onto the 12c server. Then, I tried to start the module. I was getting weblogic.application.ModuleException: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.springframework.aop.framework.AopConfigException error due to missing a particular class file. It seems like the class file belongs to "spring-aop-2.5.2.jar."
When I deployed the same war file onto the WebLogic Server 11g environment, I did not observe any problem. I ensured that "spring-aop-2.5.2.jar" exists in the war file. I am using the version 2.5.2 for the SpringFramework. I suspect it may also be a problem.
Based on my research, some people suggested to append <package-name>net.sf.cglib.*</package-name> into the to <prefer-application-packages> in your weblogic-application.xml. I do not have the weblogic-application.xml in my project or in the war file. I only see the file on the server. Although I appended the tag into weblogic-application.xml, I am still geting the same error.
Should I configure anything else based on my description? Any idea?
Having the same issue, I got it to work by putting both spring and cglib jars in the ear APP-INF/lib folder and using the following META-INF/weblogic-application.xml
<?xml version='1.0' encoding='UTF-8'?>
<weblogic-application xmlns="http://xmlns.oracle.com/weblogic/weblogic-application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.3/weblogic-application.xsd">
<prefer-application-packages>
<package-name>net.sf.cglib.*</package-name>
<package-name>org.springframework.*</package-name>
</prefer-application-packages>
</weblogic-application>
From my understanding, it's important that:
Both cglib and spring jars are in the same classpath folder
Both are present in "prefer-application-packages"
Using "prefer-application-packages" in weblogic.xml inside my .war file did not seem to work for some reason.
You should modify your weblogic.xml file to use the proper libraries with prefer-application-packages. However, do not forget to include this.
<prefer-web-inf-classes>false</prefer-web-inf-classes>
Oracle states here
Note that in order to use prefer-application-packages or prefer-application-resources, prefer-web-inf-classes must be set to false.

How can I get Websphere to find persistence.xml in a jar file rather than META-INF?

I'm building a set of REST services and deploying each service to a separate WAR file. Since each of these services uses the exact same persistence configuration, I've placed my persistence.xml in a jar file (the path of the persistence.xml file in the jar is still /META-INF).
When running this using TomEE (1.7), this works just fine. However, when I try the same thing with WebSphere (8.5.5.x) my persistence units do not get loaded. In the WebSphere log, I get an error that looks like:
[4/27/16 8:54:21:653 EDT] 00000080 JPAApplInfo E CWWJP0029E: The server cannot find the MRO_PU_JTA persistence unit in the Customer_WAR.war module and the DS_APP_EAR application.
[4/27/16 8:54:21:654 EDT] 00000080 InjectionBind E CWNEN0035E: The ds.services.helper.AbstractServiceHelper/em reference of type javax.persistence.EntityManager for the component in the Customer_WAR.war module of the DS_APP_EAR application cannot be resolved.
[4/27/16 8:54:21:657 EDT] 00000080 ResourceInjec E CWOWB0102E: A JCDI error has occurred: The ds.services.helper.AbstractServiceHelper/em reference of type javax.persistence.EntityManager for the null component in the Customer_WAR.war module of the DS_APP_EAR application cannot be resolved.
When I copy the persistence.xml file from my jar file to the local WAR's META-INF, this error goes away and everything works fine. Since I have a ton of services to deploy this way, I don't want to have to make copies of persistence.xml for every WAR file.
Is there any way to get WebSphere to find my persistence.xml file? Maybe some setting in WebSphere that I haven't been able to find?
Thanks.
Ok, so it seems that this is a duplicate of the following: Sharing a persistence unit across components in a .ear file
Looking at the answer to that question from Pascal Thivent, it becomes fairly obvious what the problem is: In order to get this to work, the jar file that contains the persistence.xml must be present in the /lib directory of the EAR that is being deployed to WebSphere. Apparently, the way it works is that the EAR resolves the persistence.xml file, and when each WAR file attempts to inject the entity manager, it refers to the EAR to do so. This is in contrast to TomEE (which is deploying without an EAR file). In that case the dependency is resolved by the WAR file classloader, so just having the jar file in the classpath of the WAR is sufficient.

Improving startup time for java web application in glassfish 3.1

I am trying to reduce the start up time of my web application deployed in glassfish 3.1.1 (build 12) application server. My web application is deployed as a war file containing multiple jar files for every module in the application. The jar files are located in the WEB-INF\lib directory.
On enabling detailed logs for glassfish, I saw that glassfish tries to search the class files in WEB-INF\classes and does not find it. Since there are more than 16K classes there is an error message for every class file.
|FINE |org.apache.naming_.FileDirContext| 88|PWC4451: File cannot be read E:\glassfish3.1.1\glassfish\domains\domain1\applications\mywebapp\WEB-INF\classes\com.xxx.yyy.MyClass.class
I added a emtpy jar named all-jars.jar in WEB-INF\lib and it contains a MANIFEST.MF file with a classpath attribute. The Class-Path attribute looks as below.
Class-Path: WEB-INF/lib/a.jar WEB-INF/lib/b.jar WEB-INF/lib/c.jar
Adding this jar didn't help though.
How can I tell glassfish to not search in WEB-INF/classes directory? Also any other suggestions to reduce the start up time?

ClassNotFoundException when using User Libraries in Eclipse build path

I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.

JBoss 4.0.5 MDB Configuration

This one is beating me, and I have not been able to figure it out ... So here it goes.
I want to add a Message Drive Bean to my app which is packaged as a .ear file
Following the documentation I've created a jboss.xml and a ejb-jar.xml, which I tried to put on the META-INF and the root and on the WEB-INF but I just don;t see it working (i.e. the MDB is never loaded, nor it received the messages.
My ear file looks like:
META-INF/
META-INF/MANIFEST.MF
META-INF/application.xml
myapp.war
My final solution was to separate the MDB code (and supporting classes) into a separate file inside the ear (myapp-mdb.jar) And to support that with the same hibernate mappings and classes, the hibernate related files were packaged on the myapp.har.
META-INF\MANIFEST.MF
META-INF\application.xml
META-INF\jboss-app.xml
myapp-mdb.jar
myapp.har
myapp.war
Just posting the answer for reference.