JBoss EAP 6.4: NoClassDefFoundError on class sun.security.jca.GetInstance - jboss

I have a deployment that calls javax.crypto.SecretKeyFactory.getInstance.
The class javax.crypto.SecretKeyFactory appears to load correctly, but when the method tries to create an instance it throws a NoClassDefFoundError on sun/security/jca/GetInstance
Looking at the OpenJDK8 sources shows that relevant javax.crypto.SecretKeyFactory constructor refers explicitly to a method in sun.security.jca.GetInstance, so it's normal that it tries to load it.
What's odd is that both javax/crypto/SecretKeyFactory.class and sun/security/jca/GetInstance.class are present in /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.el6.x86_64/jre/lib/rt.jar but that only the former is found by the classloader.
What is the jboss module classloader playing at and how can I get it to stop it?
Thanks for suggestions.

Not all JDK classes are exposed to a deployment by default. If your deployment uses JDK classes that are not exposed you can get access to them using jboss-deployment-structure.xml with system dependencies:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
<dependencies>
<system export="true">
<paths>
<path name="sun/security/jca"/>
</paths>
</system>
</dependencies>
</deployment>
</jboss-deployment-structure>
Another alternative you can import the whole system module adding the following line to MANIFEST.MF:
Dependencies: system
Ref: Class Loading and Modules

In your JBoss installation, go to directory modules/sun/jdk/main and edit the module.xml file there. In <dependencies>/<system>/<paths> add an element <path name="sun/security/jca"/>. Restart your JBoss instance and retry.

I finally fixed my problem, though not quite in the ways suggested above. I wouldn't have got there without the help though (thanks guys).
I did manage to fix the sun/security/jca access problem but it then threw up another problem of a similar type, but with a javax class. I found an ugly fix for that by removing a jar from module org/jboss/genericjms and letting the jdk version get picked up, but I felt that that was playing around too much with stuff that I couldn't predict the consequences of.
The fix I have finally settled on is to put the provided jar that references javax/crypto/SecretKeyFactory in a new module all of its own and then to pull in the classes it needs via:
<system export="true">
<paths>
<path name="java/sql"/>
<path name="javax/crypto"/>
<path name="javax/crypto/spec"/>
<path name="javax/crypto/interfaces"/>
<path name="javax/management"/>
<path name="javax/security/auth/login"/>
<path name="sun/security/jca"/>
<path name="org/ietf/jgss"/>
</paths>
</system>
in the module.xml. When I reference this new module from my code it works (I pulled it in by making it a global module in standalone.xml in fact).
Problem solved. Though I have to say that after this experience of the jboss modular class loader, give me a hierarchical one any day.
Thanks again for the help.

Related

Possibility to access wildfly / app server libraries via jboss-deployment-structure.xml?

I have a web application running on a wildfly app server (22.X). It contains a war file which has the ability (besides the actual functionality) to query the wildfly itself for its active running sessions via JMX and display that number on an simple html page.
Originally the following dependency was added (via maven) to make this work:
<dependency>
<groupId>org.jboss.remotingjmx</groupId>
<artifactId>remoting-jmx</artifactId>
<version>3.0.4.Final</version>
However this dependency brings lots of other transitive dependencies along like jboss-marshalling, xnio, jboss-threads, wildfly-*, (...) - all packages which does exist within the wildfly app server anyway. So I was wondering whether it is possible to use those app server packages instead of bundling it as part of the war. I tried to add the following to the jboss-deployment-structure.xml to the EAR:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
<deployment>
<dependencies>
<system export="true">
<paths>
<path name="sun/reflect"/>
</paths>
</system>
</dependencies>
</deployment>
<sub-deployment name="service.war">
<dependencies>
<module name="org.jboss.remoting3.remoting-jmx" services="import"/>
</dependencies>
</sub-deployment>
However it didn't work - as soon as the dependencies were removed from the war file it stopped working. My question:
Is it possible to specify/configure the deployment structure file to allow access to the necessary packages from the application server? (I know that this is a wildfly specific solution but this is intended)
It looks like this module has moved to org.jboss.remoting-jmx. The org.jboss.remoting3.remoting-jmx does export the org.jboss.remoting-jmx module in WildFly 22, however the services are not exported which could be the issue.
Either way, it's best to use the org.jboss.remoting-jmx.

