How to package a java web application - java

Our company has developed a web application based on Struts2 + Spring + Hibernate.
My boss wants me to make a installation CD contains JRE, Tomcat, MySQL, and our product, so that the client can just click sth like installMe.exe and follow the wizard to complete the installation.
I used to deploy web application with war. Just put it under tomcat webapps folder, and start tomcat.
Which software should I choose to complete my boss's task?
Thanks, guys.

You need to create an installer script and tell the installer where to put the files. I have used two, advanced installer which creates an MSI or Nullsoft which is from the guys who created winamp. A lot of open source companies are using it. I'd recommend the fist one, and getting a license to do the more complicated stuff.
The installation of Java is handled automatically with advanced installer. There is even a cool java template you can start from.

Related

Package Java+Apache+MySQL for desktop use

I need your guidance on creating java installation (may be exe) for desktop machine. Its web based application developed using JSP, java, Apache Tomcat, and MYSQL database. The installer will be packaged with - Web Server, war file, My SQL DB. When installer(.exe) is executed - it should configure web server, install my sql db and finally application icon will be created on the desktop. Clicking on the icon will open the app in the browser.
Is there a tool that can help me to accomplish this?
Thanks everyone for your suggestions.
Yes, you can use Advanced Installer. They even have a wizard which can guide you step by step through the creation of your installation setup. Just try to use their "Java -> Tomcat Web Application" project wizard.

Steps to deploy web application on Tomcat via install4j installer or Advanced Installer

Can anyone give me some documentation link/tutorial which could help me create .exe windows installer for Java Web Application.
I have a Java Web Project which runs on tomcat server and I want to run theproject on windows with a single click. So for the same I want to create .exe file which I could use as installer to run on any machine.
I couldn't find any proper document to create .exe file with the use of popular installers like Install4J and Advanced Installer.
Please let me know if somebody has document or any kind help is highly appreciable. Thanks in advance.
According to my understading of your question, I believe you'd need these few things to do:
Copying your tomcat containing the WAR file in webapps directory to
default/specified directory.
Or else for an existing tomcat, copy your war file in tomcat/webapps
directory.
Execute tomcat startup.bat from tomcat/bin.
For the above tasks, I'd say the below links will suffice:
Install4J, Advanced Installer Tutorial

How to Point Apache Towards a Vaadin (Java) Project?

Sorry if this is the wrong kind of question but currently I have an Apache server which is configured for Pyjamas. All I used to have to do was: pyjsbuild example.py and the GUI would appear in my browser.
I decided to switch to Java, so I picked Vaadin as my framework. How do I do the equivalent for Vaadin? All I want to do is compile the java and have Apache recognise it.
I'm using linux and I'm very new to building web applications, previously I only ever built the GUI side of things, I never had to touch the server.
You need Apache Tomcat to serve java pages. Install it separatly or see http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html for information on how to hook them together.
Vaadin projects work just as any web project. You have to crate a WAR file.
For example, if you are using Eclipse, right-click on the project, choose "Export..." and under "Web" choose "WAR file".
If you are using Netbeans or something else, google "create war in netbeans/intellij/..." to find out how to do this step.
This will generate a file with the extension .war, which you will have to copy in the "webbaps" folder of your Tomcat installation. Restart Tomcat and the application will be automatically deployed.
If you do not have access to the webapps folder, go to Tocatmcat's "Manager App" in the browser and
under the section "Fichier WAR à déployer"(WAR file to depploy) choose the generated file and click Deploy.
To start with, make sure that go through Getting Started chapter in Book of Vaadin. In this chapter you will find overview of the required toolchain and step-by-step installation instructions. Your Linux distribution might have more documentation about installing JDK (For example, see Ubuntu wiki for Oracle JDK installation).
It will be convenient for you to connect Tomcat to Eclipse IDE. This makes starting Tomcat and updating your application easy. For example, see this [blog] for some videos about connecting Eclipse to Tomcat.
Please note that using Eclipse is just one approach and later you might want to see if IntelliJ IDEA or command line works better for you.

what are the steps in order to run java enterprise application

