简体   繁体   中英

Adding external jar in eclipse

I have a java main project and a java library project which is added as a library in the main.

The library has some .jars with essential content for both (the main and the library). I thought the main project could access these jars, but apparently not. Am I correct?

So... I thought I would have to dupplicate the .jars from the library and put them also in the main project. But this is quite awful. So I found the "Adding external .jar" from eclipse which let me add this .jar from the library, but my question is: "What will happen when I build an unique .jar? Will the .jar be added to the library and also to the main dupplicating itself?"

Also, can I import as a library an open project wihout having to compile it into a jar and be able to edit the project in real time?

Thanks

When you build a unique jar for your own code, it will not include the classes from the other jar. If you want other people to run your program, they will either need that jar themselves, or you will have to distribute the additional jar with your own jar (assuming that's allowed).

You could unpack the jar on which you are dependent and put it in your own jar, but this is unusual and not recommended. If the people who wrote that code corrected bugs and distributed a new jar, people who got their new jar would get the fixes and improvements, but not people who were using your packed version unless you distributed a new one.

I have no idea what your last question means...

You can certainly have one project depend on another, which sounds like what you mean by " can I import as a library an open project wihout having to compile it into a jar and be able to edit the project in real time? ".

To share the jars from the library project, go to the "Order and Export" tab in the Build Path dialog, and tick the jars you want to make available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM