P
P
Pavel Sokolov2021-05-30 22:44:53
Java
Pavel Sokolov, 2021-05-30 22:44:53

How to import project1.jar into project2.jar?

project1.jar and project2.jar can be anywhere (only their location is known). How to import classes from project1.jar into project2.jar? Searched the forums and didn't find it.
When importing, there should be a reading of the manifest and finding the main class.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2021-05-30
Hasanly @azerphoenix

It depends on whether you are working with any build system or not.
If, for example, you use maven, then jar can be installed in your local repository. And you can even pour it somewhere. For example, via package cloud
Then, using the appropriate dependency tag (in pom.xml), you can import the jar as a lib. Well, then you already import the necessary classes using the import keyword.
If you are not using maven, you can for example create a libs directory. copy your jar there, through your IDE use "Add external JAR" (example name). And then also use the keyword import

G
gsaw, 2021-05-31
@gsaw

Here's an example on how to create a ClassLoader from a jar file. Well, then using this ClassLoader, you can load the manifest and read it, and how to load the class in the same example.
https://stackoverflow.com/questions/60764/how-to-l...
You just have to take into account, probably (I didn’t check it myself) the class loaded in this way will not see other classes, that is, if it has dependencies, you will have to load and dependencies, otherwise the class won't load.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question