jboss eap 6.4 oracle.sql.ARRAY cannot be cast to oracle.sql.ARRAY

JBoss EAP 6.4 standalone server
Application deployed as a war file throws a runtime exception
java.lang.ClassCastException: oracle.sql.ARRAY cannot be cast to oracle.sql.ARRAY
at line
ARRAY a = (ARRAY) cs.getArray(1);
JDBC libary included is ojdbc14.jar (WEB_INF/lib). All libraries are included in the war file and there are no "global" libaries setup on the server. I have verified no other jdbc libraries are included anywhere in the app.
In order to create a JDBC datasource, i created a deployment for ojdbc14.jar. This is the only possible source of conflict i can think of. When i remove the ojdbc14.jar from the war file, i get a ClassNotFound exception in place of the ClassCastException.
Every other part of the app works fine except this line. How do i debug this any further?
I have try something ,but not work:
(1)add a jboss-deployment-structure.xml into web-inf/.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.oracle" slot="main"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
not work and the war dont write the log too.
This error occurs when you have two copies of the class packaged.
Based on your description, one copy is in the deployment for the Oracle driver. The second copy is in the application.
Remove it from application and instead of deploying oracle jar in deployment directory, create module of it.

Eclipse/Grails - Tests don't run - ClassNotFoundException [duplicate]

