Linking jar to war - java

I created a project(in netbeans) where all my gui part(used swings) is in java application-1.The data from java application-1 is passed to servlets in WebApplication-1 where the details are stored to the database.The project is working fine.
I was asked to create jar/war for my project..so that it can used any where...
I have gone through creation of jar and war(also tested with sample applications).My question is how can I link java application-1(jar) to WebApplication-1(war)??
For suppose jar is imported in another system it has to use war(since servlets are there in Webapplication).How can I do this??Is there a way to bind all the project into one library??

You can't access a war directly from the outside since according to the Java EE spec wars have to be isolated. Thus any communication between the GUI app and the web app must use other channels, the most obvious being http-based communication, like webservices.
Another option might be to create an ear and put the database code (moving it out of the war) as well as the GUI app and the war into that.

Related

Approach to be followed for deploying the application

We have developed a web based application in java(STRUTS 2.0). Now we want to deploy the application. The client is having one pre UAT environment ,UAT environment and a production environment.
Now when we are deploying for pre-UAT we have created the copy of our project and renamed it to pre-UAT. Similarly we are planning for UAT environment and one we already have for development. So in all we will be having 3 copies of our code.
I want to ask is this approach correct or what is the standard approach followed. This is not our final release as we are first releasing a version and then we will be working on other modules.
So please can anyone guide me for approach to follow for creating this 3 different environments.Thanks in advance
I am not sure what you refer to by "we will be having 3 copies of our code". If you are implying that you actually copied the code-base around multiple times, please stop reading and refer to this:
Why is "copy and paste" of code dangerous?
And once you finish reading, do some research about source control and how to use branching/tagging for concurrent development.
If you were referring to multi-environment deployment:
Assuming your application is designed correctly (and I'm treading very carefully here), one WAR file (you were mentioning you're using Tomcat, so I am concluding that your application is packaged as a WAR) should be sufficient. The application code should be environment-independent and should read its environment-specific configuration from external resources, such as a database, configuration files or JNDI.
If your application code is environment-independent, then all you need to do is simply deploy the WAR file to each of the environments (the same WAR file), plus the environment-specific set of external artifacts (such as configuration files).

Java EE 6 WAR packaging for pure server application?

I currently set up a Java EE project for a new business application using CDI. The application is a pure server application (using jms, webservices and such, but has no frontend).
Since we are using Java EE 6, I would like to use the new WAR packaging instead of the former EAR, which seems to be a simpler packaging mechanism to me and was recommended to use if one has no special modularization needs.
My problem in understanding is now, that I am still thinking of a WAR as a web application. How is the project layout in my case, do I still have for example a WEB-INF folder even though I don't have any frontend and there's no need to publish the application under a context? Or is there a better way to structure a pure server application?
The 'new WAR' has the same layout as the 'old WAR', the only difference is that the EJB JAR(s) can now be placed inside the WEB-INF/lib folder of the WAR. In the 'old WAR' you could not place EJBs inside the WAR.

turn api with hibernate objects into service for multiple applications

i have an API that is being written for a large group of 40 or so applications to share.
my problem is currently they plan on having the API as a simple library included in each war file for each program. the problem thats going to occur is when two apps are running on the same instance with different versions of the api library. ive had a lot of problems in the past with this.
i seem to remember a while ago something where i can wrap my library into an ear file or something and deploy it to tomcat to make it global. simply including it in the lib folder won't work because it will include hibernate systems that have to be deployed to allow the api methods to access the database. then in each application i would have an interface i can implement that allows me to call those api methods. very similar to local EJB3 but not as complex and didn't require an enterprise level server to implement.
anyone else remember something like this or was it a bad dream on my part?
You will have problems if you use a single jar shared by all the webapps, since it will then be impossible for two apps to use a different version of a library. But if each webapp has its own version of the library in its WEB-INF/lib, the container shouldn't have any problem: each webapp has its own classloader, which doesn't see the libraries of other webapps.

Questions about developing GAE apps on Eclipse with Clojure

After getting counterclockwise working on my Eclipse setup
and GAE development server running in interactive mode I found these
things still unclear for me:
1) How can I start server and application without commanding it on
REPL?
2) When I deploy application to Google servers, how and where do I
define the entry point of application? I mean, how Google will know
which application, application handlers and routes to use?
3) Can I combine using java classes and clojure files on same project
so that both are compiled automatic when creating and editing them on
my src folder?
4) Which files and jars are actually needed for uploading to GAE at
the end? Im used to deploy PHP apps to GAE, but here I dont know if I should make jars, include compiled clj files. I also might like to organize files different way than counterclockwise or appengine-magic does, so where do I specify paths to resources and classes?
5) Finally is it possible to connect Google production server with
Emacs - Slime - Swank combination? That would be the fulfill of
dreams, lol.
I'm using appengine-magic with Jetty, Compojure, Ring and Hiccup.
I'm going to suggest a lein/appengine-magic/Eclipse hybrid approach. Create your GAE project with appengine-magic and then set it up in Eclipse.
Create a Clojure "Run Configuration" and check the source files you need evaluated to bring the server up. You will get a REPL to it when it starts.
Your GAE entry point is your web.xml server-class, which refers to the ahead-of-time compiled source in app_servlet.clj (assuming you used lein appengine-new to create the project originally). Look in app_servlet.clj for the call to make-servlet-service-method -- the argument there is your App Engine Magic (see def-appengine-app in core.clj) entry point. In turn that refers to your Compojure handler and routes. See https://github.com/gcv/appengine-magic for the details.
I have not done this, so cannot comment.
Let appengine-magic take care of this: lein appengine-magic prepare, then deploy the deploy the war directory appcfg.sh (which you can find in the GAE Java SDK). You may also be able to use the GAE Eclipse plugins to achieve this.
You cannot use sockets with GAE. Swank depends on sockets, so a REPL to your live application is not possible. You can REPL all you like with the dev server however.
Q 1 & 2 were eventually solved and cleared.
Q 3 I wasnt able to do it because either java or clojure classes overwrote each other and I couldnt change target directories for them separately.
Q 4 after first succesfull deployment now I know what are the core base jars to be included. Yes it depends on what you happen to use on your project. I think I have transferred way too many unnecessary files on PHP deployments.
Q 5 Thats what I thought. But I didnt get swank working on dev app engine server. Its reporting illegal access to some appengine sdk file. Maybe I need to include it on project libs...

Eclipse: Two web projects, one servlet

I use a library which includes, among other things, a servlet. I've fetched the source for this lib to a dynamic web project and it works fine.
I'd like to make an example dynamic web application in another project which would just reference to the classes of this library. Is it possible to do it this way in Eclipse Galileo and deploy to Tomcat.
This I like to do, so that in the library source project I have only the libs own code and my modifications to it and my example app would be a totally another app.
In Eclipse I've referenced my example app project to the lib project and it works fine when coding, but when I try to access the example app URL it throws a ServletException because it can't find the Servlet.
The libs own web page works fine.
Can you not just create a JAR containing the classes you which to share and then reference this JAR in each project?
I would recommend staying away from IDE features like the ones in Eclipse that try to bundle up your app and deploy it for you - I find it helps much more to control this yourself, with your own build scripts, app server setup, etc.
This way you aren't stuck wondering why a certain nuance of the IDE works the way it does (such as, why is Eclipse not deploying the output of a project I've added as a "reference" along with this project?) - you can completely control your own environment. It's more valuable to know how to bundle up and deploy things on your own anyway (since it works the same regardless of whatever IDE you are using), and the tools behind it are a lot more powerful than any "press this shiny button and everything gets deployed and launched" feature in your IDE.

Categories