Difference between revisions of "Tutorial Maven Spring"

From HaFrWiki
Jump to: navigation, search
(Created page with "{{TOCright}} Tutorials help the developer in exploring how application can be made. The tutorials here presented try to to do that too. The examples are from various parts of ...")
 
m (Hello World II)
Line 41: Line 41:
 
* Java JDK 1.7 or higher
 
* Java JDK 1.7 or higher
  
Step 1: Open Eclipse and Create Dynamic Web Project CrunchifySpringMVCTutorial.
+
===== Step 1: Open Eclipse and Create Dynamic Web Project CrunchifySpringMVCTutorial. =====
 +
{| class="wikitableharm" width="1150"
 +
|- style="vertical-align:top;"
 +
| width="575" | [[File:Eclipse-New-Dynamic-Web-Project.png|thumb|left|550px| 1. Open > New > Dynamic Wen Project]]
 +
Settings for the project (See right image)
 +
# Apache Tomcat v8.0
 +
# Dynamic wen module version: 3.1
 +
| width="575" | [[File:Crunch-DWP-010.png|thumb|left|550px| 2. Create a standalone Dynamic Web Project]]
 +
|}
  
  
  
<nowiki>[ToDo Finish this example with pictures and annotations.]</nowiki>
+
===== Step 2: Convert Project to a Maven Project =====
 +
Right click on the project and Choose
 +
{| class="wikitableharm" width="1150"
 +
|- style="vertical-align:top;"
 +
| width="550" | [[File:Crunch-DWP-020.png|thumb|Left|550px|3. Right click on the project and Choose...]]
 +
| width="550" | [[File:Crunch-DWP-030.png|thumb|Left|550px|4. Convert to Maven Project]]
 +
|}
 +
 
 +
===== Step 3: Add Spring Dependencies =====
 +
{| class="wikitableharm" width="1150"
 +
|- style="vertical-align:top;"
 +
| width="550" | [[File:Crunch-DWP-040.png|thumb|left|550px|5. Adding Maven dependencies]]
 +
| width="550" | [[File:Crunch-DWP-050.png|thumb|left|550px|6. Maven Dependencies]]
 +
|}
 +
 
 +
I have uodated the version to 4.1.5 release of Spring. Your POM file should look like:
 +
<pre>
 +
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 +
  <modelVersion>4.0.0</modelVersion>
 +
  <groupId>CrunchifySprintMVCTutorial</groupId>
 +
  <artifactId>CrunchifySprintMVCTutorial</artifactId>
 +
  <version>0.0.1-SNAPSHOT</version>
 +
  <packaging>war</packaging>
 +
  <build>
 +
    <sourceDirectory>src</sourceDirectory>
 +
    <plugins>
 +
      <plugin>
 +
        <artifactId>maven-compiler-plugin</artifactId>
 +
        <version>3.1</version>
 +
        <configuration>
 +
          <source>1.8</source>
 +
          <target>1.8</target>
 +
        </configuration>
 +
      </plugin>
 +
      <plugin>
 +
        <artifactId>maven-war-plugin</artifactId>
 +
        <version>2.4</version>
 +
        <configuration>
 +
          <warSourceDirectory>WebContent</warSourceDirectory>
 +
          <failOnMissingWebXml>false</failOnMissingWebXml>
 +
        </configuration>
 +
      </plugin>
 +
    </plugins>
 +
  </build>
 +
  <dependencies>
 +
  <dependency>
 +
  <groupId>org.springframework</groupId>
 +
  <artifactId>spring-context</artifactId>
 +
  <version>4.1.5.RELEASE</version>
 +
  </dependency>
 +
  <dependency>
 +
  <groupId>org.springframework</groupId>
 +
  <artifactId>spring-aop</artifactId>
 +
  <version>4.1.5.RELEASE</version>
 +
  </dependency>
 +
  <dependency>
 +
  <groupId>org.springframework</groupId>
 +
  <artifactId>spring-webmvc</artifactId>
 +
  <version>4.1.5.RELEASE</version>
 +
  </dependency>
 +
  <dependency>
 +
  <groupId>org.springframework</groupId>
 +
  <artifactId>spring-web</artifactId>
 +
  <version>4.1.5.RELEASE</version>
 +
  </dependency>
 +
  <dependency>
 +
  <groupId>javax.servlet</groupId>
 +
  <artifactId>jstl</artifactId>
 +
  <version>1.2</version>
 +
  </dependency>
 +
  <dependency>
 +
  <groupId>commons-logging</groupId>
 +
  <artifactId>commons-logging</artifactId>
 +
  <version>1.1.3</version>
 +
  </dependency>
 +
  </dependencies>
 +
