Linkage Error while starting WildFly - java

I have a dependency JAR that i copy into APP-INF/lib directory which is listed in application.xml file as <library-directory>APP-INF/lib</library-directory>
When ever i try to start the server i get following error
Can anybody please help me solve this problem.

Have a look at:
https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly
Our deployment structure looks essentially like this:
my.ear
+ lib/ <-- dependencies for multi-submodule deployment
+ META-INF/ <-- application.xml defines submodule(s) e.g. web.war,
<-- also jboss-deployment-structure.xml to include/export wildfly core modules for your EAR
+ web.war <-- our core deployment
I think in your case, you could just deploy your JARs to EAR/lib and they should be found across all submodules. From the Wildfly docs "Sub deployments (wars and ejb-jars) always have a dependency on the parent module, which gives them access to classes in EAR/lib"

Related

Export-Package from OSGi bundle with bundled jars

I need some help to access exported packages for an OSGi bundle.
I have a simple OSGi bundle jar which essentially bundles some other non-OSGi jars and exports their packages. This OSGi jar is structured like:
root/
lib/
mylib.jar
META-INF
MANIFEST.MF
It's MANIFEST.MF looks as below. The package mylib.mypackage is available in the bundled jar lib/mylib.jar.
Manifest-Version: 1.0
Bundle-Name: my.osgi.bundle
....
Bundle-ClassPath: .,lib/mylib.jar
Export-Package: mylib.mypackge
I need to access the package mylib.mypackage from a plain Java application. I have tried following construct by leveraging eclipse or equinox:
/*
the installBundle() is used to load the packages & packages from myosgi.jar
because it is not directly added to the class-path
*/
....
EclipseStarter.getSystemBundleContext().installBundle("file:<<path-to>>\\myosgi.jar");
EclipseStarter.run(null);
mylib.mypackge.MySampleClass obj = new mylib.mypackge.MySampleClass();
....
The myosgi.jar is NOT added to the classpath directly and installBundle() API above is intended for class loading for myosgi.jar. Adding myosgi.jar in classpath anyway does not resolve mylib.mypackge.
However the above line fails with error ClassNotFoundException / ClassDefNotFoundError for mylib.mypackge.MySampleClass.
I need some guidance for:
How can I access the classes from the packages from myosgi.jar in a plain Java application? I am fine with initiating an OSGi runtime codefully inside my application.
Is there any way to auto-test the myosgi.jar to check if the packages exported by this jar are getting correctly resolved (in an OSGi env)? I don't have access to maven, we use ant for our builds. I would prefer to have minimal dependencies on any 3rd party jars for testing purpose.
Thanks in advance.
Regards,
Gau

stateless ejb in WAR > package to EAR > local ejb call

