Error in Referencing a Dependency Jar File from JBoss 7.1 - jboss

I reference a jar file from JBoss 7.1 module according to the instructions provided in a stackoverflow question here. I have used this jar in JBoss 5.x, 6.x without any issue. However, when I try to deploy a war file in JBoss 7.1 which references the above jar, it gives me the following error:
15:59:19,220 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host]. [/Max_client]] (MSC service thread 1-2) StandardWrapper.Throwable: java.lang
NoClassDefFoundError: org/xml/sax/SAXException
at com.systinet.wasp.webservice.ServiceClientImpl.lookup(ServiceClientImpl.java:556) [wasp.jar:]
at com.systinet.wasp.webservice.ServiceClientImpl.createProxy(ServiceClientImpl.java:437) [wasp.jar:]
at org.systinet.wasp.webservice.Registry.lookup(Registry.java:168) [wasp.jar:]
at MyServlet.init(MyServlet.java:103) at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Fi
al]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_35]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_35]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_35]
Caused by: java.lang.ClassNotFoundException: org.xml.sax.SAXException from [Module "commons.wasp:main" from local module loader #2adb1d4 (roots: c:\jboss-as-7.1.1
Final\modules)]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
... 15 more
I'm very new to this new module concept in JBoss 7. Any idea what is the issue here?
Thank you!
Details on what I tried to do:
I want to be able to make this dependency jar available globally. So what I did was created a folder structure modules/common_libs/test/main and placed the required jar in it. Then created the module descriptor module.xml:
<module xmlns="urn:jboss:module:1.1" name="common_libs.test">
<resources>
<resource-root path="test.jar"/>
</resources>
</module>
Then in the application from which I need to access this jar, I added in the MANIFEST.MF:
Dependencies: common_libs.test
The application is a war file and I deployed it under the deployment folder, and created a .war.dodeploy file. I get this exception when I start the JBoss server.
Any idea, anyone?
Thanks!

You need to look at the dependencies your module requires. With the current error message it looks like it needs a dependency on SAX. You should probably add a dependency for javax.api (this is the module SAX is in) to your module.xml.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="common_libs.test">
<resources>
<resource-root path="test.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
You'll need to add dependencies for any dependencies your shared library needs.

In your module.xml add a dependency on javax.api and it should work.
As you mentioned you are new to this module concept. So little explanation for what are we doing.
with JBoss AS7x archietecture, we use modules to provide jars/ classes to our application. One +ve of this is that it lightens the war.
We create modules for our jars, module.xml is a descriptor that acts as an ID/bio of the module , tells the server about what is in it <resources> tag
and what this module is dependent on
<dependencies> tag
For mostly all our module we add a dependency on javax.api so the module couldcompile. Why? Cant remember look out for it. And add as comment when you know it.
Hope this helps:-)

Related

Jboss eap-7.2: Adding external directory to a class-path

