Distributing project into multiple WAR files - java

I currently have a Java EE Netbeans project with multiple servlets. Some of these servlets are dependent on the same classes and libraries, and some are not.
At the moment a single WAR file is built, containing all classes and servlets.
What I'm trying to do tell the IDE to build one WAR for each servlet, where the WAR contains the dependencies along with the servlet itself.
I've tried looking through the build.xml for what tags to override, but I don't find anything that suits my needs.
How do I accomplish this?

Related

Java EAR project containing multiple JARS

I was assigned to work with ten year old legacy Java project. The code base is huge and it's my first encounter with big enterprise project.
I'm confused about the project structure, as there are dozens of something.jar called directories inside src/application.ear directory, each of these jar folders containing it's own ant build and configuration. Yet the final build will be single ear. Is the rationale for building jars from different subsystems to ship them to possibly integrated system? Is this some common pattern to name the folders by the jar names?
Is the rationale for building jars from different subsystems to ship them to possibly integrated system?
Yes,
EAR (Enterprise ARchive) is a file format used by Java EE for packaging one or more modules into a single archive so that the deployment of the various modules onto an application server happens simultaneously and coherently.
In the J2EE world, an entreprise application can be composed of web modules, ejb modules, etc.
So (and this is me guessing), the directories called something.jar can be submodules of the enterprise application o library modules required by the application (EAR)...
Is this some common pattern to name the folders by the jar names?
I don't really. I never had seen before. But I understand the purpose of such layout. The purpose is to encapsulate the files (build.xml -- ant tasks) that build some artefact called something.jar ("required by the EAR app, perhaps?"). So using this layout, a developer can easily identify which build file (build.xml) constructs what artefact. Also, using this layout, a developer can define a master build script that coordinates the order and execution of the other build scripts (EAR submodules).
So, in other words, you're watching a "pseudo" Maven framework, using ANT as implementation...
May be is time to start migrating this old application to the maven model!

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.

How to Deploy Java EE Project which reference external JAR files in weblogic

I have a web application which consist of JSP pages, Servlet and Consumes Web Services.
It also references apache axis and excel libraries.
Now I want to deploy my application directly in Weblogic server
How do i do that.Whcih archive shud i make WAR or JAR??
ALso how to ensures that it covers all the referenced libraries.
I have made my application in Jdeveloper, but I dont want to deploy it using Jdevelper..
I would package my solution as a .war file, containing all dependent .jar files.
That way your solution is self-contained. You can deploy to an app server containing other apps with their own versions of your libraries (dependent or developed). If you put the dependent jars directly into the app server (as you can do), then you're forcing those versions on all applications deployed, and that could well cause you grief.
The downside is that your developed .war file can become sizable. It's not normally a major problem, and I wouldn't worry about it until it's identified as an issue.
A JAR-file cannot contain a JAR-file, so that option is out. Since you mention JSPs and servlets a WAR would seem the appropriate option, although an EAR with a WAR and several JARs could also be a way forward...
Cheers,
Consider a WAR with your JAR files in WEB-INF/lib. Or, create an EAR with APP-INF/lib folder.

Move servlets to jar file in purpose to use as library

As I know it's rule to locate servlets in webapplication module. So after packaging we'll have war archive.
But later I need servlets to use like library. So as we cannot use war file as library i need the jar.
The question: is it normall to refactor webmodule so that move servlets to other project(module) to package to jar archive and use it in webapp as dependency while compiling ?
It's pretty rare to have general purpose, reusable servlets (except if you're developing a framework). But if you have one, putting it in a jar to make it reusable by several webapps is the way to go.
It's not normal (or, indeed, recommended) to package servlets in a jar or to use them as "libraries". What you are supposed to do is extract and isolate any business-logic that is "common" and should be usable by others than the servlet. Those classes can then be packed in a jar that is included in the webapp war as well as any other clients/modules you have that need them.

How to deploy a single webapp with multiple web-modules that may be removed or added individually

We currently run two separate webapps (WARs) deployed in one single EAR containing additional JARs and settings. To improve our deployment I want to split one of these webapps into different modules that may be build and packaged individually. But I've currently no clue on how to package these modules so that I'm able to add or remove them as desired - at best during runtime.
The webapp is getting more and more complex and I'd like to separate some of the functionality into modules. These modules should be packaged as single archives. As long as they contain only classes and resources loaded through code I know how to do this (simple JARs). But how about JSPs? Normally a WAR file contains JSPs or HTML files. I my case it are JSF pages utilizing JBoss Seam and RichFaces.
These modules will add classes, resources and JSF pages and other includes to the running webapplication. Is it somehow possible to deploy them as individual archives to serve the same running webapp?
We are using Maven for our build and packaging and deploy into JBoss v4.
Simple way of doing it is to put the JSPs of different modules in different folders and the JSPs which are used commonly in all modules can be kept in the root.
Now if you want to unload a module, remove the corresponding folder.
Hope this helps.

Categories