Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Deployment Assembly and J2EE Module Dependencies in Eclipse

When using a Eclipse 3.7 Indigo for Java EE Developers, there is something called Deployment Assembly . I could find on google and understood that it is similar to the J2EE Module dependencies where in we could select the jar and which goes and sits in the EAR folder or in WEB-INF/lib in case of WAR. Now the doubt I have is,

I have a JavaProject Dependencies. I have added all the dependent Jars via classpath variable. Now the Dependencies Project is added as dependency to my Web Project TestWebProject. The compilation of the Web Project is correct but during runtime I get an error because some jar was not found. I could fix this my include jar in Deployment Assembly of Dependencies Project, which is a standalone project.

The question is that, why I had to fix the jar in deployment assembly since ,first, its a standalone project and second is if I would not have this deployment assembly , how could this be fixed?

like image 890
chaosguru Avatar asked Jun 20 '12 18:06

chaosguru


3 Answers

I could find on google and understood that it is similar to the J2EE Module dependencies

It was called "J2EE Module Dependencies" until with Eclipse 3.5. After that version, it was renamed to "Deployment Assembly". But it's effectively the same in case of Java EE web projects.


The question is that, why I had to fix the jar in deployment assembly since its a standalone project

Because this way Eclipse will autobuild a JAR file of the project and put in /WEB-INF/lib of the web project's deployment. If you don't do that, the JAR isn't available during webapp's runtime, but only during compiletime and Eclipse expects that you've already built and placed it anywhere else in runtime classpath, e.g. server's own /lib.


if I would not have this deployment assembly , how could this be fixed?

Manually build/export the JAR and drop in webapp's own /WEB-INF/lib or server's own /lib. The "Deployment Assembly" configuration is however more easy and the recommended way.

See also:

  • Business Logic Layerin Servlet and JSP
like image 79
BalusC Avatar answered Nov 12 '22 08:11

BalusC


When assembling a WAR, Eclipse cannot tell just by looking at your build path dependencies whether they are something that should be bundled in WAR's WEB-INF/lib directory or if they are something that you expect to be available on your server classpath. Extra metadata is needed to differentiate among those cases.

If you look in your problems view, you should see numerous warnings that look like this:

"Classpath entry [something] will not be exported or published..."

Right click on these and select "Quick Fix". You will see a dialog with available fixes. One of them is going to say something like "Mark the associated classpath entry as publish/export dependency...". Use that option.

The above will make a slight alteration to your Java project's .classpath file to tag the dependencies for inclusion in the assembly. You can test without running by exporting a WAR file and checking the contents of WEB-INF/lib folder.

like image 5
Konstantin Komissarchik Avatar answered Nov 12 '22 07:11

Konstantin Komissarchik


Build path - place your jar's here directly, it will be available for code runtime and compile time.

Deployment assembly - eclipse expects the projects under this path to be bundled and deployed as .jar in web-inf/lib folder. So that it is available for both compile time and run time. If the project is not deployed in deployment assembly then the code is available only for compile time, eclipse won't bundle it and at run-time dependent projects are unavailable to the code.

like image 1
Preetham R U Avatar answered Nov 12 '22 07:11

Preetham R U