Not able to access classes in javamail in OSGi

I have an OSGi bundle and I'm using java mail api in it to add mail functionality.

The problem I'm facing is, the bundle class loader is not adding the entries for mail-1.4.jar and activation.jar in classpath variable which it creates while loading the local or global classes.

I've added the mail-1.4.jar and activation.jar in the bundle classpath in manifest and these jar are simple jars(not the OSGi bundles). And these are in lib directory in my bundle. Now while loading javax.mail.Address class ClassNotFoundException is thrown. And this is when I'm running my application using command line.

It works completely fine when I run it in Eclipse. I'm using equinox as my container. Any suggestions?

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Workexp
Bundle-SymbolicName: com.gslab.workexp
Bundle-Version: 1.0.0
Bundle-Activator: com.gslab.workexp.Activator
Bundle-Vendor: GSLAB
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.osgi.framework
Bundle-ClassPath: .,
 lib/mysql-connector-java-5.1.20-bin.jar,
 lib/commons-beanutils-1.8.0.jar,
 lib/commons-collections-2.1.1.jar,
 lib/commons-digester-2.1.jar,
 lib/commons-javaflow-20060411.jar,
 lib/commons-logging-1.1.1.jar,
 lib/iText-2.1.7.jar,
 lib/jasperreports-4.6.0.jar,
 lib/jdt-compiler-3.1.1.jar,
 lib/log4j-1.2.9.jar,
 lib/mail-1.4.jar,
 lib/activation.jar

Your use of the bundle classpath is unusual. You should use Import-Package (best practice) or Require-Bundle for dependencies. Bundle classpath is saying all those jars are packaged inside a lib folder inside your bundle archive. I suspect this isn't the case, and even if it was, you'd be totally bypassing all the modularity Eclipse gives you.

Try adding the 'javax.mail' package to your Import-Package header. For an explanation of why this isn't needed in Eclipse, see i/Why_does_Eclipse_find_javax.swing_but_not_Felix%3F.

链接地址: http://www.djcxy.com/p/74720.html

上一篇: tomcat osgi实现中的简单Web应用程序包(WAB)

下一篇: 无法访问OSGi中的javamail中的类