As per project need we need to migrate from jboss-eap-5.1.2 to jboss-eap-7.2 and for testing I was trying to deploy the war file in jboss-7.2.
But it started giving me exception
rom relative location [mailsender.xml]
Offending resource: class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreExcept
ion: IOException parsing XML document from URL [vfs:/C:/dev/migration/jboss-eap-7.2-eap/bin/content/basel.war/WEB-INF/classes/mailsender.xml]; ne
sted exception is java.io.FileNotFoundException: C:\dev\migration\jboss-eap-7.2-eap\standalone\tmp\vfs\temp\tempc01c1475a2367060\content-53d16429
03fec06a\WEB-INF\classes\mailsender.xml (The system cannot find the file specified)
i.e. file mailsender.xml is not added in the classpath.
Query : Is there any way in jboss-eap-7.2 to add a external folder(where I can put all of my XML's which needs to be present at the classpath) to classpath?
This works for me in JBOSS EAP 7.1, where APP-INF/classes resource folder in ear or war:
add META-INF/jboss-deployment-structure.xml with similar config:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<resources>
<resource-root path="APP-INF/classes" />
</resources>
</deployment>
</jboss-deployment-structure>

No Jar found in /WEB-INF/lib after deploying maven project from eclipse to wildlfy9

I am seeing a very strange behavior of wildfly9.x. Build process goes successful. after clicking on RUN AS -> Run on Server(WildFly9.x). It shows exception like NO class def found.
I have already added dependency in POM.xml and its scope is compile.
POM.xml file:
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.6</version>
<scope>compile</scope>
</dependency>
Exception:
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64 from [Module "deployment.worldportfolio.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
Thanks in advance.
I solved it by myself. If you want to run wildfly server from eclipse IDE so you should follow this a very simple method create lib folder in WEB-INF and place all the required Jars in the lib folder. You are done.

Wildfly 8.2 fails to load jbossws-cxf-client module

I am working on a web application that contains a Soap client and that needs to have access to the cxf Client implmentation, because we have to use different certificates for different calls to the remote endpoint.
Wildfly comes with a module jbossws-cxf-client which has dependencies to all the different cxf modules required. There is a maven version of this module as well.
In the maven module pom file we have a dependency like so:
<dependency>
<groupId>org.jboss.ws.cxf</groupId>
<artifactId>jbossws-cxf-client</artifactId>
<version>4.3.2.Final</version>
<scope>provided</scope>
</dependency>
Note that the version has been matched with the version that is mentioned in the wildfly 8.2 release notes:http://wildfly.org/news/2014/11/20/WildFly82-Final-Released/
When deploying our application we get the following message from the log:
14:22:12,492 INFO [org.jboss.weld.Bootstrap] (weld-worker-1) WELD-000119: Not generating any bean definitions from nl.topicuszorg.lsp.service.MultipleCertificatePingStubServiceImpl because of underlying class loading error: Type org.apache.cxf.transport.Conduit from [Module "deployment.kdplus-lsphub-server-1.1-SNAPSHOT.war:main" from Service Module Loader] not found. If this is unexpected, enable DEBUG logging to see the full error.
14:22:12,689 INFO [org.apache.deltaspike.core.util.ProjectStageProducer] (MSC service thread 1-2) Computed the following DeltaSpike ProjectStage: Production
14:22:13,628 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."kdplus-lsphub-server-1.1-SNAPSHOT.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."kdplus-lsphub-server-1.1-SNAPSHOT.war".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_25]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_25]
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type PingStubService with qualifiers #Default
at injection point [BackedAnnotatedField] #Inject nl.topicuszorg.lsp.service.PingPongServiceImpl.pingStubService
at nl.topicuszorg.lsp.service.PingPongServiceImpl.pingStubService(PingPongServiceImpl.java:0)
The real problem is logged as INFO, strangely enough. org.apache.cxf.transport.Conduit can not be loaded. This is part of the org.apache.cxf module, and should be loaded transitively by loading the jbossws-cxf-client module.
It should not be necessary, but we also implicitely declare the module dependencies in the jboss-deployment-structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<excludes>
</excludes>
<dependencies>
<module name="org.slf4j"/>
<module name="org.apache.cxf"/>
<module name="jbossws-cxf-client"/>
<module name="org.apache.cxf.impl"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
It seems the module is not loaded, I don't know why. I can not find a way to check which modules have been loaded.
What is going wrong here?
As it turned out I had to move my jboss-deployment-structure.xml from the META-INF to the WEB-INF directory.
Bummer...

class def not found in jboss as 7.X

I have a project structure as
eardirectory.Ear
lib/
my-custom-classes.jar
.....
.....
my-custom-ejb.jar
META-INF/
....
//Now I tried to load classes from classloader as
ClassLoader cl = Thread.currentThread().getContextClassLoader();
clazz = Class.forName(my-custom-classes.class1.class.getName(), true, cl);
but this will not work as current thread is of jboss and jboss has not any identification of my-custom-classes.jar.So my question is how this can be done with jboss? I have to have to load class definition at runtime.
Is there any way in "jboss-deployment-structure" I can define how to load classes before deploying EAR?
Follow the steps to create module it should work
Step-1
In jboss-as-7.1.1.Final/modules/com/company/gyani/main/
-module.xml
-my-custom-classes.jar
Content of module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.company.gyani">
<resources>
<resource-root path="my-custom-classes.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
Step-2 Now IN my.ear/META-INF/
-jboss-deployment-structure.xml
-MANIFEST.MF
Content of MANIFEST.MF
Manifest-Version: 1.0
Dependencies: com.company.gyani
You need to use concept of module(s) provided by JBoss AS7.
Here you configure your classes/jars/property files as modules and these are loaded while starting JBoss at server scope and are accessible to any deployed application that carries a dependency on this module.
Read through How to configure module

ClassNotFoundException while dynamic class loading in JBoss 7.1.1 from OSGi-bundle

I deployed a simple OSGi test-bundle into JBoss 7.1.1 and try to dynamically instantiate the Jacorb ORB by doing
Class clazz = Class.forName("org.jacorb.orb.ORB");
All I got is
java.lang.ClassNotFoundException: org.jacorb.orb.ORB from [Module "deployment.test:1.0.0" from Service Module Loader]
What I already did:
in the JBoss configuration standalone.xml I added for the osgi-subsystem the capability <capability name="org.jacorb" startlevel="1"/>, so that the org.jacorb module is loaded. That already solved the problem, that the installation of my test bundle fails.
I declared the Dependencies-Descriptor on org.jacorb in my MANIFEST.MF (also tried with and without the export option): Dependencies: org.jacorb export
I added the jboss-deployment-structure.xml to my META-INF with the following content
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.jacorb" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Also I did experiments with the ClassLoaders and realized, that the ContextClassLoader is null. But in the end, I cannot effect this as the non-test-code, because the Class.forName() cannot be changed to use a specific classloader.
So why do I get this ClassNotFoundException?
Thanks in advance
Alex
After hours of digging I did the puzzle ;-)
In standalone.xml/domain.xml JBoss configuration I added <capability name="org.jacorb" startlevel="1"/> in the <subsystem xmlns="urn:jboss:domain:osgi:1.2" activation="lazy"> section under <capabilities>
In the META-INF/MANIFEST.MF I added DynamicImport-Package: org.jacorb.orb to allow the classloader to dynamically extend the classpath during runtime
Set the context classloader by Thread.currentThread().setContextClassLoader(getClass().getClassLoader() that has been null before
If you have a normal OSGi bundle and it should see the org.jacorb.orb.ORB class,
then you should have:
1. ALL org.jacorb packages and subpackages have to be exported in the osgi framework.
2. Your bundle has to import ALL of the packages you use - e.g. with
"Import-Package:org.jacorb.orb"
Check that the versions are compatible.
Check that you import all packages and subpackages. Import of org.jacorb doesn't imply org.jacorb.orb.
If both conditions are satisfied, then the Bundle Classloader of your bundle should be able to see org.jacorb.orb.ORB.