|
|
|
Re: Add external Jar to Kura OSGI Bundle [message #1751512 is a reply to message #1751506] |
Wed, 11 January 2017 00:34 |
Tom Morocz Messages: 9 Registered: January 2017 |
Junior Member |
|
|
Hi Matteo,
I'm relatively new to working with Eclipse/Java/Kura. I thought perhaps we could go back to basics. I'm not sure the mongodb Jar files have been correctly added to the project. If we could get the following example working as a Kura Bundle it should help to resolve my issues.
I'm attempting to add a "mongo-java-driver-3.4.1.jar" to a hello world example. I have place the mongo.xx.jar in a root level "lib" folder and added the lib/*.JAR to the Build Path. There does not seem to be a reference to the JAR in the Manifest. Is this correct?
At the moment I have these errors when I create the JAR.
The code snippet is below along with the Manifest.
# 1/10/17 7:09:59 PM EST
# Eclipse Compiler for Java(TM) xx-201604081629-e45, 3.11.0, Copyright IBM Corp 2000, 2015. All rights reserved.
----------
1. ERROR in /Users/tommorocz/Documents/workspaceJanEE/kura/org.eclipse.kura.example.hello_osg1/src/org/eclipse/kura/example/hello_osg1/HelloOsgi.java (at line
import com.mongodb.MongoClient;
^^^^^^^^^^^
The import com.mongodb cannot be resolved
----------
2. ERROR in /Users/tommorocz/Documents/workspaceJanEE/kura/org.eclipse.kura.example.hello_osg1/src/org/eclipse/kura/example/hello_osg1/HelloOsgi.java (at line 26)
MongoClient client = new MongoClient("localhost", 27017);
^^^^^^^^^^^
MongoClient cannot be resolved to a type
----------
3. ERROR in /Users/tommorocz/Documents/workspaceJanEE/kura/org.eclipse.kura.example.hello_osg1/src/org/eclipse/kura/example/hello_osg1/HelloOsgi.java (at line 26)
MongoClient client = new MongoClient("localhost", 27017);
^^^^^^^^^^^
MongoClient cannot be resolved to a type
----------
3 problems (3 errors)
------------------
package org.eclipse.kura.example.hello_osg1;
//import java.util.logging.Logger;
import org.osgi.service.component.ComponentContext;
import org.slf4j.LoggerFactory;
import com.mongodb.MongoClient;
import org.slf4j.Logger;
public class HelloOsgi {
private static final Logger s_logger = LoggerFactory.getLogger(HelloOsgi.class);
private static final String APP_ID = "org.eclipse.kura.example.hello_osgi";
protected void activate(ComponentContext componentContext) {
s_logger.info("Bundle " + APP_ID + " has started!");
s_logger.debug(APP_ID + ": This is a debug message.");
MongoClient client = new MongoClient("localhost", 27017);
String connectPoint = client.getConnectPoint();
s_logger.info("Mongo has started!");
//System.out.println(connectPoint);
client.close();
}
protected void deactivate(ComponentContext componentContext) {
s_logger.info("Bundle " + APP_ID + " has stopped!");
}
}
-----------------
Manifest.mf
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Hellow World Examlple with Logger
Bundle-SymbolicName: org.eclipse.kura.example.hello_osg1
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: org.osgi.service.component;version="1.2.0",
org.slf4j
Service-Component: component.xml,
OSGI-INF/component.xml
Thanks,
Tom
|
|
|
|
|
|
|
|
|
|
Re: Add external Jar to Kura OSGI Bundle [message #1751986 is a reply to message #1751943] |
Tue, 17 January 2017 14:41 |
David Woodard Messages: 420 Registered: July 2014 |
Senior Member |
|
|
Hi Tom,
Let's take a step back.
Regarding the correct *.jar file to use, I was following this guide [1]. It appears you are using "Uber MongoDB Java Driver" or mongo-java-driver. While this may work by embedding in your bundle, I would recommend installing this bundle directly in the Kura framework since it is already an OSGi bundle. If you are intending to embed the jar in your bundle, I would use "MongoDB Driver" or "mongodb-driver". This is not an OSGi bundle, but rather a standard Java Jar file. I will try both of these options later in the week and let you know what I find.
All that said, is your application bundle working within Kura? Meaning, from within Kura, are you able to make a connection to MongoDB?
I am not sure what you mean by "In testing I have NOT been able to connect to ANY web resources from within Kura". To which resources are you referring? Are you trying to externally connect to the MongoDB instance? Are you trying to connect to your Kura application? If you are trying to connect to the MongoDB instance, you will need to open the appropriate ports in the Kura firewall [2].
As I said, I will try this later in the week and report back.
[1] http://mongodb.github.io/mongo-java-driver/3.0/driver/getting-started/installation-guide/
[2] https://docs.mongodb.com/manual/reference/default-mongodb-port/
Thanks,
--Dave
|
|
|
|
|
Re: Add external Jar to Kura OSGI Bundle [message #1752292 is a reply to message #1752275] |
Fri, 20 January 2017 16:39 |
David Woodard Messages: 420 Registered: July 2014 |
Senior Member |
|
|
Hi Tom,
1. The "mongo-java-driver" will not work by itself. I tried, but it itself depends on many other libraries. I guess this is why they recommend the "Uber Jar", so I would stick with this. One thing to note, a lot of the errors being generated are showing in /var/log/kura-console.log not /var/log/kura.log. Errors sent to standard out show in kura-console.log not kura.log. This may help in your long term debug efforts.
2. You cannot use "Import Existing Project..." because I did not include the .project file in my repo. You could try "Import File System", but this may cause other issues. I would just try and pull the pieces of my code you need to get your project working. My guess is you should only need the MANIFEST.MF "Import-Package" items. You do not need the example CAN project, that is separate and has nothing to do with this.
3. I am only using the CryptoService so I can make the password dynamic, if you have the password hard coded you don't need this. If you want to use this, you will need to bind the service [1].
3(a). Yes, this is likely the same problem. Let's get Mongo working first.
If you continue to have problems, please post the output of /var/log/kura-console.log.
[1] https://github.com/dwoodard1/kura_examples/blob/master/org.dwoodard.kura.example.mongodb/OSGI-INF/mongoDbExample.xml
Thanks,
--Dave
|
|
|
|
Powered by
FUDForum. Page generated in 0.04429 seconds