</project>
 +
</pre>
  
  
 +
<nowiki>[ToDo Finish this example with pictures and annotations.]</nowiki>
  
 
== AJAX with Sprint MVC ==
 
== AJAX with Sprint MVC ==

Revision as of 18:57, 26 February 2015

Tutorials help the developer in exploring how application can be made. The tutorials here presented try to to do that too. The examples are from various parts of the Internet and are always presented with reference to the original side.

To understand the presented examples pre-required knowledge is necessary on:

  • Language Java JDK 1.8 and JEE
  • Build tool Maven (Version 3 or better)
  • IDE Eclipse (Luna or better)
    • with JEE
    • and m2eclipse Apache Maven plug-in.
  • Web Container Tomcat (8.0 or better)
  • Spring MVC
  • AJAX tool jQuery (1.8 or better)

Basic Maven Tomcat Deployment

Procedure will help you create a new web application using the m2eclipse Apache Maven plugin for Eclipse, and then deploy and run it on the Tomcat server defined in your Eclipse IDE [1].

  • In Eclipse, create a new Maven Project. File > New > Other... > Maven Project.
  • Accept the first Screen, choose Next
  • In the second Screen find and select the maven archetype called maven-archetype-webapp,

[ToDo Finish this example with pictures and annotations.]

Hello World

Tutorial for Spring MVC HelloWorld Using Maven in Eclipse [2].

Java developers often rely on examples to learn Spring framework. Simple examples are often a key learning resource. There are many Spring MVC HelloWorld applications. However, most of them are outdated (do not integrate Maven, use old version of Spring, etc) or not complete (missing key steps or file hierarchy view). All steps for creating a Spring MVC HelloWorld application using Maven in Eclipse are illustrated with as much details as necessary.

Prerequisite are installed versions of:

  • Java 7 or higher
  • Eclipse Kepler Java EE
  • Tomcat 7 or higher

[ToDo Finish this example with pictures and annotations.]

Hello World II

Tutorial of Crunchify [3] to create the most simple Hello World with the pre required tooling:

  • Tomcat 7.0.56 or Higher
  • Eclipse IDE Luna Service Release 1 v4.4.1 or higher (don'y forget the JEE
  • Spring 4.1.1 (No download required)
  • Java JDK 1.7 or higher
Step 1: Open Eclipse and Create Dynamic Web Project CrunchifySpringMVCTutorial.
1. Open > New > Dynamic Wen Project

Settings for the project (See right image)

  1. Apache Tomcat v8.0
  2. Dynamic wen module version: 3.1
2. Create a standalone Dynamic Web Project


Step 2: Convert Project to a Maven Project

Right click on the project and Choose

3. Right click on the project and Choose...
4. Convert to Maven Project
Step 3: Add Spring Dependencies
5. Adding Maven dependencies
6. Maven Dependencies

I have uodated the version to 4.1.5 release of Spring. Your POM file should look like:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>CrunchifySprintMVCTutorial</groupId>
  <artifactId>CrunchifySprintMVCTutorial</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-context</artifactId>
  		<version>4.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-aop</artifactId>
  		<version>4.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-webmvc</artifactId>
  		<version>4.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-web</artifactId>
  		<version>4.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>javax.servlet</groupId>
  		<artifactId>jstl</artifactId>
  		<version>1.2</version>
  	</dependency>
  	<dependency>
  		<groupId>commons-logging</groupId>
  		<artifactId>commons-logging</artifactId>
  		<version>1.1.3</version>
  	</dependency>
  </dependencies>
</project>


[ToDo Finish this example with pictures and annotations.]

AJAX with Sprint MVC

[4]

See also

top

Reference

top

  1. Base22, How to make a Maven web app with Tomcat, by
  2. Program Creek, Spring MVC HelloWorld Using Maven in Eclipse, by X Wang.
  3. Cruchify , Simplest Spring MVC Hello World Example / Tutorial – Spring Model – View – Controller Tips
  4. Cruchify, How to use AJAX, jQuery in Spring Web MVC (.jsp),