I have created an OSGi bundle and I want to add two external jar files to it called mediasenseplatform.jar and tinyos.jar So I added this line into my manifest file:
Bundle-ClassPAth:.,mediasenseplatform.jar,tinyos.jar
but it doesn't work and I don't see these files in my bundle jar file. How can I solve this problem?
OSGi doesn't make jar files, it is a platform for deploying and running them. If you want to include these jars in your bunde (which is just another jar) then you have to put them in there yourself.
There are build tools like maven which can do this for you.
You may also want to take a look at this related question.
Related
has any way to read a file inside on dependency?
For example, I have my pom.xml and I using the maven-antrun-plugin to copy the .war generated to my remote server, but i need to pass two attributes: keyfile and knowhosts, today, I have these files inside my project, in java/resources path, but i would like to know if has any way to wrapper these files in a .jar, and use this as dependency in my project, and read theses files from this dependency.
Thank very much!
I'm not sure if I understand your question correct so let's summarize your question how I understand it:
You have a project based on Maven and build a WAR file for deployment on an application server.
In your current situation you have two files in your projects resource folder that you read from/with your project code.
You want a situation that the two files are packed in a custom jar file and put that file as dependency on the classpath/in the pom file. The question is if you can still read them from your project code.
Yes, that's possible. If you add the dependency to the dependency list in the pom file the file will be also included in the war file and then available on the classpath of your application.
Only if your project jar is marked as sealed it won't work (Sealed jar files only can read classed from it's jar file and I think that is also not possible for resource files).
If this is also a good solution is more complex to answer and I can't answer that with the current limited info I have about your project.
Currently I'm working with osgi and karaf.
My problem is the no "osgi ready" dependencies , which means a jar that is not ready to be deployed as a bundle into karaf for example.
I tried two solutions in order to deal with this kind of problems :
I tried to to use "Embed-Dependency" which will include the jar
dependency with the project... I don't think this could be a solution
because when I try to embed the jar , it will ask me to include other
jars that the first jar depend on , and so on ..
I tried to convert the no "osgi ready" jars into bundles using bnd tool or from "Plug-in from Existing JAR Archive" from eclipse project.
And this led to the same result , each jar will call another jar that it depend on it..
I am not sure if I'm doing it the wrong way or what is the problem exactly.
Any tips how to deal with no osgi ready dependencies ?
The simplest way to start is to use the wrap: protocol to auto create a jar. Behind the scenes it uses bnd to create a bundle on the fly. Simply prepend wrap: to the mvn url of the jar.
When you try to install the jar using bundle:install -s wrap:mvn:... karaf will tell you which imported packages are missing. Install jars that provide these packages in the same way. The pom of the jar can give you a hint what is missing.
This can mean to install lots of jars if your initial jars has lots of dependencies.
Once you have a list of jars that are installable together you can either create a feature using wrap protocol or you can make bundles from the individual at build time.
In any case you should take a look are the servicemix bundles. It provides OSGi ready bundles for many libraries.
Is there a way we can load all the jar files inside a folder, as dependencies in a maven project.
So that, I do not have to mention each and every jar files in pom.xml, just mention or tell maven to pick all the jar files from folder 'x' and build the system.
Is this supported by maven?
I think this is supported by ant. Not sure whether gradle supports either.
In
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies
you see that you can reference single files, but there is no mechanism for directories. As I mentioned in the comment, using the disk is discouraged in general.
If you need the same set of dependencies in many projects, you can write a pom for that and use it (as parent or by setting a dependency to it).
ActiveMq v 5.10.1
I downloaded ActiveMq.
Went to its lib folder.
Selected and unzipped
activemq-web-5.10.1 and
activemq-kahadb-store-5.10.1
jars.
Went inside the respective META-INF folders and noticed this file named as DEPENDENCIES.
What is this DEPENDENCIES file ?
It seems related to dependency Management.
What does it do?
After searching with various different keywords, I was eventually able to figure out what is this DEPENDENCIES file.
It comes from Apache-Resource-Bundle. See Here http://maven.apache.org/apache-resource-bundles/
It is basically a way to ensure that any jar created by Apache is having some standard. For example, it includes License, Disclaimers.
The DEPENDENCIES file simple is a list of Dependencies on which the jar depends in pretty format.
It is not at all involved in dependency management. It is simply of packaging purposes.
Developing on the Mac with IntelliJ 9.0.2 Community Edition.
I have a program which depends on two library jars. I have figured out how to get IntelliJ to make me a jar of my source (with the Artifact tab), and even to include the two jars in it.
However, if I get a listing of the jar file it produces, it looks like this:
com/acme/MyClass1.class
com/acme/MyClass2.class
...
mylib1.jar
myLib2.jar
And, no surprises, if I double-click the jar file, it gets a NoClassDefFoundError the first time it tries to access a class in one or other library jar.
It seems I need to tell IntelliJ to "inline" the library jars -- but this menu option is always greyed out!
Does anyone have any idea how to get jars inlined in a jar artifact?
IDEA doesn't support it yet, you can use Ant integration to package your jar (either by unpacking all the jars into the temp folder and then packaging the project output plus this temp folder into the single jar or by using some Ant task like jarjar).
If you want this feature to appear in the future IDEA versions, please vote for the request.
Having the dependency JARs included in your JAR should allow yoru code to run successfully. You probably don't have the JARs on your classpath.
I will use Maven Assembly plugin. Its simple and will give you a neat little jar file..