I have a android A.jar file deployed at system path.
/product/framework/A.jar
it has dependency to B.jar. but looks like if use A.jar as dependency in D project, it will expose B.jar file to D as well.
D project use A.jar and B.jar as below:
complieOnly A.jar
implementation B.jar
I found this since when I add B.jar to D as dependency, it actually use the version from A.jar file.
That's very weird since the version of B.jar maybe different, how to prevent A.jar expose it's dependency?
Related
I have intelliJ project A that has an imported external jar file (made from project B, jar file and gradle setup made by some other dev) that looks like this:
I want to replace that jar with a different jar I made from project B (where I modified some code).
Project B's main module looks like this:
Then when I make a jar file for it selecting main as the module (I don't select a class):
And import the jar into project A, it comes out like this with a lot more folders than just the com:
I'm guessing this is because Project B has a lot of other dependencies that it depends on so when it makes that jar file it needs to include those other folders for it to rely on. The thing is, a lot of those dependencies are included in project A. Does anyone know how to make it so the jar file only looks like the first picture posted at the top and it depends on the other dependencies already included in project A?
A JAR file is in reality just a different name for a ZIP file (plus an optional manifest file). All you need to do is put your .class files from Project B in a zip file (in the right directory/ies) and then change the extension to .jar
I am preparing for a Java 11 certification exam and I still do not fully understand the new Java modules system: A training question gives a situation like the following:
In my app I have 2 jars, say A.jar and B.jar, where A.jar uses B.jar, but B.jar does not use A.jar.
Further, B.jar is modularized, while A.jar is not.
Now it sais, that if I try to run it like this:
java -classpath A.jar --module-path B.jar com.AMainClass
with a main class from A.jar, then it will fail to run - but why? For what I understood, when I put a non-modularized jar on the classpath, it becomes part of the "unnamed module", which should be able to see all the modules on the module path. So shouldn´t I be able to see the required dependencies from B.jar, when I run the main class from A.jar? Where is my misunderstanding?
It further sais, that it will work, if I put both jars on the module path and run the module instead of running the class:
java --module-path A.jar;B.jar --module A/com.AMainClass
Now A.jar, being on the module path, will become an automatic module and will also see the other module - ok, this is fine. But what is the difference between running a module and running a class? Why doesn´t it work when I try to run the class (as above) and what changes, when I run the module?
Today I found that after I delete a pom file like a.pom and leave an a.jar file exist, Mvn install can still success. but the result jar lost some dependency descriped in a.pom . So I wonder what's the releastionship between a.jar and a.pom file? Is every maven module after installing has an a.jar and a.pom file ?
also I found that there already an a.pom file inside a.jar ,why there still an a.pom file outside a.jar. what's the difference?
Cause I am new to maven , maybe there is something basic knowledge in maven I dont know.
thanks for answering.
I'll try to boil my issue down into a basic external JAR linking question, which I have not been able to find an example/answer for. I have 2 JARs, a.jar and b.jar, in the same directory. The MANIFEST.MF of a.jar contains: Class-Path: b.jar.
Essentially, I want to run a.jar that contains minimal application-level classes, but links to a large external b.jar with all other necessary classes. But running the command java -jar a.jar results in: Exception in thread "main" java.lang.NoClassDefFoundError: com/example/MainApp.
Not sure if it's relevant, but b.jar is actually a Spring Boot JAR which contains the expected classes (e.g. com/example/MainApp.class) in BOOT-INF/classes. The MANIFEST.MF of b.jar contains: Spring-Boot-Classes: BOOT-INF/classes/.
I want to know if there's a simple way to achieve this? Let me know if any more details are needed to diagnose the issue.
Update:
I copied the com/example/MainApp.class file to the base directory in b.jar, and the class was found! But I want to keep the original files in place. So I suppose that rephrases the question: how do you specify where classes are located inside the JAR?
did you try something like that path like "classpath: path/to/jar/b.jar"
I have two maven web application, let's say ProjectA and ProjectB which are packed as WAR files. Both applications are using third maven application ProjectC which contains some shared classes. I added ProjectC as dependency in ProjectA and ProjectB.
ProjectA and ProjectB are running in Eclipse using maven jetty plugin, but in production it is deployed as WAR files to the Tomcat web server.
This approach used to work fine until the moment I started to share some hibernate entities. Due to the problem I described in this question, jar-file from persistence.xml is not found in eclipse, it's not possible to link persistence.xml with entities in ProjectC.jar so I have to find some alternative solution.
I thought that it would work if I could compile ProjectC classes when ProjectA and ProjectB are compiled, so the structure looks like:
projectA
-WEB-INF
-classes
-project-a.classes
-project-c.classes
projectB
-WEB-INF
-classes
-project-b.classes
-project-c.classes
rather then:
projectA
-WEB-INF
-classes
-project-a.classes
-lib
-project-c.jar
projectB
-WEB-INF
-classes
-project-b.classes
-lib
-project-c.jar
I don't know if this is possible to do with maven multimodule approach, but some other ideas which will solve the problem are also welcome.
Thanks,
Follow this link to know a way you could use to unpack the resources of some third Project (like your Project C) into another project as resources. It is a excellent and simple guide.
You can take the idea to include the entities as classes of you projects A and B, but it will be easier put the persistence.xml and other common files in a new project and keep the java classes (your entities) into separate jar projects.
Try to set addClasspath=true in war manifest and package your war classes to jar with archiveClasses.
You'll have war structure like this
projectA
-WEB-INF
-lib
-project-a.jar
-project-c.jar