Adding a Web Project as a jar in an Eclipse Deployment Assembly - java

The site I'm working on now is made up of several java projects and a main web project A which references them. The IDE I'm using is Eclipse Helios.
What I'm trying to accomplish is adding a new project B to the stack. The project is also referenced by the main one, but is in itself a Web Project. When I add B to the Deployment Assembly of A, when publishing, Eclipse automatically packages it as a war and deploys it to the server's WEB-INF/lib.
I want it to be deployed as a jar, but also keep the project's web nature, as it has some features (and tests) that are run on it. I have ant tasks in place for building a jar out of B, but I don't know how to use them in Eclipse. Also, I'm not sure if it's possible to make Eclipse deploy a jar out of a web project.
I can add the jar manually (as an archive from the workspace), but that would mean that whenever someone cleans all projects, the jar for B would get deleted and not generated, as the build only compiles the classes and the deploy packages them into the war.
P.S. I know the design is poor, but changing it is out of the question as I don't have the authority :).

I found the following solution that works for me on Eclipse Luna
Project B "Project Facets" : select "Utility Module" instead of "Static Web Module" or "Dynamic Web Module"
Project A "Deployment Assembly" : remove "B" and add it another time.
=> The "Deploy Path" of B is now B.jar

The easiest way is: File -> Export... -> Java -> Jar File
To use ant: open project properties, the go to Builders, Click new, selec Ant Builder, etc.

You can do something like this:
Write a shell/batch script that
calls ANT script of project B which creates a JAR file.
and then, it calls ANT script of project A.
Update ANT script of project A, add a copy task. This file copy task will use relative path to copy the JAR file created in step#1 to project A's WEB-INF/lib directory.
In Eclipse, go to External Tool > External Tools Configuration > Program > New Progam and add this Shell/Batch script to it.
Whenever you want to build. Run this external tool from menu.This will ensure
Your build always has the latest of Project B
ANT tasks will stay small.
Adding a Web Project in an Eclipse Deployment Assembly
I did not know any such thing, until Thorbjørn Ravn Andersen pointed this out in another question where I answered. As mentioned there:
What goes in the deployment is determined not by the build path but by the Deployment Assembly entry in Preferences for the dynamic web project.
But, may be, you have already tried this.
Edit#1: fixed grammar
Edit#2: added more info

Related

Add project JAR to deployment assembly but not build path in Eclipse

Eclipse automatically adds everything in WEB-INF/lib (specified in deployment assembly) to the project's build path. Is there a way to override this behavior? I need for another project jar to be deployed and available at run time but not have a forced compile-time dependency on it. Thanks!
Go to the properties window of the project. Then go to java build path tab and remove the relevant other project from libraries there. Then go to projects in the same tab and select the required project by using the add option and add it. Then restart Eclipse.

The project uses build.properties from another NetBeans installation

When using trying to build a NetBeans project created with a previous version, I get the following confirmation dialog:
Build Project
The project ... uses build.properties from another NetBeans installation.
Build Anyway
Use this installation
Update
What would these options do?
No matter which options I choose, I do not notice any difference in the build process.
Using NetBeans Development with projects created on NetBeans 8.1.
it depends on what type of dependencies you are using in your project, to be on safe side , I'd prefer clicking Update which it'll update current project's build properties with the external one,
also here's what (wiki.netbeans.org) have about build.properties file:
"If you edit build.xml by hand, you can of course arrange to build other projects (or any Ant scripts) as part of your build, using the or tasks. Note that a build-impl.xml, when building a foreign project, calls its build.xml (rather than skipping to its build-impl.xml), so you can freely mix a hand-customized project with IDE-customized projects."
thanks

Export a project referenced as a library on a web project to tomcat

I have a project which reference another project (like this example : http://upload.wikimedia.org/wikipedia/commons/c/c0/EDT_Tutorial_edt_richui_sql02_service_project_Java_build_path.JPG) and when I run my dynamic web project i got the NoClassDefFoundError.
I checked the checkbox on the Order & Export tab.
I succeeded when I created a jar of that project and placed it in WEB-INF/lib but I don't want to rebuild manually that jar everytime, how to do that ?
PS : I'm not using maven.
You need to set up where the projects in your Java Build Path should end up in the deployment. Yes, this is something for which you can use Maven. In your case, I think you should be going to the EGL Development Deployment page. If this were a conventional DWP, I'd say to use the Deployment Assembly (http://www.eclipse.org/webtools/releases/3.2.0/NewAndNoteworthy/javaee.php) page.

Adding 3rd party jars to WEB-INF/lib automatically using Eclipse/Tomcat

I have a dynamic-web project set up on Eclipse and I'm using Tomcat 7 as my web server. It doesn't seem to be automatically putting 3rd party JARs I add to my library on my build path into the WEB-INF/lib folder. Is there a way I can do this automatically? Every time I search for an answer to this, I find something like this.
So how do I do that automatically? Is there a way to configure my build path to do this?
Here are the instructions for Helios. For earlier releases, see SeanA's answer.
Project Properties -> Deployment Assembly
Add -> Java Build Path Entries
You should now see the list of libraries on your build path that you can specify for inclusion into your finished WAR.
Select the ones you want and hit Finish.
You can use "Ant" to copy files to WEB-INF/lib when you deploy files. Using Ant you will be able to copy only those files which have changed.
http://ant.apache.org/manual/Tasks/copy.html
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.user/gettingStarted/qs-81_basics.htm
I haven't tried this personally, but what I believe it does is what I think you are looking for:
Right-click project -> Properties
Go to Java EE Module Dependencies
Check the boxes for the JARs that you want to export with your Web Application
Let me know if this automatically puts them in your exported WAR. I always just add mine to WEB-INF/lib :)
Instructios for Eclipse Indigo (version 3.7.2)
Project Properties -> Deployment Assembly
Add -> Archives From File System -> Next -> Add
(The file dialog of your system opens up.)
Navigate to the archive you want to include in your WEB-INF/lib, select it and hit OK.
Hit Finish.
Hit OK.

Eclipse exporting JAR in WAR

I have two projects in eclipse, a library project producing a Jar file and a web project dependant on that Jar. How do I get the web project to export the first projects jar in its war automatically. I know this must have been answered before, but I really cant find it.
Thanks,
The mechanism to determine what goes in the war is not the build path as for "normal" applications, but the "Deployment assembly".
Right-click on the root node of the dynamic web project, and select Properties, and select Deployment assembly. Here you can add projects (which are jarred up and added to WEB-INF/lib) and individual jars in the project.
EDIT 2015-08-20: A few years later, Maven has become the standard way to build Java-based software primarily due to the script based approach to dependency management. This includes how to build WAR-files, and the three major IDE's (IntelliJ, Netbeans and Eclipse) fully support this allowing you to switch between IDE's while developing. In Eclipse the problem asked here will not apply, as this is fully controlled by the Maven plugin.

Categories