Sorry for this simple questions but i am too much confused with how to run java application. Whenever i ask some each one tells his own tools to proceed and i have learn that thing.
So provided i have simple basic eclipse with no plugin and i have downloaded the sample web application which uses spring , hibernate , mysql ,
The folder structure of app is
.setting
src--main,test
target
.classpath
.project
Now i want to run this using localhost in browser
what thing i need to do. i will tell from my knowledge and u guys can correct it
i don't want to use STS or install any plugin in eclipse.
I imported the project from eclipse
menu and i appeared on left window
As it uses spring do i have to add
the spring jar files in build path
of spring. or anything else
Same for hibernate jar files
Fior simple java app i used to
compile the class which contain the
void main function but i have no
idea which file to compile to run
this app
I added the mysql connector in build
path to connect with mysql in simple
java app. will same thing work here?
I knoow we need web server for that.
so if i want to install glass fish
server then how will i connect it to eclispe or that app. will tomcat be
ok than glass fish??? i know tthere
is eclispe ide with embedded glass
fish but i want integrate evrything
myself
IN browser i which url i need to use
to see that app
I don't know how did maven , appfuse fit in here. Can i run app without maven if yes then what does maven really do , i mean does it compile the java files or what. If i require maven then
Do i need to install it separately i
mean exe file or jar file
how to link with eclipse
I have read about building with
maven , what will ahppen after
building i mean what is the result
of building , will i see browser
after building or after building
there are some steps further. do
maven needs to link with web server
installed
sorry for basics questions but i am confused with all new trminology
Building a webapp is complicated. I will try and address your specific questions.
Utimately you don't need Maven or Appfuse, both can be very helpful.
Maven is a build tool. Maven and Eclipse do some similar tasks. Both can compile your code and manage a classpath. Maven handles a lot of things out of the box that Eclipse can't do by default. Maven can manage dependencies (i.e. download the spring jars for you) and create complex build processes.
If you are unfamiliar with Maven and creating a build file from scratch then it probably won't be much help. If you have a pom.xml (Maven build file) from somewhere else then Maven can be a big help. The result of Maven depends on how your build file is structured. The result is most often either a .war file (described below as step 5) or that your application is deployed directly to your web server (described below as step 6).
Appfuse is also not mandatory but can be useful. Appfuse will create a skeleton project for you. When it does this it will create a pom.xml (Maven build file) to automatically build your project. Appfuse by itself doesn't do anything other than help get projects started. Most people don't start building web apps from scratch anymore since getting the directory structure right and creating the build file can be a lot of work and it's easy to make mistakes. A tool similar to Appfuse is Spring Roo.
Tomcat, Glassfish, Jetty, and JBoss are web servers. They are also often called Servlet Containers which is just another name for a web server that hosts servlets in a certain fashion. Any of them will work for your project, they all have different learning curves. Integrating them into Eclipse may work for you, when I got started I found it was easier (although a little slower) to keep them separate.
In the JDK there is an interface named javax.servlet.Servlet. This is the interface that the entry class of your web application must implement. In particular the method service(ServletRequest req, ServletResponse res) is called every time there is a request for a URL. If you want your web application to respond to HTTP it may be simpler to extend the abstract class HttpServlet (which implements Servlet) instead. Most libraries (i.e. Spring web framework) have their own implementations of Servlet that are the entry point to the library.
I will now describe the basic process for building a web application. This is a complicated process and most people eventually automate it with Maven. I do not suggest trying to manually walk through the process yourself it can be very complicated but you can if you want. I am going to assume that you are placing all of your built files in a folder named $BUILD
Compile your source code. The compiled classes need to end up in a folder called $BUILD/WEB-INF/classes
Place all your jar files (external libraries) in a folder named $BUILD/WEB-INF/lib
Create a deployment descriptor, this is a file that tells your web server how to deploy your code. The most important thing in this file is a mapping from URLs to Java classes that implement Servlet. It should be named web.xml and put in $BUILD/WEB-INF
jar up the all this code with the root of the jar being at $BUILD. You could call this code application.jar
Rename the jar file extension to war. A war file is simply a jar file that has the required WEB-INF directory inside of it.
Deploy this war file to your web server (Tomcat/JBoss/Jetty/Glassfish/etc.), the process for doing this is different for each web server
That is the basics of web application deployment. Your web server will extract the war file and load all of the jars in the lib folder into the classpath. It will then take any URL requests it receives and send them to the appropriate Servlet implementations declared in your deployment descriptor.
As you can see this is not a simple process. This is the reason tools like Appfuse and Roo exist. They try and give you a starting point which does all of this basic stuff for you. If you are having trouble I would suggest trying again from scratch with Appfuse/Roo. As you start to get the hang of things I would also suggest learning more about Maven (or Ivy+Ant) to handle dependencies for you.
You should download the Java EE edition of Eclipse - it contains the code needed to work with enterprise applications.
You will also need an enterprise server (like JBoss or Glassfish) and the corresponding server adapter, which is a bit much for a beginner.
The easiest way to get started is to download Netbeans with Glassfish and use that instead - at least for now - as everything is configured correctly and it is very fast to get started! When you are more familiar with the way things work, you can switch back to Eclipse if you want to.

