Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Web Project referencing another Java project

I have a Java Project, for which I'm now creating a Web interface, using a Dynamic Web Project from Eclipse. The Web project consists of a single servlet and two JSP's. Something like this:

/JavaApplication
  /src
  /lib
  /resources
/WebApplication
  /src
    /Servlet.java
  /WebContent
    /WEB-INF
    index.jsp
    other.jsp

Now, I need to reference JavaApplication from WebApplication, in order to use its classes to process web requests. What's the best way to accomplish this ? My idea is to create a .jar of the JavaApplication, containing all the .class files, /resources, and /libs. In this way, I could include the .jar in the web application, and I could have a single .war file that contained the entire application.

What do you think? How is this problem typically solved ?

Note: I don't want to convert the Java Project into a Web project.

like image 552
João Silva Avatar asked Nov 07 '09 01:11

João Silva


People also ask

How do I reference another project in Eclipse?

To access the Project References Properties page, right-click a PHP project in PHP Explorer view and select Properties | Resource -or- select the project and from the menu bar go to Project | Properties | Project References Properties .


1 Answers

In Eclipse project properties, add the project to the Java EE Module Dependencies (Eclipse 3.5 or older)

Java EE Module Dependencies

or Deployment Assembly (Eclipse 3.6 or newer) entry in the project properties.

Deployment Assembly

This way Eclipse will take care about doing the right thing to create a WAR out of this all (it will end in /WEB-INF/lib). No other configuration is necessary, even not some fiddling in Build Path.

like image 137
BalusC Avatar answered Oct 05 '22 18:10

BalusC