简体   繁体   中英

how to refer java web project library from current project?

I have a web project Web1.war which have some jar file in its libraries (let's call it lib.jar ). That is Web1.war --> lib.jar .

Then I did convert to jar file that web project: Web1.jar . Afterwards add the Web1.jar file to another java web project Web2.war .

How to refer that library lib.jar from current project ( Web2.war ) through jar file ( Web2.war --> Web1.jar --> lib.jar ) ?

Java only supports JAR level dependencies. You mention having converted you 'web project' to a JAR but don't give the details of how you did this.

By default, Java uses the classpath to find dependencies. In a 'web project' (WAR) the classpath is the WEB-INF/classes directory and any JARs in the WEB-INF/lib .

If you have classes in one 'web project' (WAR) that you need to use in another 'web project' (WAR) then you have a couple of options, both of which will involve modifying your build:

  1. put shared classes are in their own jar, which you include in both 'web projects' (WARs).

or

  1. unpack the first 'web project' (WAR) adding the classes (and/or libraries) to the second 'web project' (WAR).

Update

You cannot covert a WAR to a JAR as you have suggested in your edits. While it's possible to create a custom archive format, a JAR cannot (and should not) contain other JARs.

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