Resolve the NoClassDefFoundError of third-party packages in the OSGI Environment
Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
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:
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.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.