Eclipse exporting JAR in WAR - java

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.

Related

How to organize gae projects in eclipse

I try to find the way to organize a GAE with several projects within Eclipse using the Google plugin for GAE:
The Web App project (a WebApp project) containing the GAE web application.
A Java project with data access
A Java project with utility classes
My problem here is how to link things together. I want to add the two Java projects in both build and execution paths. Since a Web App project follows the JavaEE structure, only what is specified in the WEB-INF/lib directory is taken into account.
I would like to find out how to simulate a Jar file in this directory based on a Java project present in the Eclipse workspace based on what the Google Eclipse plugin for GAE provides.
I saw something that seems to be related in the WebApp project properties Google > Web Application, section "Suppress warnings about these build path entries being outside of WEB-INF/lib".
For the GAE web application to run then you'll need the classes or a jar from the projects you want to include in the WEB-INF/classes or WEB-INF/lib folders respectively.
One way would be to build your data and utility projects and put the resulting jars in the WEB-INF/lib folder. You can then then reference those jars as libraries from your web app and all should be fine. Of course that's a bit tiresome to do manually, so you should probably check out some dependency management tools. From personal experience Ivy and IvyDE were easy to get into and should cover your needs although Maven and others have their strengths.
Another way that is a easier (but less structured) is to used linked source folders in your build path (to the source folders for your data and utility projects). In such way Eclipse will build those sub projects to WEB-INF/classes and build and execution should work similarly.

Myeclipse deployment issue for web module dependent java jars

I am using WAS 8, in the deployment folder, I just need to get the dependent java jar projects under the x.war-> web-inf-> lib, .
This can be done easily in RAD using j2ee module dependencies-> web library tab. How to do this in Myeclipse?
I disabled the deployment assembly mapping and tried many options in Myeclipse but seems like all have same result..
Eclipse indigo some how deploys the dependent java jar projects under the x.war-> web-inf-> lib.
Please help.
Dependent projects are deployed in the manner specified in the project properties (or the workspace preferences). Select the project, right click then go to Properties->MyEclipse->Web and select the Deployment tab. You can specify here how dependent projects are deployed and how exported jars from dependent projects are deployed, among other things.

How to properly set a JavaEE project classpath in Eclipse?

I'm developing a JavaEE system with several applications on a Weblogic AS (10.3.5) using Eclipse indigo with OEPE plugin. I turned my computer off, turned it back on, started the eclipse, and all of a sudden I get class-path errors all over the place (didn't change a thing).
Now let me get this straight:
1. Say I have an application with one EAR project that contains an EJB project and an EJBClient project (both in the deployment assembly).
2. I have written a new regular Java project, and I want to use it in both the EJB and EJBClient projects (it needs to be visible to them).
3. As far as I know, I can simply add this Java project to the EAR project's deployment assembly, and it will be visible to the EJB and EJBClient projects.
4. This has been working for me so far, but now I get class-path errors and I have to add this Java project to the build path of each project.
How should I set the class-path when using JavaEE technology in Eclipse?
After some tweaking I managed to solve the errors:
First I removed the library named 'EAR libraries' from the build path of each of my regular Java projects (I have no clue why Eclipse added them, they shouldn't be there).
Then, for each EAR project, I deleted and re-added every project or jar that was not part of the EAR (regular Java projects, other EJBClient projects, etc).
This solved the issue of not finding classes which aren't included in the EAR, but then I had a 'circular dependency' error.
I narrowed that error down to the projects that caused it - It was a regular Java project that was using an EJBClient project of some application in its build path, and the EJBClient project was also using the Java project in its build path.
Sounds trivial, then why havn't I seen it in the first place? Well, I looked into the EAR project of the application, and it didn't have the java project in the deployment assembly, and the EJBClient didn't have Java project as a 'required project'. So where was it?
The java project was in the 'EAR libraries' library of the EJBClient project, which, according to Eclipse, is automatically generated according to the 'MANIFEST.MF' file (which was empty, btw).
So I simply deleted and re-added the 'EAR libraries' library from the build path of the EJBClient project, and it solved the problem, and everything now works.
In conclusion, it seems like the OEPE plugin for Eclipse have some bugs that needs to be fixed.

How to include third party libraries in Utilty Project?

In Eclipse Java EE perspective, how does one add a thridparty Jar to a Utility Project?
To elaborate: In a "normal" Java (Not Java EE) project, there's Referenced Libraries where you can put jars. In a Dynamic Web Project, there's Web App Libraries. In a Utility Project, there's only EAR Libraries, which don't appear relevant (well, there are Referenced Libraries that show up in the Package Explorer in Java perspective, but not in the Project Explorer in the Java EE perspective). I went ahead and added a /lib directory under my Utility Project root, and put a jar there (I forgot if I did that in the Java Package perspective, or just in the file system). I added it to Java Build Path, and everything compiles, including the Dynamic Web projects that reference the Utility Project. But when I deploy to Tomcat, I get ClassNotFoundException for the classes in the thirdparty jar.
How do I add the thirdparty jar to the Utility Project in a way that will make it get deployed as part of the web application?
I answered something similar before.
Eclipse and How it Handles JARS -- Odd Case
In essence, there's a difference between build-time and run-time JAR dependencies. For inclusion in EAR / WAR files, you have to use the "Deployment Assembly" panels.
I am not sure to understand exactly your question, but you can simply right-click on your project, in Properties you select Java Build path > Libraries, and then add your JAR in the list of third parties libraries. This will add your jar in the classpath project.
Another way is to use the (ugly) solution of creating a lib directory, put all your third parties libraries in it, and add this directory in the classpath of your project (like for the previous solution, as you can add a whole directory in Eclipse project).
The last solution is to give the responsibility of the dependencies management to a real build system, such as Maven, Ant+Ivy, Gradle...

Eclipse WAR with 2 projects?

I am trying to export a WAR file from Eclipse. I have a "Dynamic Web Project". But I need classes created for two other projects, one a plain Java project, the other another web project. So in the Build Config I told it to add the other projects and on the "Order and Export" page I clicked the boxes to export the second and third projects. In runs fine within Eclipse, apparently finds the files from the other projects with no problem. But when I export, only the files from the first project are included in the WAR file.
How do I get Eclipse to include the other projects' files in the WAR? Apparently just adding them to the Build Config and marking for export isn't enough. Is there a problem because one of the other projects is also a web project? Does Eclipse balk at that?
I presume I could make this work by copying the files I need from the other projects to the first. But then any time they are updated, I would have to know that this had happened and copy the new versions. That would be a pain, and I thought that's what Eclipse projects were for, so I could share files between applications.
Edit
Let me clarify that I don't want to deploy 2 WARs. I have a web app written for one project that includes some classes that I want to re-use on another project. What I was trying to do was just pick up those couple of classes in the "real" WAR. I definately don't want to deploy 2 WARs because this might go on the same server as the original project, and I don't want to overwrite the existing WAR of the original project.
Thanks for any help!
You need to add your other project as a Java EE module to your web project. Right click on your web project -> properties -> Java EE module Dependencies. Add the 'other' project to it. Eclipse will include this project in the export.
Packing together different projects for deployment is achieved through an EAR file (enterprise archive). An EAR may combine multiple web projects (WAR), Enterprise JavaBeans projects (JAR), standard JARs, etc. and packs it into a single application.
Create a new EAR project in Eclipse, open its properties and check all dependencies on the Java EE Module Dependencies page. After that export the project as an EAR and deploy it.

Categories