I've written a simple javaagent that basically injects some logging in classes that are part of the JDK, such as javax/imageio/spi/ServiceRegistry, using javassist.
It works fine in a simple standalone application, but I cannot get it to work in WildFly 10. What I have tried:
Added the agent JAR as a module to WildFly along with the corresponding module.xml which declares <module name="org.javassist"/> as dependency
Appended the agent package and org.javassist to JBOSS_MODULES_SYSTEM_PKGS
Appended -javaagent:/full/path/to/agent/jar/in/module to JAVA_OPTS
WildFly starts but in server.log I get:
java.lang.NoClassDefFoundError: javassist/ClassPool
at net.luniks.agent.LoggerChanger.transform(LoggerChanger.java:48)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1015)
at java.lang.ClassLoader.loadClass(ClassLoader.java:413)
at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.jboss.modules.ClassLoaderLocalLoader.loadClassLocal(ClassLoaderLocalLoader.java:74)
at org.jboss.modules.Module.loadModuleClass(Module.java:606)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
It seems the module class loader is used but even though the agent module has a dependency to org.javassist, it still cannot load its classes.
What am I missing?
Eventually I got it to work by adding only the package of the agent to JBOSS_MODULES_SYSTEM_PKGS (not "javassist") and adding the org.javassist module JAR to the boot classpath:
JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:/path/to/wildfly/modules/system/layers/base/org/javassist/main/javassist-3.18.1-GA.jar"
Now the agent works, it can load the Javassist classes. Certainly not the clean way but it is just for debugging purposes...
Related
I tried injecting a method call statement using javassist in every method of some desired classes. The statement corresponds to a class in the java-agent jar. For example if my agent has class like a.b.HelperClass, I am injecting a.b.HelperClass.call(); in the beginning of every class using javassist.
I tried with a spring boot web app and the agent works fine but with RCP application it is throwing
java.lang.ClassNotFoundException: a.b.HelperClass
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Do I need to load the classes residing inside agent-jar using the eclipse class loader? BTW I'm instrumenting by calling agent-main method and not premain.
Eclipse is OSGi based and has a module system that is enforced.
The HelperClass must be in the classpath of the Eclipse Plugin where it should be used.
I'm new with OSGi and I'm having trouble trying to run an example of this library: https://github.com/jitsi/libjitsi
java.lang.NoClassDefFoundError: org/osgi/framework/BundleContext
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
at org.jitsi.service.libjitsi.LibJitsi.start(LibJitsi.java:247)
at org.jitsi.service.libjitsi.LibJitsi.start(LibJitsi.java:180)
at com.dotsystem.AVTransmit2.main(AVTransmit2.java:327)
Caused by: java.lang.ClassNotFoundException: org.osgi.framework.BundleContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Do I need an external jar for osgi?
A class not found exception on a core osgi class, seems that you are missing a jar/framework jar that implements OSGi specification. Check which OSGi implementation your target system supports. If you have choice in choosing you can try,
Apache felix OSGi
Eclipse equinox OSGi
If you are trying to run example from IntelliJ it may be problem that you haven`t imported maven dependencies. When you import java project into IntelliJ you must also import its dependencies (they are not imported by default).
I have built and deployed a war file in websphere 8.5 server. All axis 1.4 related jars are placed in WEB-INF/lib folder. However when I run the application and try to access the code that calls the webservice I get below error. Same war file works fine in TOMCAT 7 server. I do see that axis.jar exist and contains axisfault.class. Please help.
Caused by: java.lang.NoClassDefFoundError: org.apache.axis.AxisFault
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:93)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:170)
at java.lang.Class.forNameImpl(Native Method)
at java.lang.Class.forName(Class.java:179)
at org.uddi4j.transport.TransportFactory.getTransport(TransportFactory.java:61)
at org.uddi4j.client.UDDIProxy.send(UDDIProxy.java:1940)
at org.uddi4j.client.UDDIProxy.find_service(UDDIProxy.java:888)
at bofasecurity.UDDIHelper.getEndPoint(UDDIHelper.java:70)
at bofasecurity.xxxxSecurityWrapper.buildBofASecurityWrapper(BofASecurityWrapper.java:273)
at bofasecurity.xxxxSecurityWrapper.<init>(BofASecurityWrapper.java:212)
at bofasecurity.xxxxSecurityWrapper$Builder.build(BofASecurityWrapper.java:179)
at com.ml.grci.service.impl.SearchACCLServiceImpl.buildSecWrapper(SearchACCLServiceImpl.java:721)
at com.ml.grci.service.impl.SearchACCLServiceImpl.searchACCL(SearchACCLServiceImpl.java:160)
at com.ml.grci.webapp.action.ACCLSearchAction.execute(ACCLSearchAction.java:233)
... 83 more
Caused by: java.lang.ClassNotFoundException: org.apache.axis.AxisFault
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:650)
This is likely due to a classloader issue. WebSphere 8.5 loads axis.jar (see /deploytool/itp/plugins/org.apache.axis_1.4.0.v201005080400/lib). Would recommend either removing the conflicting jar or changing the class loader policy (PARENT LAST). See how to set java class loader PARENT_LAST
Also not sure if this would help, but if you're trying to do web services using a third party framework there's a very good article on how to do this: http://www.ibm.com/developerworks/websphere/library/techarticles/1001_thaker/1001_thaker.html
I am running a java application on Apache Tomact 6.0.32 and rrunning successfully and same thing I am running on Test Server with same Apache Tomact 6.0.32 config and getting following exception, any help will be highly appreciated.
Caused by: java.lang.ClassNotFoundException: org.JSON.JSONException
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
I am already using JSON Parser.jar
JSON lib requires commons-lang and other libraries as mentioned below as mentioned here.
Json-lib requires (at least) the following dependencies in your class
path:
jakarta commons-lang 2.5
jakarta commons-beanutils 1.8.0
jakarta commons-collections 3.2.1
jakarta commons-logging 1.1.1
ezmorph 1.0.6
Are you sure you have added the above libraries.
#Vardan Gupta,You think the tomcat is the same ,but things would not be like the same.
If I were you,I would do like this:
Choice I):copy test server's tomcat 6.0.32 to the environment you run successfully, then test the war in this copy.
Choice II):Or you can try to copy the tomcat you run successfully to the test server and do the new test.
Thus,you would found out things.
In my experience,I would copy tomcat(run successfully copy) to the test server...
On Weblogic 10.3 my enterprise application includes a webservice that runs ant scripts inside. My problem is that I cannot get my custom tasks running due to java.lang.ClassNotFoundExceptions.
(All this works well on Tomcat 5.5)
My task implementation can be found in 4 different locations:
something.ear/APP-INF/lib/antaddon.jar!/foo/bar/MyTask.class
something.ear/Webservice.war/WEB-INF/lib/antaddon.jar!/foo/bar/MyTask.class
something.ear/Webservice.war/WEB-INF/classes/foo/bar/MyTask.class
server/lib/antaddon.jar!/foo/bar/MyTask.class
I see that the Weblogic 10.3 integrated Ant 1.6.5 module might cause problems
as I have an Ant 1.8.0 bundled, so I added
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>org.apache.ant.*</package-name>
<package-name>org.apache.zip.*</package-name>
</prefer-application-packages>
to my weblogic-application.xml to overcome this. (This solved some NoSuchMethodErrors..)
However my Task is still not found:
java.lang.ClassNotFoundException: foo.bar.MyTask.class
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:457)
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:183)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:142)
at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:91)
can you help me how to solve this?
The problem was that my prefer-application-packages directive was wrong, ant classes are not in org.apache.ant.* but in org.apache.tools.ant.*. After repairing this my custom class gets loaded and works well from APP-INF/lib/antaddon.jar