How do I properly deploy and structure projects in Eclipse against Tomcat?

I am relatively new Java developer that's been thrown in the deep end, my usual skillset lies in Microsoft products and C#.
However I have managed to write a nice web service using Restlet and incorporating Toplink and doing some database CRUD stuff, etc etc.
I developed this in Eclipse against Tomcat 5.5. I followed tutorials and examples and managed to throw something together that works.
I had all my jar files in WebContent/WEB-INF/lib directory of my project - I soon realised that when I export this as a WAR file and deploy in Tomcat, it takes these jar files with it and stores them local to the application.
Fine, but then when you try to undeploy the app, it only does it partially as Tomcat "holds on" to some of the jars it was using i.e. the Oracle JDBC, and Toplink ones. This makes sense as the web service was using these jars as there was a live Oracle connnection going on.
So then I thought I should have all these jars in a common place where all deployed apps can access them, that folder I believe is:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib
(in my case). This made total sense, it's logical as you don't want loads of apps on Tomcat all referencing the same jars. So I removed all the jars out of my projects lib folder and put them in the common\lib directory.
Now my app will not work properly - it can't find my source code in src, the custom bespoke code that I have programmed against these jars. It will only work if I jar up my source code and put in the directory stated above. Odd.
I am obviously very confused with class paths and build paths and all of that stuff, and must have got this sort of stuff all wrong as I am no Java expert, as I readily admit I have pretty much hacked this together - so can anyone explain to me in laymans terms how I should structure my project to get it working with jars held in a common folder in Tomcat. Or are there any good resoureces on the web to help explain to me what I should do.
Hope this all makes sense...
Here is a pic of my current project:
Sounds like you are not using WTP web project.
If you've installed 'Eclipse IDE for Java EE Developers' flavor of Eclipse, the WTP is already bundled in there. Otherwise here its update site -> http://download.eclipse.org/webtools/updates
Once you've installed WTP you should create 'Dynamic Web Project'.
In general I would recomment to put only your presentation layer here ( JSPs, CSS, HTML ) and put all pure java projects into standard 'Java' project that you later add as a dependency to 'Dynamic Web Project'.
WTP can run your web application under a number of containers, fortunately Tomcat is supported.
You will need to configure it through Window->Preferences->Server->Runtime Environments.
Once runtime envirnonment is configured, you can create your server runtime:
Right click in 'Servers' view.
Choose New->Server
Select server type: 'Tomcat v.5.5 Server'
(Optional) Change server name to whatever makes sense for you
Select server runtime environment: This is the Runtime Environemtn that you have configured previously
Hit 'Next' button
Add your 'Dynamic Web Project' project to 'Configured projects:' panel
Hit 'Finish' button
After the server is configured you can just run it, or you can put it in Debug mode. All source code referenced by dependent projects will be available for debugging.
NOTE:
From personal experience, I would not recommend using common/lib. Put all the jars that your web application relies upon into its WAR file. If you are worried about dependency tracking then start looking into Maven and m2eclipse.
Usually I put my jars in $CATALINA_BASE/shared/lib/
Please read this documentation for more clarification and specially Class Loader Definitions section.
Also restart the server after you copied the jars.
Go to Window > Show View > Other > Server > Servers, a servers tab will appear below with console tab. Click on your server and then F3, this will open server configuration.
Check Server Locations, and make sure you checked Use tomcat installation(takes control of tomcat installation) then click Modules tab below and it will show your installed modules, make sure the module is present or add it.

Categories