Accessing classes within a jar placed in a dependent plugin - maven

I have the following usecase. I have added a jar file(generated out of maven) as an external jar in the bundle path of a plugin (say Plugin A).
I have exposed all the packages inside this jar in Plugin A.
Now Plugin A is added as a dependency to Plugin B.
But in Plugin B, I am not able to access the classes inside the jar file which is added as an external jar to Plugin A and whose packages are exposed
Is it advisable to the same jar in every plugin ? Please pour in your suggestions.

I resolved this issue . In eclipse there is an option to generate a plugin from JAR file.So I have created a plugin from the jar file and added it as dependency to other plugin(after exposing the packages in the generated plugin).

Related

How does a jar pull transitive dependencies in Maven?

I am buliding small Spring Boot app - pacakged as jar file (I'm using maven plugins).
I know that there are solutions which allow me to build jar file with all desired dependecies (e.g. maven assembly plugin).
The question is what if I don't pack maven required depedencies using those solutions? Am I correct that I will always get "NoClassDefFoundError" ? So should I always pack my project with all depedencies into jar file or there is another solution to "makes thigns work"?

Include the bytecode of a JAR file in a gradle library vs. just adding it as a dependency

If I add a JAR file to a gradle project's depenencies, the code compiles just fine, but after publishing to maven (publishToMavenLocal), the classes from the JAR are not found.
Obviously, this is because the jar is added as a "dependency" and not part of the project itself. Is there a way to get the contents of the JAR file to merge into the library? Do I need to make a separate maven repo for each JAR?
You can always try to create a fat jar which includes dependencies. You can follow the instructions provided here https://www.baeldung.com/gradle-fat-jar

In maven how to create jar where lib is outside?

How do I configure my pom.xml so that maven generates a jar where the lib folder and all it's jars are a separate folder outside of my generated jar?
What you need here is to use :
Maven Jar Plugin to copy your generated jar to a different location you want.
Maven Dependency Plugin to copy your dependent jars to a location that you want.
You need to use the outputDirectory property in both the plugins to define the required location where you would like the jars to be copied to, respectively.
Here is an example of the configuration you would add in your POM.

Add non-osgi jars to RCP4 project

I am building an RCP4 application.
I have two non-osgi jars called a.jar and b.jar. Both jars have tons of non-osgi dependencies. One of the dependencies of a.jar is b.jar. So the hierarchy looks like this:
My application
|--a.jar
|----aDependency1.jar
|----aDependency2.jar
|----aDependencyN.jar
|----b.jar
|------bDependency1.jar
|------bDependency2.jar
|------bDependencyN.jar
Some of the bDependencyN.jars are different versions of the aDependencyN.jars
(An example is commons-logging-1.0.4.jar vs commons-logging-1.1.2.jar)
I need to directly reference a.jar and b.jar from my RCP4 application. In other words, when I write code, I will import packages from a.jar and b.jar)
Which is the best approach:
Use bnd 2.4 via command-line to turn all non-osgi jars into osgi ones. I then add every jar to my project via target file
Create a new project "Plug-in from existing JAR archives", and select a.jar and all of its dependencies and export it as a "deployable plugin and fragment" called a.with.libs.jar. I do the same with b.jar and create b.with.libs.jar. I then add those 2 new jars to my project via target file
Create a new project "Plug-in from existing JAR archives", and select a.jar and all of its dependencies, and b.jar and all of its dependencies and export it as a "deployable plugin and fragment" called ab.with.libs.jar. I then add the new jar to my project via target file
Is there a better approach than the suggestions above?
One option is to use bnd-platform (I am also the author) to manage third party dependencies and create OSGi bundles from them. You can use it with both dependencies retrieved from Maven repositories and local Jars (see the README). When you configure a Maven dependency it will also include the transitive dependencies. Under the hood it uses bnd. If needed you can also customize how the Jars are wrapped. bnd-platform is a plugin for Gradle, you can easily start with this template - just add your dependencies and provide the configuration as described in the project README (bundle symbolic names, versions) and run gradlew bundles. The created bundles can then be added to the target platform. You can also use bnd-platform to build a p2 repository / update site.

How to add a plugin as a jar to a grails project

I created a custom plugin 'myPlugin' for GRAILS. I compiled and installed it as a binary (my-plugin-0.1.jar) file.
The jar file can't be found by grails in a "normal" project, because it only looks for my-plugin-0.1.zip (the plugin is defined within the plugins-block in BuildConfig.groovy)
How can i add the .jar file as a plugin?
Binary plugins packaged as jar has to be referred in the dependencies section instead of the plugins section in BuildConfig
dependencies {
compile "mygroup:myplugin:0.1"
}
or you can put the jar in application's lib directory which I would discourage. :)
Add it in the dependencies block (not plugins) in BuildConfig.groovy.
Publish plugin installs the jar into local maven cache (/.m2). Verify the existence of the jar in .m2.
Also verify if the application using the plugin has mavenLocal enabled in repositories' buildConfig.

Resources