Making / Deploying War file from Eclipse web project - java

I don't know if some one asked this but I have a problem that I am working on this tutorial Hello World Example with annotation driven Spring 3 MVC in Eclipse .Now I am very embarrassed to say that how can I make war file to deploy on tomcat. Please guide me in this regard. Thank you
P.S: Just to inform you that I have Tomcat 6.0 and eclipse indigo 3.7

You have many options depending on the environment you're using; the more simple ways can be:
for testing purpose you can reference a Tomcat installation inside your Eclipse in the Severs tab of the J2EE perspective and add your Dynamic Web Project to it; then you can control (start/stop/debug) your server from Eclipse
to build a war to deploy, you can right click the Dynamic Web Project and choose Export War File

I would recommend using Apache Maven as it will help you much as you project will get bigger and your will have a lot of dependencies. You can try it as Eclipse plugin (m2eclipse) or use it from command line.

Related

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 happens behind the scenes of deploying a Spring MVC application to tomcat outside of eclipse?

I guess a drawback of using such an awesome IDE like eclipse is that you miss the point for what happens behind the scenes of an application. I'm a ruby developer so not a java veteran. So I've been coding a project in java and using the spring framework for IOC and MVC. Can someone explain to me what is going on when I select run on server in eclipse? Because eventually I will be deploying this masterpiece of an application to a Linux server. Here is my setup. I am using Spring MVC 3 and the maven plugin in eclipse. In the pom.xml file, I have stuff like latest spring release version, log4j, spring mvc, spring context etc.
I have been testing my application on localhost using the handy option of run on server in the eclipse IDE. The server configuration in eclipse is pointing to the tomcat directory location for where I have installed tomcat 7. Please demystify what happens behind the scenes and what I will need to do if I want to deploy this application on a production server. The more detail the better. Thanks a ton in advance.
Deploying a web application to Tomcat is as simple as this (assuming Tomcat is installed)
Bundle your application in a .war with the correct format.
Move the generated .war file to the /webapps directory of your Tomcat installation folder.
Run the /bin/startup.[sh|bat] script in the Tomcat installation folder.
Note that there are intermediate steps you can do to configure the deployment, like changing your context path. Go through the Tomcat documentation for details.
In step 3, Tomcat will extract the .war contents to a directory in the /webapps folder with the same name as your .war file. It will use this as the context path. The script itself launches a java process by putting the WEB-INF/[class|lib|...] onto the classpath along with some Tomcat libraries.
So Eclipse basically does all the steps above for you.
Ultimately you are deploying an web application that means you are deploying a war file to the server. Regardless of using frameworks like spring, struts anything.
SO a web application request starts from web.xml file. SO for spring mvc application, you are mapping all request coming from browser to DispatcherServlet and then this guy is responsible to manage whole life cycle of your application.
For more details of how MVC works please see
http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html
So in order to deploy your application (a war) on server first of all you have to create a war from your source code. You can go to traditional approach to use java given utility like using jar from command prompt or you can use ANT, GRADLE, MAVEN and such build tool that creates war for you in automated way.
Spring is not doing anything extra for you. I believe you to research a bit more on how these tools works.
Once a war is ready for you, you can simply go to tomcat UI and there you will find options to deploy your war.
I hope it helps you.
All the majic happens in two places.
The first is your 'Servers' directory in the root of your Eclipse Package Explorer. These are your server configuration files that Eclipse will use (mostly) when it creates a new server instance.
The second is in the ./metadata/.plugins/org.eclipse.wst.server.core/ file system directory in your Eclipse workspace. This is where the tomcat application is actually deployed by eclipse.
The Tomcat Documentation is pretty good actually and helps explain how to do deployments. FYI, I do not know many people that use the Manager, from my experience most people deploy their applications by hand.

Run spring project in eclipse

I am new in spring.I imported one spring project in eclipse and try to run with apache tomcat but it is not running.There is no main method in project.It contains only controllers and models and one jsp page.When i tried to run as a java application is shows below dialog. Please help me.I tried all in google for how to run spring project but i can't understand.Please tell me how to do?
Assuming you have added tomcat to your eclipse.
If your project is pure java project then it will not show you the run on server option in eclipe. You need to change project facet and add dynamic web module to it then you can run it on tomcat server from eclipse.Basically project needs to be web project.
After doing above if it gives error or do not run properly, check your project deployment assembly and add projects webapps folder in eclipse.
you need to have a tomcat installed in your eclipse and run it on the server.
Here is a tutorial to do this
You need to install the Web Tools Platform, which has support for the usual Web-application tools.

How to setup a jboss seam build with Maven that includes downloading and configuring the server?

I have a jboss(5.1.0.GA)/seam(2.2.0.GA) app that gives me a lot of work everytime I need to setup a development environment for it.
What I want is to port the build to maven, and have it setup all the development environment for me(including downloading and configuring the AS).
How could I acomplish something like that? Currently the build is managed by eclipse and has a default java ee project structure(projects for ear, ejb and jsf) so a simple example of porting an eclipse java ee project to maven with the above requeriments will suffice.
I found these two posts which can explain how you can use seam-gen and convert it to use maven.
This might be helpful for you.
Post 1 and Post 2

In IDEA, I setup to deploy using web app exploded, how do to .war file?

Using IDEA and tomcat I setup a simple spring mvc app (thanks to you guys) and it was deploying using a 'web app exploded' format.
Is a .war file the same thing, except in a single file appname.war?
How can I configure IDEA to do this?
how do I have IDEA make a .war file during compilation and/or deployment?
how do I link this to tomcat?
when tomcat runs, how does it point to my output and where does it configure my app to run?
It depends on the IntelliJ IDEA version you are using.
Usually in the same screen where you setup the exploded directory, you can setup to generate a WAR file too - just need select that checkbox.
With IntelliJ IDEA 9.x however, a new configuration was introduced called "Artefacts" - it is much more flexibile, but for me it was not as intuitive as the old solution.
Here is a small article about this "Artefact" new feature, but you can read more about it directly from the IntelliJ online help.
If you want to control tomcat form inside IntelliJ (e.g. practical when developing), than you need to add in the project configuration a new Facet - the Tomcat Facet. That way you can specify in that screen the deployment mode.

Categories