Application referencing library fails to find interface within another library - java

I have a strange problem and I cannot figure out regarding libraries and dependency.
I have an app called MyApp. Which calls a class called MyLib1Class1.
MyLib1Class1 implements MyLib2Interface and MyLib1Class calls MyLib2Class and passes the interface to it.
MyLib1... and MyLib2... are two separate library projects that are published to a local Maven repository.
MyLib1 has the dependency in the gradle file to MyLib2
MyApp has the dependency of MyLib1
The two libraries compile fine.
When I compile MyApp I get the error:
class file for MyLib2Interface not found
Note, that the app only reference MyLib1 and MyLib1 reference MyLib2 which contains the interface.
If I add the dependency of MyLib2 into MyApp it works but I don't want to have to do this, I want to be able to include the dependency of MyLib1 which automatically contains MyLib2 without needing to reference it again in the app.

Related

How we can get under development dependency in maven

I encounter an issue that, I have 3 projects porject_1,porject_2 and porject_3.
porject_1 contains one abstract class for example ClassDef.java, and porject_2 and porject_3 are implementing ClassDef.java in there code some where.
If ClassDef.java has added some new API in porject_1(under development means not released yet ) which should be verified by porject_2 & porject_3.
But in maven porject_2 & porject_3 need porject_1 dependency to get new implementation and we can not add porject_1 development jar into class path of porject_2 & porject_3 project in maven hence I can't take latest change in both dependent project at same time. how could I resolve this issue?

How to call a plugin method from another plugin in Eclipse?

I'm having the following situation:
I want to extend the functionality of a given plugin A (I have it's source code and start it by running the project as an Eclipse Application which opens a new Eclipse IDE which provides the plugins functionality) with an plugin B I am writing.
My plugin does run when I run it as a Java Application. Let's assume it just prints Hello World in the console. What I want is that I can call the function which does that from plugin A.
What I did:
I added my plugin B to plugin As Required Plugin-Ins.
I create an instance of the class which implements the Hello World-print and call the function inside a method of plugin A (I also tried to make the method static and call it without creating an instance which resulted in exactly the same errors).
I created an Extension Point in plugin B and added it as an Extension in plugin A. I just set the ID and name in the Extension Point.
What happens:
When the instance of the class in plugin B should be created, the program crashes with this error:
java.lang.NoClassDefFoundError: de/name_of/plugin_b/package/ClassName
[...]
Caused by: java.lang.ClassNotFoundException: de.name_of.plugin_b.package.ClassName cannot be found by de.name_of.plugin_a.package_1.0.0.qualifier
I guess I'm missing something imporant - can someone help me out on what it is?
Edit 2:
I've just read that I have to add "." to the classpath. Seems like this solved the issue! Thanks for making me dig deeper into the manifest, greg!
I do get a different error now tho, which also seems to be connected to me making mistakes when creating the plugin as I do not get this error when I run plugin B as a Java Application.
java.lang.NoSuchMethodError: org.apache.lucene.store.FSDirectory.open(Ljava/nio/file/Path;)Lorg/apache/lucene/store/FSDirectory;
The problem is, tho, that this method does exists (see lucene API here).
As seen in the manifest, I added the lucene-jars to the dependencies of plugin B.
You need to include every package that other plugins use in the Export-Package section of your plugin. In the MANIFEST.MF editor this is on the 'Runtime' tab in the 'Exported Packages' section.
You don't need an extension point to make this work.

Package-wise compilation with Maven?

I am new to Maven, we are converting ant based project into Maven project. Every thing is working fine. Additionally we need to compile source code package wise.
To be more clear, we have three packages in src/main/java folder, namely dao, svc and controller. I want to compile dao first and then compile svc by giving dao reference to it, similarly compile controller by giving reference of svc only but not dao.
Finally the goal is to make sure that the controllers are not using any of the dao classes, they can use svc classes only. If this condition fails, Maven build has to be failed.
Please suggest.
It sounds like you need a multi-module maven project. Create a parent project, whose task is simply to aggregate your three modules and to provide one thing to build. Create one module for each of your packages, then define dependencies between those modules in the individual POM files.
The Maven build system is clever enough to know in which order to build the modules, based on the dependencies you declare between them. In cases where you don't define a dependency (e.g. between controller and dao), the controller module cannot access classes in the dao module.
The final source layout will be something like:
your-project
your-project/pom.xml <--- parent POM
your-project/dao
your-project/dao/pom.xml
your-project/dao/src/main/...
your-project/svc
your-project/svc/pom.xml
your-project/svc/src/main/...
your-project/controller
your-project/controller/pom.xml
your-project/controller/src/main/...
To be more clear, we have three packages in src/main/java folder, namely dao, svc and controller. I want to compile dao first and then compile svc by giving dao reference to it, similarly compile controller by giving reference of svc only but not dao.
Judging by your requirements, I think more or less you need to setup a maven based Multi Module project. Take a look at these links
Link 1
Link 2

Java 6 runtime not overriding class called from within .jar dependency

I have a project with different classes and packages as dependencies. Note that everything writte below occurs in one project.
I have a class that at some point runs the code getDiagramPanel().setRelationsPaintOrder(new Comparator() {.
getDiagramPanel() calls the method from DjtSheet.class, which is located in a dependency .jar-file. This method returns the DjtDiagramPanel object. I also have a DjtDiagramPanel.java file, which should override the one from the package and contains the method setRelationsPaintOrder().
In Java 7, this works fine. It correctly calls the method from the dependency, which returns the object in the format of the class which overrides the panelclass from the dependency package.
In Java 6 however, the panelclass from the dependency package is returned instead of the one from my project.
java.lang.NoSuchMethodError:
com.dlsc.djt.gantt.DjtDiagramPanel.setRelationsPaintOrder(Ljava/util/Comparator;)V
Note that this message occurs at runtime! Compiling the project gives no errors.
How can I solve this?
This problem definitely means that you have a problem in class path. I guess that the problem is that class DjtDiagramPanel is duplicate and you have 2 different veraions: one that has method setRelationsPaintOrder and second that does not have. Apparently you compile code against the "good" version and run against the "bad" one.
When this happens you can probably change the order of class loading by playing with order of dependencies in project properties of eclipse, but it will just fail later (on production). So, you should find what is the root cause of the duplication.
First find these 2 versions of the same class. Then find how the bad version arrived to your classpath. It typically happes because of 3rd party dependencies. If you are using maven you can use dependency plugin to find the root cause and disable it using tag "exclusion".

Scala - class is broken

I am trying to build a project that has an external dependency on one of the jars. I have a Java version of the class that uses class X from the jar and that builds fine. As soon as I try to build taht using scala, I am getting an error that the "class X is broken" followed by NullPointerExcpetion. What might be the reason for it?
You have a broken dependency on your MANIFEST file. Add the dependency of that X class and try again.
This can happen if your external dependency itself depending on something external. This way builder can not make a whole class, so it is reporting you that class or jar is broken.

Categories

Resources