I've been tasked with updating a plugin for Cytoscape, a biological visualization software platform, to the latest version of the Cytoscape API. Cytoscape 3.x uses an OSGI framework (Karaf 2.2.x, I think) to interface with its plugins (which are now called "apps").
The problem is that the plugin/app uses JAX-WS to communicate with an external server, and JAX-WS seems to have problems with loading classes in the OSGI environment.
Here is a snippet of the problematic code:
public class AnatServerService extends Service {
#WebEndpoint(name = "AnatServerPort")
public AnatServerIfc getServerPort() {
AnatServerIfc port = super.getPort(new QName("network", "AnatServerPort"), AnatServerIfc.class);
((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, path);
return port;
}
}
And here is the resulting exception:
java.lang.NoClassDefFoundError: com.sun.xml.internal.ws.api.message.Header not found by AnatApp [168]
at com.sun.proxy.$Proxy64.<clinit>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.reflect.Proxy.newInstance(Unknown Source)
at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createProxy(UnknownSource)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at javax.xml.ws.Service.getPort(Unknown Source)
at anat.ws.AnatServerService.getServerPort(AnatServerService.java:36)
at anat.task.AvailableNetworksTask.getAvailableNetworks(AvailableNetworksTask.java:39)
at anat.task.AvailableNetworksTask.run(AvailableNetworksTask.java:62)
at org.cytoscape.work.internal.sync.SyncTaskManager.execute(SyncTaskManager.java:86)
at anat.view.BackgroundDefinitionDialog$AvailableNetworksSwingWorker.doInBackground(BackgroundDefinitionDialog.java:1544)
at anat.view.BackgroundDefinitionDialog$AvailableNetworksSwingWorker.doInBackground(BackgroundDefinitionDialog.java:1535)
at javax.swing.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at javax.swing.SwingWorker.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I can confirm that this code does work outside of OSGI.
Any suggestions? I've tried experimenting with embedding the JAX-WS API and/or implementation classes directly into the bundle using Embed-Dependency, but that didn't help. I've also tried playing with the org.osgi.framework.system.packages.extra and org.osgi.framework.bootdelegation properties, to no avail. It is possible that I'm doing something wrong, though.
I'm afraid that OSGI might have some fundamental incompatibility with the Reflection API being used to create that header. But surely it can't be impossible to run a web service client in this environment, right?
It seems like JAX-WS is dynamically weaving dependencies into your bundle that were not present at build time. Because these dependencies are dynamic, the build tooling doesn't find them and doesn't generate an Import-Package statement for them.
Specifically your bundle has a dependency on the package com.sun.xml.internal.ws.api.message. You never wanted or asked for that dependency, but JAX-WS added it for you anyway. How nice of it!
Your question suggests that you are using Maven with the maven-bundle-plugin to build your bundle. Therefore you need to add something like this to your pom:
<Import-Package>
com.sun.xml.internal.ws.api.message,
*
</Import-Package>
Note that there may be other packages that need to be added to this list... you will probably find out about them after adding this one. Again, because these are dynamically weaved-in dependencies it's impossible to get a full list of them in advance.
With regard to your final question. You're right, it's certainly not impossible to run a web service client in this environment! However OSGi does tend to expose the invalid assumptions and bad coding practices that are typically found in crappy libraries like JAX-WS.
I've solved my own problem. It turns out I had edited the org.osgi.framework.bootdelegation property in the wrong file - config.properties instead of custom.properties.
This is still a problem in the long term, though. I'd like to be able to distribute this bundle without requiring users to edit config files.
I had the same problem. Adding the following line to Felix's config.properties file solved the problem:
org.osgi.framework.bootdelegation=com.sun.xml.internal.ws.*
Related
Fairly new to Webservices, have done some research and generated client stubs for a third party WSDL using JAX-WS RI (wsimport tool). JDK 8 is being used. Using generated Stubs, web service client is written to invoke the WSDL operations. Maven Build is successful but while testing it, getting "java.lang.NoClassDefFoundError: javax/xml/ws/Service".
Here is the Web service client. Tried to refer many resources for NoClassDefFoundError as well, but nothing actually worked. While debugging understood its failing in line-11 below. How to fix this NoClassDefFoundError, please Help?
line-11: ServiceWS service = new ServiceWS(); //#WebServiceClient
line-12: ServiceWSSoap stubWS = service.getServiceWSSoap(); //where ServiceWSSoap is #WebService and getServiceWSSoap() is #WebEndpoint
Here is the Stack trace
java.lang.NoClassDefFoundError: javax/xml/ws/Service
at package1.ProjectClient.getStub(ProjectClient.java:11)
at package.Project.<init>(Project.java:55)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.base/java.lang.Class.newInstance(Unknown Source)
at package.SubClass.getInstance(SubClass.java:1284)
at package.SubClass.getCall(SubClass.java:635)
at package.SubClass.execute(SubClass.java:317)
at package.MainClass.run(MainClass.java:1216)
at package.MainClass.execute(MainClass.java:759)
at package.ServerClass.b(ServerClass.java)
at package.ServerClass.run(ServerClass.java)
at java.base/java.lang.Thread.run(Unknown Source)
I have included jaxws-api dependency in my pom.xml, but still no luck
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
Research links:
1) Java Webservice Client (Best way)
2) https://mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/
3) https://mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/
You have included only API classes.
Your project needs also some Implementation classes (artifact).
One of possible implementations is jaxws-ri:
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.1</version>
</dependency>
Thanks for your response Volo Myhal. I have already included jaxws-rt dependency as well. But still I keep getting NoClassDefFoundError.
This issue is resolved after manually adding the required jars into our local server path from the .m2 folder
Hi I am currently building an eclipse plugin project and I need to write tests to test some package private classes however the tests need to be placed in a different plugin project which has the actual application plugin in its dependencies.
In order to access the package private classes I named the test package the same as the actual one. The issue is that if I run it as a JUnit plugin test i get an InvalidAccessException
java.lang.IllegalAccessError: tried to access class framework.resourcepack.datamodel.IResourceModel from class framework.resourcepack.datamodel.testCreateModel
at framework.resourcepack.datamodel.testCreateModel.testCreateLanguageModel(testCreateModel.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at ...
This runs fine if i run as a standard junit. I have checked all dependencies and they are fine. Any help would be much appreciated ;)
The most common way around this is to make your test bundle a Fragment rather than a Plugin and set its host plugin as the one containing the classes you are testing.
This will mean the fragment uses the host plugin's ClassLoader and so should have access to those classes.
I've been having troubles lately in creating a jar file that can call a secured web service on Weblogic server using Jdev.
I've created a web service proxy which is handling the situation perfectly. My goal is to deploy this web service as a jar file so that I can use it in my other projects as a simple library.
I was able to deploy the project as a jar file, which in turn allowed me to use it's different methods to connect to the web service.
However, when I run the web service client on eclipse I get an error:
Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/xml/crypto/wss/provider/CredentialProvider
at WebServiceCaller.callGetCardDetailJar(WebServiceCaller.java:55)
at WebServiceCaller.main(WebServiceCaller.java:29)
Caused by: java.lang.ClassNotFoundException: weblogic.xml.crypto.wss.provider.CredentialProvider
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
The problem may be fixed by finding the weblogic.jar file and including it in the eclipse build path, but is there a way to deploy a jar file with all the library dependencies included in it ?
There is a way to create a wlfullclient.jar (see oracle doc http://docs.oracle.com/cd/E13222_01/wls/docs103/client/jarbuilder.html ), but your class is not in it, it's rather in oracle.webservices.standalone.client.jar or in wls-api.jar or in weblogic.jar... it's rather confusing, I think Oracle never managed to simplify this jar dependency problem, actually in earlier versions of WebLogic things were a lot simpler!
After a lot of work migrating our code to another & fixing all the manifests and the bundles,
when I try to run the applet on the server I get many errors like this one:
java.lang.NoClassDefFoundError: org/jitsi/service/configuration/ConfigurationService
at net.java.sip.communicator.service.resources.AbstractResourcesService.<init>(AbstractResourcesService.java:127)
at net.java.sip.communicator.impl.resources.ResourceManagementServiceImpl.<init>(ResourceManagementServiceImpl.java:48)
at net.java.sip.communicator.impl.resources.ResourceManagementActivator.start(ResourceManagementActivator.java:36)
at org.apache.felix.framework.util.SecureAction$Actions.run(SecureAction.java:1243)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:620)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1904)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1822)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1192)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:266)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.jitsi.service.configuration.ConfigurationService not found by [12515]
at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:812)
at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:72)
at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1807)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.felix.framework.ModuleImpl.getClassByDelegation(ModuleImpl.java:670)
at org.apache.felix.framework.resolver.WireImpl.getClass(WireImpl.java:102)
at org.apache.felix.framework.ModuleImpl.searchImports(ModuleImpl.java:1426)
at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:747)
at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:72)
at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1807)
at java.lang.ClassLoader.loadClass(Unknown Source)
All the bundles are getting resolved properly, and even when I tried to get some code out of the external jar into our code, it still threw me that error, I know that's a problem in Felix that I need to fix, but I don't know where can I start, all the bundles starting in their proper time...
I'm building the app with ant/Felix.
Maybe it's a problem with the activator?
Thanks for all the help, love to hear some opinions...
Your bundle is using the class org.jitsi.service.configuration.ConfigurationService but it doesn't import the package. Make sure that org.jitsi.service.configuration is listed in the Import-Package header in your bundle's manifest.
I'm a .net dev, usually do this using nhibernate and can work with that fine. I'm doing a project which needs to be written in Java and have the following issue:
All I have so far is a blank java project setup in eclipse. I have C:\work\lib\java\cp\hibernate3.jar in the Referenced Libraries node in the package explorer.
in my code (main) i'm doing this
Configuration config = new Configuration().
setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect").
setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver").
setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:RefenceDb").
setProperty("hibernate.connection.username", "sa").
setProperty("hibernate.connection.password", "").
setProperty("hibernate.connection.pool_size", "1").
setProperty("hibernate.connection.autocommit", "true").
setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider").
setProperty("hibernate.hbm2ddl.auto", "create-drop").
setProperty("hibernate.show_sql", "true").
addClass(Boy.class);
and in the consol i have:
Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at ReferenceApplication.Main.main(Main.java:15)
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 1 more
any ideas?
the path C:\work\lib\java\cp\ is in the classpath
w://
While the other answers here referencing dom4j are correct, you will soon find there a dozen or so other dependencies.
Starting from total scratch is a noble pursuit, but I would actually recommend giving yourself a head start by installing Maven (for dependency management) and running mvn archetype:generate from the command line. If you're doing a web application (which you may not be based on the question text) selecting "maven-archetype-j2ee-simple" or "maven-archetype-webapp" would be a pretty good kickstart. Doing so will set up a project for you that can then be used in eclipse (you could even use m2eclipse plugin to do dependency management from within eclipse).
It will turn out that Maven has a learning curve of its own, but my opinion is that the benefits outweigh the costs.
Good luck!
Download dom4j and put it on your classpath (in the referenced libraries tab)
From the stack trace, it looks like you're missing dom4j.jar. Hibernate (for Java) has a ton of dependencies. Make sure that you have all of Hibernates required dependencies added to your Eclipse project.
You need to put the dom4j jar on your classpath. You should be able to get it here:
http://www.dom4j.org/download.html
I think that hibernate uses version 1.6.1
To make all this easier, I would quickly learn Maven and then use the m2eclipse plugin.
I know it's a learning curve, but it will make everything massively easier at deploy time.