While running junit test in eclipse I am getting this Exception:
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
I've added junit.jar library file.
I've tried different versions of junit.jar: 4.4, 4.8, etc.
How do I fix this Exception?
Add hamcrest-all-X.X.jar to your classpath.
Latest version as of Feb 2015 is 1.3:
http://code.google.com/p/hamcrest/downloads/detail?name=hamcrest-all-1.3.jar&can=2&q=
According to the JUnit GitHub team website (https://github.com/junit-team/junit/wiki/Download-and-Install), junit.jar and hamcrest-core.jar are both needed in the classpath when using JUnit 4.11.
Here is the Maven dependency block for including junit and hamcrest.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.1.2</version>
<scope>test</scope>
</dependency>
<!-- Needed by junit -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
A few steps you have to follow:
Right click on the project.
Choose Build Path Then from its menu choose Add Libraries.
Choose JUnit then click Next.
Choose JUnit4 then Finish.
Works for me: IntelliJ IDEA 13.1.1, JUnit4, Java 6
I changed the file in project path: [PROJECT_NAME].iml
Replaced:
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
By:
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
So the final .iml file is:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
P.S.: save the file and don't let to IntelliJ Idea reload it. Just once.
You need junit-dep.jar because the junit.jar has a copy of old Hamcrest classes.
Just in case there's anyone here using netbeans and has the same problem, all you have to do is
Right click on TestLibraries
Click on Add Library
Select JUnit and click add library
Repeat the process but this time click on Hamcrest and the click add library
This should solve the problem
This problem is because of your classpath miss hamcrest-core-1.3.jar. To resolve this add hamcrest-core-1.3.jar as you add junit-4.XX.jar into your classpath.
At first, I encounter this problem too, but after I refer to the official site and add hamcrest-core-1.3.jar into classpath with command line, it works properly finally.
javac -d ../../../../bin/ -cp ~/libs/junit-4.12.jar:/home/limxtop/projects/algorithms/bin MaxHeapTest.java
java -cp ../../../../bin/:/home/limxtop/libs/junit-4.12.jar:/home/limxtop/libs/hamcrest-core-1.3.jar org.junit.runner.JUnitCore com.limxtop.heap.MaxHeapTest
You need to add the hamcrest-core JAR to the classpath as described here: https://github.com/junit-team/junit4/wiki/Download-and-Install
As a general rule, always make sure hamcrest is before any other testing libraries on the classpath, as many such libraries include hamcrest classes and may therefore conflict with the hamcrest version you're using. This will resolve most problems of the type you're describing.
the simplest way of solving the problem to begin with is copying latest version of hamcrest-code.jar into your CLASSPATH that is the file you store other .jar files needed for compilation and running of your application.
that could be e.g.: C:/ant/lib
It sounds like a classpath issue, so there are a few different ways to go about it. Where does org/hamcret/SelfDescribing come from? Is that your class or in a different jar?
Try going to your project Build Path and on the Libraries tab, add a Library. You should be able to choose JUnit to your project. This is a little bit different than just having the JUnit jar file In your project.
In your Run Configuration for the JUnit test, check the Classpath. You could probably fix this by adding making sure your Classpath can see that SelfDescribing class there. The Run option in Eclipse has a different set of options for the JUnit options.
If this problem arise in a RCP project it can be because JUnit has been explicitly imported.
Check the editor for your plugin.xml under Dependencies tab, remove the org.junit from the Imported Packages and add org.junit to the Required Plug-ins.
The problem is when you set up eclipse to point to JRE instead of JDK. JRE has junit4.jar in the lib/ext folder, but not hamcrest.jar :) So the solution is to check installed JREs in Eclipse, remove the existing one and create a new one pointing to your JDK.
This happens when you run Ant via command line. The implicit user dependencies are added in the classpath at the end and take precedence over the project-added classpath. Run Ant with -nouserlib flag. The implicit dependencies would be excluded from the classpath.
There is a better answer to solve this problem.
add dependency
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
The hamcrest-core-1.3.jar available on maven repository is deprecated.
Download working hamcrest-core-1.3.jar from official Junit4 github link .
If you want to download from maven repository, use latest hamcrest-XX.jar.
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
I had the same problem, the solution is to add in build path/plugin the jar org.hamcrest.core_1xx, you can find it in eclipse/plugins.
A few steps you have to follow:
Right click on the project.
Choose Build Path & then from its menu choose Add Libraries.
Choose JUnit then click Next.
Choose JUnit4 then Finish.
This works for me...
"java.lang.SecurityException: class" org.hamcrest.Matchers "'s signer information does not match signer information of other classes in the same package"
Do it:
Right-click on your package
click on Build Path -> Configure Build Path
Click on the Libraries tab
Remove JUnit
Apply and close
Ready.
Try adding the jar files manually or try with force update with the latest hamcrest.jar

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.

org/apache/commons/codec/DecoderException when integrating Ant-Contrib into Eclipse

I've tried to integrate Ant-Contrib 1.0b3 into Eclipse by adding the ant-contrib-1.0b3.jar and the appendant jar-files from the libs-directory to the "Global Entries"-section of the Ant-Runtime-preferences page in Eclipse.
For tasks that don't need the libs, such as propertyregex, this works fine.
But when I try to use the postMethod task I get the following error:
java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
Any suggestions on what to do to resolve this?
It looks like your rig doesn't include the Apache Commons Codec which must be a dependency of ant-contrib.
According to the dependencies here you might also need commons-logging, but you've probably already got that.
It's much cleaner to specify classpath when you define 3rd-party tasks in your build file.
Provide either individual jars or add a <fileset> of dependent jars to classpath, e.g.
<taskdef
resource="net/sf/antcontrib/antlib.xml"
uri="http://ant-contrib.sourceforge.net"
>
<classpath>
<pathelement location="${ant-contrib.jar}"/>
<fileset dir="${ant-contrib-dependency.lib}">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
You can define default ant-contrib.jar and ant-contrib-dependency.lib properties in this build file, and provide project specific overrides in ant build tool VM arguments. This means you don't have to copy these files into various directories on your system.