I have an ear which contains 2 war files and each war contains stateless ejb and jersey rest classes. The interfaces locate in commons.jar file. The EAR structure looks like this:
EAR
-- /lib/commons.jar
-- rest-1.war
-- stateless-ejb-1.java
-- jersey-rest-1.java
-- rest-2.war
-- stateless-ejb-2.java
-- jersey-rest-2.java
I am trying to use stateless-ejb-1 from stateless-ejb-2 with #Inject annotation but I get a CDI deployment failure:WELD-001408: Unsatisfied dependencies error during deployment time. When I use #EJB in stateless-ejb-2 then the ear is deployed but I get a remote lookup error while calling jersey-rest-2.
This are my method call chains:
jersey-rest-1 > stateless-ejb-1: works fine
jersey-rest-2 > stateless-ejb-2 > stateless-ejb-1: I get an ejb-1 lookup error
I do not want to use remote ejb call because everything is packaged in the same ear (I would like to use #Inject instead of #EJB) but it does not work.
I guess that if I pack stateless-ejb-1.java to a jar and put it under EJB/lib than it will work. But I do not want to create a new module in my project just to pack this one file to separated jar file.
What is the solution?
You need to move stateless-ejb-1 into an ejb-jar module in the EAR.
Classes in different WAR files are never visible to each other, even when built into an EAR file.

Wildfly Class Loading issue with jca resourceadapter

I am trying to deploy an ear application on wildfly 9 that tries to connect to MQ and to a JCA resource adapter.
Structure of my ear file
myApp.ear
|--lib/
|----Spring.jar (Multiple jars for different modules needed)
|----META-INF/
|--myAppEJB.jar (EJB project)
|--myAppWeb.war
|--jboss-deployment-structure.xml
The JCA resource adapter (myCompConnector.rar) is packaged as a rar and deployed with an ra.xml inside it. myCompConnector uses two jars supportingjar1.jar and supportingjar2.jar and are packaged inside the rar file.
Structure of my MyCompConnector.rar:
MyCompConnector.rar
|--META-INF
|--supportingjar1.jar
|--supportingjar2.jar
|--MyCompConnector.jar
my application also uses the classes that are in myCompConnector but is compiled with myCompConnector.jar. I make the build using maven 3 and I do not package the myCompConnector.jar or any depending jars.
If i deploy it says that NoClassDefFoundError for a class in supportingjar1.jar, So i add ONLY the supporting jars by putting in the lib of the ear myApp.ear (making the war a skinny war as well supporting jars are only used in the EJB project's pom file not in WAR)
Then If i deploy it on wildfly it says NoClassDefFoundError MyCompConnectorInspector.java and ClassNotFoundError MyCompConnectorInspector.java. MyCompConnectorInspector is a class in the MyCompConnector.jar which is also present in MyCompConnector.rar.
Caused by: java.lang.NoClassDefFoundError: Lcom/myComp/MyCompConnector/MyCompConnectorInspector ;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2317)
at java.lang.Class.getDeclaredFields(Class.java:1762)
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57)
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66)
... 10 more
Caused by: java.lang.ClassNotFoundException: com.mycomp.MyCompConnector.MyCompConnectorInspector from [Module "deployment.myApp-1.3.ear.myAppEJB-1.3.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
... 15 more
So I add MyCompConnector.jar as well in the lib folder of the ear file
(So now my MyCompConnector.rar is loaded and MyCompConnector.jar is loaded from the lib folder in the ear file)
If i deploy now it says ClassCastException: com.comp.MyCompConnector.MyCompConnectorInspector.java cannot be cast to com.comp.MyCompConnector.MyCompConnectorInspector.java
which is true as it is loaded from two sides. Now i cannot remove the rar resource adapter so if i remove the jar file from the lib of the ear it says the above mentioned error: NoClassDefFoundError MyCompConnectorInspector.java and ClassNotFoundError MyCompConnectorInspector.java.
So now i am in a fix. If i add the jar to remove the NoClassDefFoundError it will give me classcast exception.
In the event of the class cast exception I see that MyCompConnectorInspector is loaded from the RAR's MyCompConnector.jar (when i do -verbose=class) but when i remove the jar file from the myApp/lib/ then i do not see MyCompConnectorInspector being loaded from the RAR's MyCompConnector.jar.
my jboss-deployment-structure in the ear file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="MyCompConnector.rar" />
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.jms.api"/>
<!--<module name="com.compConnector.supportingjar1"/>
<module name="com.compConnector.supportingjar2"/> -->
</dependencies>
</deployment>
</jboss-deployment-structure>
How can I make the rar deployment seen as something that my ear file should refer to as a library as well as all he dependent libraries included in the RAR.
one more question: when i deploy a RAR, is it technically a module. (Modules are a new concept for me from Jboss 5 or websphere which i have worked with before)
One funny thing that I have seen, If i use
<module name="deployment.MyCompConnector.rar" />
that I have seen in some expamples in any Resource Adapter definition it does not load at all. if i remove the deployment. then it creates the jndi name for it and binds it. I dont know if it is related tough.
Any help will be appreciated. I am new to Wildfly so I am still learning its tricks.
Thanks.
P.S : I even tried to do
<global-modules>
<module name="deployment.MyCompConnector.rar" />
</global-modules>
but it only gave me Failed to load module: deployment.MyCompConnector.rar:main
Then ModuleNotFoundException : deployment.MyCompConnector.rar:main
i deployed the rar through the console and not through creating a module in the modules folder and then added a connection definition in the resourceAdppaters in the standalone-full.xml . this is the same I deployed the wmq.jmsra.rar file and then made the connection definition.
It seems there is an issue in Wildfly when a resource adapter is being referenced from within a jar (in modules) or from a jar inside an ear. In a war it works fine.
I may be mistaken when i assume there is an issue in WF9. but i made it to work. I had this issue in case of an ear as well as a jar.
in case of ear I simply converted the ear into a war and pluggged my EJBs into the War's WEB-INF/lib folder as a jar. and it worked without any issues.
Hopefully it will help some one who has a RAR resource adapter and is using the resource adapter'sconnection classes as library inside the EJBs of an ear project.

How to specify order of JAR class loading in weblogic

I have an EAR file that contains two different jars that share some classes with an identical package.class name. These JARs are deployed in my APP-INF/lib directory.
Let's say A jar contains the latest version of classes and B contains the old version of classes. When a class is referenced Weblogic looks first into B jar and loads the old version which break some functionality.
How can I tell Weblogic to load jar A before B from APP-INF/lib? I need to define a specific order to avoid loading old classes.
I have already tried adding A jar to <classloader-structure> in weblogic-application.xml like so:
EAR structure:
EAR
\--->A.jar
\--->webapp.war
.....
weblogic-application.xml:
<classloader-structure>
<module-ref>
<module-uri>A.jar</module-uri>
</module-ref>
.......
</classloader-structure>
but then it throws error saying
weblogic.management.DeploymentException: classloader-structure element in weblogic-application.xml is referencing the module-uri A.jar which does not exist in this application.
Also one thing to remember is that A.jar is not a module, war or EJB it just a plain hibernate library: hibernate-jpa-2.0-api-1.0.1.Final.jar
I am using Weblogic 12c version.
You need to set parent last strategy for class-loader, refer http://www.rgagnon.com/javadetails/java-0551.html, as i remember there is a GUI in weblogic server to do the same.

Glassfish 3.1b41 - JDO83008: CMP Compilation failed: class file not found

we have an "old" JavaEE Application, which we want to port from the old Sun Application Server 9.1 to the current Glassfish 3.1. We updated the deployment descriptor xml files (renamed them, updated DocType, validated against DTD, nothing else). But when we try to the deploy into the GF3.1 we get this error:
JDO83008: CMP Compilation failed:
C:\workspace\glassfish31eclipsedefaultdomain\generated\ejb\archivetool-app-1.9.5\archivetool-ejb-1.9.5_jar\de\ems\archivetool\ejb\metadata\cd\eb\CdBean_821611534_ConcreteImpl.java:10:
cannot access de.ems.archivetool.ejb.framework.AbstractCMPBean
class file for de.ems.archivetool.ejb.framework.AbstractCMPBean not found
C:\workspace\glassfish31eclipsedefaultdomain\generated\ejb\archivetool-app-1.9.5\archivetool-ejb-1.9.5_jar\de\ems\archivetool\ejb\productdata\product\eb\ProductionLibraryBean40992531_ConcreteImpl.java:416:
cannot find symbol
symbol : class EBSBusinessException
location: package de.ems.archivetool.ejb.framework
WARNUNG: JDO83004: CMP Compilation failed. See log for details.
SCHWERWIEGEND: Exception while invoking class org.glassfish.ejb.startup.EjbDeployer prepare method
SCHWERWIEGEND: Exception while invoking class org.glassfish.javaee.full.deployment.EarDeployer prepare method
SCHWERWIEGEND: Exception while preparing the app
SCHWERWIEGEND: JDO83004: CMP Compilation failed. See log for details.
org.glassfish.deployment.common.DeploymentException: JDO83004: CMP Compilation failed. See log for details.
But we can still deploy in the old SUN App Server.
The application consists of 4 modules and a build module. Generally, the .ear file, consisting of the two EJB modules, one WAR module and one JAR module, is build with Maven without problems (UnitTest succeed etc).
(pom.xml and the resulting application.xml)
So, everything builds fine, but when we try to deploy the application to GF3.1 we get the "class file not found" error. The classes which are not found are within the JAR module and contain base classes for the EJB modules.
Does anyone has a starting point?
Regards,
Andreas
Ok, after hours of googeling, I finally found the exact answer to this problem here.
The important part is:
The Java EE 6 specification imposes strict rules about which JAR files
are visible from an enterprise archive (EAR) file. Refer to section
EE.8.3.3; specifically, application client modules should not have
access to any EJB JAR file unless the application client JAR file's
manifest Class-Path refers to the EJB JAR file(s) explicitly.
This is a change from GlassFish Server v2, in which application
clients automatically had access to all EJB JAR files in the EAR file
and all JAR files at the top level of the EAR file. To comply with the
stricter specification language, GlassFish Server 3.0.1 cannot
automatically provide application clients with access to these JAR
files.
What you have to do is, let maven put the jar (and other dependencies) into a library folder in the ear container. You do this by adding this to your ear pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
//here starts the important part
<defaultLibBundleDir>lib</defaultLibBundleDir>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
//end of important part
<modules>
<jarModule>
<groupId>gID</groupId>
<artifactId>aID</artifactId>
</jarModule>
//etc some more ebjs, war, ...
</modules>
This will put the jar module into a folder lib, and all depending ejbs will get the Class-Path entry in their MANIFEST.MF.
Hope that helps some of you with the same problem.

Categories

Resources