views:

48

answers:

3

So I downloaded a trial of idea ultimate, and I want to get spring mvc going with tomcat.

So I setup a new project, configured it to use sun jdk.

I chose a spring application, and it created and downloaded the following:

http://img15.imageshack.us/img15/4853/idealspring1.png

I don't see any spring-mvc libraries, are they included in there or do I have to do something about that?

Can someone outline what I have to do to get this to build like a spring mvc web application?

A: 

I'm not sure if your setup would be identical to mine, but when I downloaded spring-framework-2.5.6 there were jar files named spring-web.jar, spring-webmvc.jar, etc. in the \dist\modules subfolders. The tutorial indicated at least spring-webmvc.jar should be in your WEB-INF/lib folder.

This tutorial optionally used eclipse, but might be helpful anyways, especially getting started:

http://static.springsource.org/docs/Spring-MVC-step-by-step/

Jake
A: 

I think there are specific JARs for the Spring MVC stuff. Basically when you download the latest Spring Framework and you extract the zip you need to go to the dist folder and add the org.springframework.web.jar and org.springframework.web.servlet.jar/org.springframework.portlet.jar to your project. I'm pretty sure that the servlet/portlet jars will have your MVC specific classes.

tkeE2036
+1  A: 

I find that the best way to start a new IDEA project is to use the Maven. This allows you to easily build your project without launching the IDE, automatically maintaining all libraries for you.

"Create project from scratch", then select "Maven module" in the next screen. Click on "Create from archetype" and select the "maven-archetype-webapp". This will give you a basic Maven layout which builds a simple WAR file.

Now to add the Spring libraries, open the Maven build file - pom.xml - and insert a new dependency on the Spring MVC framework:

   <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.0.0.RELEASE</version>
    </dependency>

From here, you can follow the Spring MVC reference documentation - add the Dispatcher Servlet and Context Listener to web.xml, a Spring XML context and so on.

Something else you might find useful is the Maven Jetty plugin. Once configured, you can run your app by simply typing "mvn jetty:run" at the command prompt (or launching it from within the IDE). Maven will fetch all that's required and deploy the app for you, no need for an external app server setup for quick testing.

Pavel
so will hitting 'Run' automatically build and deploy or there is some setup there? what about facets/artifacts and module setup?
Blankman
IDEA will automatically detect the "Web app" facet at first, and then the "Spring app" facet when you create an application context. It won't create a deployment for you out of the box, but running "mvn package" will give you a deployable war file. You can configure a Run/Debug configuration for Tomcat in IDEA and add the war module as one of the deployed artifacts. Every time you build it, IDEA will offer to redeploy it for you.
Pavel
I hate how that message about the facet appears, and then disappears in 1 second! Ok so how do I link the .war file with Tomcat? I have configured tomcat already. thanks!
Blankman
Don't worry if you miss the facet notification, just open the Project Structure dialog (Ctrl+Alt+Shift+S) and you will find all the modules plus all their facets under "Modules". If you highlight a specific module, you can manually add a facet using the little "+" button at the top.To deploy your new war into Tomcat, open the Run/Debug Configurations dialog, navigate to your Tomcat instance, and select the Deployment tab. You should see a list of artifacts, e.g. "war" and "war exploded" - pick one, select a deployment path, and hit Apply. When you run Tomcat IDEA will deploy the app for you.
Pavel