Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » How to import external .jar and use it in a bundle
How to import external .jar and use it in a bundle [message #1709204] Thu, 24 September 2015 21:06 Go to next message
Silvio Tavilla is currently offline Silvio TavillaFriend
Messages: 7
Registered: September 2015
Junior Member
Hi all,
I would like to import an external .jar in my bundle and use it through Java code.
Any help about it??

Thanks in advance!!
Re: How to import external .jar and use it in a bundle [message #1709208 is a reply to message #1709204] Thu, 24 September 2015 23:19 Go to previous messageGo to next message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

Hi Silvio,

There are two ways by which you can achieve this.

1. Convert the non-osgi jar to bundle. You have to use bndtools or eclipse to do so. Once you are done converting your jar to bundle, import the required packages in your own bundle. Create your own bundle which uses those exported packages from the newly created bundle. Then in the OSGi container, install the first OSGi bundle and then your own bundle.

2. Another way is to put the jar in your own bundle and create manifest header mentioning Bundle-Classpath: lib/*.jar (assuming your bundle has a lib folder and it has the jar file). It will work as well.

Thanks and Regards,


Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com
Re: How to import external .jar and use it in a bundle [message #1709217 is a reply to message #1709208] Fri, 25 September 2015 02:40 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello Silvio,

If you use option two suggested by Amit, you can see an example in the web bundle manifest [1]. The jar of note is gxt-2.2.5.jar near the bottom of the file.

[1] https://github.com/eclipse/kura/blob/develop/kura/org.eclipse.kura.web/META-INF/MANIFEST.MF

Thanks,
--Dave
Re: How to import external .jar and use it in a bundle [message #1709288 is a reply to message #1709217] Fri, 25 September 2015 16:07 Go to previous messageGo to next message
Silvio Tavilla is currently offline Silvio TavillaFriend
Messages: 7
Registered: September 2015
Junior Member
Thanks for your answers!

I have used the Amit's option "two" and I have inserted the path of the jar files (about org.apache.httpclient) in bundle's MANIFEST.
During the writing of Java code I haven't any problem, but when I have installed the bundle in Kura, I have had a series of error.

I attach kura-console.log's output about it.

Thanks for your help!
Re: How to import external .jar and use it in a bundle [message #1709292 is a reply to message #1709288] Fri, 25 September 2015 16:27 Go to previous messageGo to next message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

Hi Silvio,

I think something went wrong with your OSGi Container and that's why the framework couldn't find the some of the bundles. Would you please check if this does happen only when you try to install your own bundle or it stays same even when you don't install your bundle. If it is happening due to your bundle, I would advise you to host your source code either in Bitbucket or Github so that we can try solving your issue.

Thanks and Regards,


Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com
Re: How to import external .jar and use it in a bundle [message #1709294 is a reply to message #1709292] Fri, 25 September 2015 16:35 Go to previous messageGo to next message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

Hi Silvio,

I think this is happening due to your bundle as it has missing links to the libraries you have included in the Bundle-Classpath. Make sure to include your library folder in the Binary Build of your bundle.

http://s29.postimg.org/r5f8m4zeb/Screen_Shot_2015_09_25_at_10_02_18_pm.jpg


Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com
Re: How to import external .jar and use it in a bundle [message #1709304 is a reply to message #1709217] Fri, 25 September 2015 19:49 Go to previous messageGo to next message
Silvio Tavilla is currently offline Silvio TavillaFriend
Messages: 7
Registered: September 2015
Junior Member
Hi Amit,
Thank you!

Yes, I have controlled it and it looks setted correctly.

Next days, I will try to create a new bundle and repeat jar importing.

Maybe, has anyone ever had problems importing org.apache.httpClient libraries (http-client, http-core)???

Thanks and Regards
Re: How to import external .jar and use it in a bundle [message #1709321 is a reply to message #1709304] Sat, 26 September 2015 07:10 Go to previous messageGo to next message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

Hi Silvio,

As Apache HttpClient Libraries are not provided as OSGi Bundles, you either have to convert it to OSGi Bundle or put it in Bundle Classpath using Bundle-Classpath manifest header. There should not be any problem if you put it in Bundle's Classpath as it is same for any non-osgi library to be used in any Bundle's Classpath. If you still encounter any problem, you can host your bundle somewhere so that we can have a look together to find the issue.

Thanks and Regards,


Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com
Re: How to import external .jar and use it in a bundle [message #1709327 is a reply to message #1709321] Sat, 26 September 2015 12:54 Go to previous messageGo to next message
Lorenzo Carnevale is currently offline Lorenzo CarnevaleFriend
Messages: 3
Registered: September 2015
Location: Messina
Junior Member
Amit Kumar Mondal wrote on Sat, 26 September 2015 07:10
As Apache HttpClient Libraries are not provided as OSGi Bundle


Hi at all,

I would follow this topic because I have a question on external package import.
Like you said, some jar package, as httpclient or httpcore in this case, are not part of the framework kura. Maybe, cause of this issue is the absence of it into plugins' target platform? If so, I can add external jar to target platform?


Lorenzo Carnevale

email: lorenzocarnevale@gmail.com
Re: How to import external .jar and use it in a bundle [message #1709341 is a reply to message #1709327] Sun, 27 September 2015 03:08 Go to previous messageGo to next message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

Hi Lorenzo,

If you want to add a Non-OSGi library to your Eclipse Target Platform, you have to convert the Non-OSGi library to OSGi Bundle first and then you can put it in the dropins or plugins folder in Eclipse Installation Directory. Make sure to restart the IDE after you put the library in the respective folder. After the restart you would be able to use its exported packages.

Apart from it, you can manually create a folder anywhere and put the respective OSGi Library inside the folder and then you can add that directory to your target platform from Eclipse Preferences Dialog.

I would advise you to put the Non-OSGi Library in a specific folder inside your Bundle and put it in the Bundle Classpath. This will make your eclipse installation lightweight.

Thanks and Regards,


Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com
Re: How to import external .jar and use it in a bundle [message #1709751 is a reply to message #1709341] Wed, 30 September 2015 17:03 Go to previous messageGo to next message
joseph muscolino is currently offline joseph muscolinoFriend
Messages: 11
Registered: July 2015
Junior Member
Hi to all.

I'd like to add to this discussion bacause i ran into a similar trouble. i've followed the first advice of Amit and i tried to add more external jars building a new bundle (org.eclipse.kura.lib_HTTP) and adding it to the main bundle (org.eclipse.kura.example.clientFIX). I'm trying to do a simple Http request.
I hope to help you to understand better by posting my screens.
Any advice?

Thanks in advance.

[Updated on: Thu, 01 October 2015 14:20]

Report message to a moderator

Re: How to import external .jar and use it in a bundle [message #1709784 is a reply to message #1709751] Thu, 01 October 2015 06:13 Go to previous messageGo to next message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

Hi Joseph,

As you have already provided all necessary source code, I can see that in your build.properties file there are two warnings. I would advise you to correct them first. Secondly, the exception says that your HTTP Consumer Bundle can't be resolved as it has a missing dependency. It can't find org.apache.http package as it has to import this package to resolve consumer bundle. You have to install the bundle to your OSGi container which exposes the respective package (org.apache.http). After you install the bundle, start it so that your consumer bundle can import its relevant packages for resolution.

N.B: If you have already installed the apache http bundle, make sure it's started. Sometimes you can even confront that dependency bundles are not even started as those might need other dependencies for resolution. In such scenario, you have to install those needed dependencies as well.

Thanks and Regards,


Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com

[Updated on: Thu, 01 October 2015 06:16]

Report message to a moderator

Re: How to import external .jar and use it in a bundle [message #1709866 is a reply to message #1709784] Thu, 01 October 2015 14:47 Go to previous messageGo to next message
joseph muscolino is currently offline joseph muscolinoFriend
Messages: 11
Registered: July 2015
Junior Member
Thanks Amit.
I was able to solve the problem. I wonder if is normal the fact that each time i add a new jar in my bundle, then kura needs to be restarted to take the new library. Actually now i have a new problem: when i launch my main bundle into Eclipse it works well, instead when it runs on Kura it seems to not reach the outside, by giving me an IOException. Both DNS and search domain of the target device look like well setted.
Any advice?

Thanks!
Re: How to import external .jar and use it in a bundle [message #1709876 is a reply to message #1709866] Thu, 01 October 2015 16:34 Go to previous messageGo to next message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

Hi Joseph,

It would be helpful if you can share the screenshot of the exception stack trace.

Thanks and Regards,


Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com

[Updated on: Thu, 01 October 2015 16:35]

Report message to a moderator

Re: How to import external .jar and use it in a bundle [message #1710008 is a reply to message #1709876] Fri, 02 October 2015 15:29 Go to previous messageGo to next message
joseph muscolino is currently offline joseph muscolinoFriend
Messages: 11
Registered: July 2015
Junior Member
Hi Amit.
I solved the IO problem. It was an error on the access point properties. Nevertheless i still don't understand why when i install 2 bundles, one dependent on the other, if i try to update one of these, changes made don't seem work until i restart Kura. Moreover, i noticed each time i restart, processes' pid increase them value.
Is it normal? Is possible to mantain the value of a pid, even after a restart?

Thanks in advance.
Regards.
Re: How to import external .jar and use it in a bundle [message #1710128 is a reply to message #1710008] Sun, 04 October 2015 20:08 Go to previous messageGo to next message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

Hi Joseph,

Basically you have two ways to update your bundles.

1. You can use Kura's OSGi console to update the modified bundles
2. You can use Kura WebConsole to update the deployment package which comprises the modified bundles

For both the scenarios, you don't need to restart Kura and your changes should be reflected as well.

I am not sure what exactly happened to your Kura Installation which caused such trouble.

Thanks and Regards,


Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com
Re: How to import external .jar and use it in a bundle [message #1710249 is a reply to message #1710008] Mon, 05 October 2015 14:03 Go to previous messageGo to next message
Alessandro Da Rugna is currently offline Alessandro Da RugnaFriend
Messages: 43
Registered: December 2014
Member
joseph muscolino wrote on Fri, 02 October 2015 17:29
Nevertheless i still don't understand why when i install 2 bundles, one dependent on the other, if i try to update one of these, changes made don't seem work until i restart Kura.

Do updated bundles have a different version number? If number stays the same, probably OSGi does not unload/reload the classes.


My project: Kura web log level changer https://github.com/darugnaa/kura-web-log
My blog: http://darugnaa.github.io
Re: How to import external .jar and use it in a bundle [message #1731340 is a reply to message #1710249] Wed, 04 May 2016 12:46 Go to previous messageGo to next message
David Nguyen is currently offline David NguyenFriend
Messages: 13
Registered: March 2016
Junior Member
Hi everyone,

I also have a problem when I want to use an external jar file.

I need to use "paho-mqtt-client-1.0.1.jar" to connect and work on mqtt protocol.
Here, I don't use exist mqtt class of Kura because I need more features.
After read and do completely following second Instrucion of Amit Kumar MondalFriend(edit MANIFEST.MF), My code isn't still working.
My client still not connect to mqtt broker.
There is my sample code:

protected void activate(ComponentContext componentContext) {

        s_logger.info("Bundle " + APP_ID + " has started!");

        s_logger.debug(APP_ID + ": This is a debug message.");
        ......................................................................
		String broker="tcp://192.168.40.152:1883";
		s_logger.info(broker);
		
		option = new MqttConnectOptions();
		option.setUserName("test");
		option.setPassword("12345".toCharArray());
        String clientId     = "JavaSample";
		s_logger.info(clientId);

        MemoryPersistence persistence = new MemoryPersistence();
		s_logger.info("persistence");

		try {
			s_logger.info("try1");
			try {
				s_logger.info("try2");

	            MqttClient sampleClient = new MqttClient(broker, clientId, persistence);
	            s_logger.info("try3");
	            MqttConnectOptions connOpts = new MqttConnectOptions();
	            s_logger.info("try4");
	            connOpts.setCleanSession(true);
	            s_logger.info("try5");
	            s_logger.info("Connecting to broker: "+broker);
	            s_logger.info("try6");
	            sampleClient.connect(connOpts);
	            s_logger.info("try6");
				s_logger.info("Connected to " 
						+ broker + " with clientID " + clientR.getClientId());
				
			} catch (MqttException e) {
				// TODO Auto-generated catch block
				s_logger.info(">>>>>>>>>>>>>>>Error");
				e.printStackTrace();
			}

			
		} catch (Exception e) {
			s_logger.info(">>>>>>>>>>>>>>>Error");

			// TODO: handle exception
		}


And console log just show to "try 2".
It means what happen when I create a new MqttClient which belong to "paho-mqtt-client-1.0.1.jar".
Please help me review and fix this issue.
Thank a lot.
Re: How to import external .jar and use it in a bundle [message #1731365 is a reply to message #1731340] Wed, 04 May 2016 16:13 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

The majority of Paho features are exposed through Kura, I would be interested in what features you need that Kura isn't providing.

Can you please login to the OSGi console and provide the output of 'ss' and 'ls'.

Thanks,
--Dave
Re: How to import external .jar and use it in a bundle [message #1731415 is a reply to message #1731365] Thu, 05 May 2016 04:42 Go to previous messageGo to next message
David Nguyen is currently offline David NguyenFriend
Messages: 13
Registered: March 2016
Junior Member
Thank David for your reply.
I know Kura has exist paho mqtt through DataService class.
But I don't want to touch deeply to Kura Core.
I just want to write some simple API for my private purpose.
It the reason that I want to call and use independently "paho mqtt".

I also try to use "org.eclipse.paho.client.mqttv3_1.0.1.jar" from "../kura-KURA_1.4.0_RELEASE/kura/target-definition/common/repository/plugins".
But it still not effect.
Please review the output od "ss" & "ls" from my attached file.

Thank a lot.
p/s: My bundle's name is org.eclipse.kura.example.hello_Osgi

David Woodard wrote on Wed, 04 May 2016 16:13
Hello,

The majority of Paho features are exposed through Kura, I would be interested in what features you need that Kura isn't providing.

Can you please login to the OSGi console and provide the output of 'ss' and 'ls'.

Thanks,
--Dave

  • Attachment: ls.png
    (Size: 109.69KB, Downloaded 571 times)
  • Attachment: ss.png
    (Size: 135.05KB, Downloaded 366 times)
Re: How to import external .jar and use it in a bundle [message #1731561 is a reply to message #1731415] Fri, 06 May 2016 19:10 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

The service you are trying to register is unsatisfied (output of ls command). From the OSGi console, please provide the output of 'comp 37'. Also, can you please post your bundles MANIFEST.MF file?

--Dave
Re: How to import external .jar and use it in a bundle [message #1748347 is a reply to message #1709204] Tue, 22 November 2016 11:53 Go to previous messageGo to next message
Patrick Frick is currently offline Patrick FrickFriend
Messages: 2
Registered: November 2016
Junior Member
Hello to all,

I got nearly the same problem. I try to insert some external jars to my bundle for connecting to the Microsoft Azure AD.
I added all my external jars to the Bundle Classpath.
When the bundle gets started the error in the txt file appears.

I hope someone can help me. I added the Manifest and my packages I want to insert.

Best Regards
Patrick
Re: How to import external .jar and use it in a bundle [message #1748394 is a reply to message #1748347] Tue, 22 November 2016 17:29 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hi Patrick,

I don't think the issue is related to your included JARs, the error I am seeing is that the bundle loader cannot find your class:

java.lang.ClassNotFoundException: com.stihl.example.cloudClient.Client


Can you please post the contents of your component XML file?

Thanks,
--Dave
Re: How to import external .jar and use it in a bundle [message #1748719 is a reply to message #1748394] Sun, 27 November 2016 19:52 Go to previous messageGo to next message
Abel Gr is currently offline Abel GrFriend
Messages: 13
Registered: January 2016
Junior Member
Hi David & all,

I also have near problems as Patric.

I try to integrate Kura to Azure IoT Hub.

I inserted all external jar lib folder and add "Bundle-ClassPath" to Manefist.

But I have reached this problem:

 No instances were created because: Can not activate instance of component org.kura.microsoft.simulatedevicesecond.Simulatedevicesecond. The activation throws: java.lang.NoClassDefFoundError: javax/crypto/spec/SecretKeySpec


I try to find and realized that javax/crypto/spec/SecretKeySpec is a class in jce.jar (existed in java jdk).

So i don't know how to fix this error.Please help me

Thanks,

Abel
  • Attachment: comp_error.PNG
    (Size: 33.06KB, Downloaded 276 times)
  • Attachment: bundles.PNG
    (Size: 51.89KB, Downloaded 363 times)
  • Attachment: Manifest.PNG
    (Size: 19.55KB, Downloaded 286 times)
  • Attachment: component.PNG
    (Size: 7.47KB, Downloaded 310 times)

[Updated on: Mon, 28 November 2016 03:59]

Report message to a moderator

Re: How to import external .jar and use it in a bundle [message #1748814 is a reply to message #1748719] Tue, 29 November 2016 02:59 Go to previous messageGo to next message
Abel Gr is currently offline Abel GrFriend
Messages: 13
Registered: January 2016
Junior Member
Does any one have any idea to help me?

Please let me know,direction or something useful.

Thanks
Re: How to import external .jar and use it in a bundle [message #1748890 is a reply to message #1748814] Tue, 29 November 2016 19:39 Go to previous message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

I believe you need to add javax.crypto.spec to your MANIFEST.MF import list.

Thanks,
--Dave
Previous Topic:Does KURA supports lwm2m protocol?
Next Topic:Setting Up Kura and Wifi on RPi 3 Model B
Goto Forum:
  


Current Time: Fri Apr 26 09:10:20 GMT 2024

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

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

Back to the top