How to handle shared dependencies - java

I'm currently working on a web project that has some commom modules/ jars dependencies with other projects that run on the same server and I'd like to know whether it is possible to "pass" those depencies to the server so that i get "thin" wars. Our projects are built using ant's build.xml and we user Tomcat as the server.
Context:
Recently my company started using AWS on it's projects, so we had to add aws-sdk jars to all our projects and their .war grew substantially in size, so my goal here is to transfer all the common jars/modules (or aws-sdk at least) to the server /lib folder.
Currenty all the dependencies go onto the [project_name]/WEB-INF/libs folder, so I face the situation described below:
project1/
WEB-INF/
libs/
aws.jar
common.jar
myjar.jar
and
project2/
WEB-INF/
libs/
aws.jar
common.jar
itext.jar
And I'd like to extract those common [common.jar and aws.jar] jars to a common folder such as {tomcat_home}/lib or another.
Questions:
Is it possible ?
[if it is possible] How can it be done ?

Related

usage and significance of .Classpath in Application EAR

I am currently working on an EAR application which has a WEB project and EJB project in it.
To work on eclipse with local set up i do so many build path setups and all.
All these buildpaths show up in .classpath of the project.
Now when i export the EAR and deploy on Server everything works on server.
My doubt is how does server know about my local system paths which are present in .classpath of my project.
Does it mean .classpath has no significance at runtime?
Please explain.
.classpath file is eclipse specific, it will not be bundled with the EAR. Eclipse uses it to set the classpath for the project.
An EAR has a well defined structure and Servlet container understands that structure, using it's knowledge it prods around in the EAR file and extracts classes to load in the runtime.
Obviously server doesn't have any knowledge of your local environment. An EAR (or WAR or JAR) file is a simple archive file (with some specification or the file order and all). You can unzip it using any utility (something like 7zip). Check the structure of the packed EAR, that will give you a better understanding of what goes to your server.

JBoss buildpath, project delete external jars

I'm developing a web application in JBoss in Eclipse Luna using external jars. I have imported the jars clicking on Project => Properties => Build Path => Add External Jars. Because the web application will need to use those jars, i have placed them in the MyApp.war/WEB-INF/lib folder, so, when the webapp will be finished, i'm sure i can just export the .war folder and deploy it on another server.
1) The problem is that everytime i turn on my pc in the morning, the deployment process gives me a ClassNotFoundException. I see that the external jars are no longer in their place. As far as i know, i'm not using any plugin to manage dependencies (i'm a newbie on webapps)
EDIT:
2) what i do is unpack my zip containing the jars again in the lib folder. Strangely, if i unpack them in a subfolder (for example, i place the jars in lib/httpcomponents/lib) JBoss cannot find the jars. What's the reason?
Try to inserting the external jar files in to jboss server lib directory (jboss\server\default\lib)

Converting backends to modules. I.e. going from WAR to EAR structure

We are in the process of converting our appengine project that uses backends to one that uses modules instead. See https://developers.google.com/appengine/docs/java/modules/converting
This implies going from a WAR project to an EAR project.
However the appengine eclipse plugins only has support for pointing out a WAR directory.
Does anybody know how this work. I.e. should we point this to our EAR directory?
We faced the same problem when migrating from backend to modules.
it seems that currently the GPE doesn't support modules, how ever we did solve this with this hack:
We renamed our WAR directory to "default" (you can point the web application there (under Project Properties -> Google -> Web Application -> WAR Directory).
We also included a dispatch.xml file in that module's WEB-INF dir that tells appengine which module to serve according to urls.
the last thing we had to do is to have a custom script that compiles gwt/class to those directories and deploys to appengine.
here is the overview of the project's layout change:
OLD LAYOUT
project_main_dir
war
NEW LAYOUT
project_main_dir
default
WEB-INF
dispatch.xml
module1
WEB-INF
module2
WEB-INF

Does the Google-Eclipse plugin autogenerate war directory contents?

I just created my first Web Application Project using the Google-Eclipse plugin. Amongst other artifacts, it autogenerated a war/ directory with several subdirectories and many files, including:
war/
WEB-INF/
lib/
<Lots of JARs here>
web.xml
appengine-web.xml
etc.
Several times now I've cleared out certain parts of this war/ directory (messing around with buildscripts and other Google-Eclipse plugin features - this is just a test/temp project for getting used to the plugin), and they magically reappear at some point in the future.
I'm wondering if, because I set this up as a Web Application Project (and it is thus managed by the Google-Eclipse plugin), is the plugin trying to preserve the structure of the war/, and as such, continuing to auto-generate any missing files?
If so, why? Exactly (which files/directories) what is it trying to preserve? Can I disable it?
And if not, then I obviously have something else going on here. In which case, has anybody else ever experienced this with the Google-Eclipse plugin, or just Eclipse in general? Thanks in advance.
This plugin only updates war/lib directory by adding dependencies. Actually it just copies jar files when you switch to a another version of Google App Engine SDK.
This should not be a problem.
War folder is the exploded package that later on you need to deploy to Google App Engine.
When you build or deploy file to GAE, this folder will be re-created/updated, and it contains the newly compiled jar and the necessary libs.
Read this.
War folder contains the generated javascript files which are deployed to the app engine.

Java - Difference between dist and deploy folders

Forgive me for a novice question, but what is the difference between the dist and deploy folders? It seems like the same thing - both contains the .jar of the files. However, when you clean and build the project, it looks like only the dist folder is updated. How does the deploy folder get updated?
Thanks.
I will assume that you are using a directory layout similar to what Netbeans IDE creates by default.
dist is the folder where your generated archives are stored (so it gets updated through clean and build).
build folder contains compiled classes and resources, but not the compressed archives.
Maven, by default, places the content of both into a target folder.
A deploy folder is the place where you put your generated artifacts (either archives or directory trees with the same layout as archives, a.k.a. exploded archives) so that you Application Server can serve it.
In development environments it is not unusual to configure the server to scan the dist folders for generated artifacts and redeploy them. So, in that sense, deploy and dist folders can be the same.
You can even have "in place" deployment scenarios. This works by compiling your classes direct to WEB-INF/classes folder inside webapp (with something like Maven war:inplace goal). If you set your server to scan changes in this folder, you can edit resources such as jps in place and have it immediately reflected into your running application (a.k.a. exploded artifact hot deployment).
Of course that you can accomplish something similar by instructing your IDE to copy resources and compiled classes to a exploded archive structure and configuring your server to scan it. Netbeans tends to use build/web for that purpose.
Also sometimes incremental redeployment is not possible and frequently full redeploys are not desirable (some applications may take several minutes to redeploy). That is why you can use separate folders / deploy your artifacts as jars / wars / ears, etc.
Compiling, packaging and deploying are very different phases / concepts of a Build lifecycle, which may or may not happen together.
I hope this is enough info to get you going.
Cheers,
Typically a project is responsible for creating one artifact, when that artifact gets built it is put in a directory called target or dist. When your project is responsible for creating a web application, you need a place to layout the files in your project to run under your servlet container or app server, and that place is the deploy folder. So the dist directory would typically have a single artifact like a war, ear or jar, while the deploy folder would have the contents exploded in a directory structure where the app server can use them. How the deploy folder contents get updated depends on your build process or IDE integration.

Categories