Resolve the NoClassDefFoundError of third-party packages in the OSGI Environment

Source: Internet
Author: User
Solve the NoClassDefFoundError of third-party packages in the OSGI environment-Linux general technology-Linux programming and kernel information. The following is a detailed description. I finally fixed this problem and made a conclusion:

1. Transform the class file of a third-party package into a bundle and export all packages.

2. Use equinox of eclipse to start all bundle

3. In the eclipse environment, the startup is normal, but it fails to be started on the command line (both windows and linux), that is, the following error occurs:

Exception in thread 'thread-1' java. lang. NoClassDefFoundError: javax/naming/NamingException
At java. lang. Class. forName0 (Native Method)
At java. lang. Class. forName (Class. java: 169)
At com. ibatis. sqlmap. engine. builder. xml. SqlMapConfigParser. class $ (SqlMapConfigParser. java

4. After comparing the running environments, we found that the key difference is that java. syspath and osgi launcher are different, but they cannot be changed.

5. After searching by javaeye and osgi china groups, I found a foreign post (Share it with me ):

Option 1: "DynamicImport-Package: *" to the manifest of your bundle. This is one possible pure OSGi solution and shocould do what you want.

Option 2: If you are using Equinox as OSGi implementation you coshould also take a look at the Buddy-Loading Mechanic:
Http://help.eclipse.org/help33/t.../buddy_loading.html

6. Solution Summary: load other classes in the class of the third-party package, and these classes are not in the current bundle. This exception may occur as long as they are in the Manifest. add the mf file to DynamicImport-Package: *, or use the buddy loading Mechanism of eclipse (which has not been tested yet) to solve the problem.

In short, osgi has many advantages, but its disadvantages (inconvenient) are also obvious, that is, the classpath (classloader) mechanism. Because of this, I gave up spring. However, spring + osgi is the trend of the times. The DI of the two is very similar. osgi ds is used very much like spring configuration files. Wait for time to study the combination of the two.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.