Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Need help wrapping third party to a bundle
icon4.gif  Need help wrapping third party to a bundle [message #1446322] Thu, 16 October 2014 17:35 Go to next message
nemewsys hellius is currently offline nemewsys helliusFriend
Messages: 1
Registered: October 2014
Junior Member
Hello!

I need to use these two packages in my code:
    import org.apache.commons.validator.routines.DomainValidator;

    import org.apache.commons.validator.routines.InetAddressValidator;


So I need to grab apache commons-validator 1.4.0 and make it a bundle.

For that I've created a new maven project, consisting only in one POM file, where the POM contains the following:

	<modelVersion>4.0.0</modelVersion>
	<groupId>apache-commons-validator-osgi</groupId>
	<artifactId>apache-commons-validator-osgi</artifactId>
	<version>1.4.0</version>

	<packaging>bundle</packaging>

	<name>${project.groupId} - ${project.artifactId}</name>

	<description>
	Demonstrates how to easily deploy the classes contained in a pre-packaged vanilla jar file into an OSGi
	container, when the jar does not contain the necessary OSGi manifest headers.
	</description>

	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.felix</groupId>
					<artifactId>maven-bundle-plugin</artifactId>
					<version>2.3.5</version>
					<extensions>true</extensions>
				</plugin>
			</plugins>
		</pluginManagement>
		<plugins>
			<plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<configuration>
					<instructions>
						<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
						<Embed-Directory>OSGI-INF/lib</Embed-Directory>
						<Embed-Transitive>true</Embed-Transitive>
						<_exportcontents>
							org.apache.commons.validator.*;version=${commons-validator.version}
						</_exportcontents>
					</instructions>
				</configuration>
			</plugin>
		</plugins>
	</build>

	<properties>
		<commons-validator.version>1.4.0</commons-validator.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>commons-validator</groupId>
			<artifactId>commons-validator</artifactId>
			<version>${commons-validator.version}</version>
		</dependency>
	</dependencies>



However, when I compile this project, the resulting bundle manifest will start importing new stuff... Check the Import-Package tag of the generated MANIFEST.MF here:

Manifest-Version: 1
Bnd-LastModified: 1413479060520
Build-Jdk: 1.6.0_65
Built-By: Pedro
Bundle-ClassPath: .,OSGI-INF/lib/commons-beanutils-1.8.3.jar,OSGI-INF/li
 b/commons-digester-1.8.jar,OSGI-INF/lib/commons-validator-1.4.0.jar,OSG
 I-INF/lib/commons-logging-1.1.1.jar
Bundle-Description: Demonstrates how to easily deploy the classes contai
 ned in a pre-packaged vanilla jar file into an OSGi	container, when the
  jar does not contain the necessary OSGi manifest headers.
Bundle-ManifestVersion: 2
Bundle-Name: apache-commons-validator-osgi - apache-commons-validator-os
 gi
Bundle-SymbolicName: apache-commons-validator-osgi
Bundle-Version: 1.4.0
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: *;scope=compile|runtime
Embed-Directory: OSGI-INF/lib
Embed-Transitive: true
Export-Package: org.apache.commons.validator.javascript;version="1.4.0",
 org.apache.commons.validator.util;uses:="org.apache.commons.validator";
 version="1.4.0",org.apache.commons.validator.routines.checkdigit;versio
 n="1.4.0",org.apache.commons.validator.resources;version="1.4.0",org.ap
 ache.commons.validator.routines;uses:="org.apache.commons.validator.rou
 tines.checkdigit";version="1.4.0",org.apache.commons.validator;uses:="o
 rg.apache.commons.validator.util,org.apache.commons.validator.routines,
 org.xml.sax";version="1.4.0"
Import-Package: javax.servlet,javax.xml.parsers,org.apache.avalon.framew
 ork.logger,org.apache.commons.collections.comparators,org.apache.common
 s.collections.keyvalue,org.apache.commons.collections.list,org.apache.c
 ommons.collections.set,org.apache.log,org.apache.log4j,org.w3c.dom,org.
 xml.sax,org.xml.sax.helpers
Tool: Bnd-1.43.0


I would expect it to import nothing and be self-contained... I hate this stuff when working with OSGi, including 3rd party dependencies is very hard Sad

How can I make this bundle self-contained?
Re: Need help wrapping third party to a bundle [message #1447155 is a reply to message #1446322] Fri, 17 October 2014 21:58 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
This isn't really a JDT question, but I'll give some comments anyway:

OSGi isn't any harder than Maven, it's crossing the border that can cause pain. But in both worlds, an artifact / bundle is seen as a module that may depend on other modules. Making a bundle into a self-contained, standalone blob isn't a normal approach in either world.

So ideally, you would find your 3rd party libraries in Eclipse Orbit, where they're already OSGi'ified and all their dependencies are, too. Unfortunately, nobody has yet created a Orbit version of commons-validator.

Perhaps you should first use maven to get the full list of (transitive) dependencies. From there you can make the call whether transforming all those is a viable option.

Stephan
Previous Topic:Hitting Breakpoints in Run -> Debug Configurations... -> Debug
Next Topic:[Kepler] exported packages don't show up for import in other plug-ins
Goto Forum:
  


Current Time: Mon Nov 23 16:46:37 GMT 2020

Powered by FUDForum. Page generated in 0.01998 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top