Creating spring project clone it with GIT step by step.
01.Create an empty GIT
repository and select a repository name.
02. Check to add README.md and technology
to add it inside the gitignire file0- it will include all the generated class
when we complete the application.
03. Copy the github repository URL.
04.Open eclipse and go to, Window – Show View – Other - Type
git on the folder and select git repositories.
05. Now clone this repository at your desired location in which we are going to keep the project specific file.
a) a) Step One.
b) Step Two.
c) Step Three.
Both projects are generated as bellows
d) Step Four
Open the gitingnore file and ignore the target
folder of the project. All the class files which are generate with compile the
code are store in target folder. Class file can be generated. Because of that
we don’t commit that folder to git.
e) Step Five
Open window – preference –
filter for git configuration select it then add two entries if it is not
present.
Click on the add entry
Key – user.name
Value – your name
Click on the add entry
Key – user.email
Vslue – your emil
f) Step Six
Right click on the repository
and select Commit – Git Staging view. Select all the files in the unstages
change and drag it to the stage changes
Enter your commit message
.Click on Commit and Push. It will ask for your credentials enter your
github account username and password.
g) Step Seven
Solving archetype related problems. This happen
because of the incomplete downloads. So, go to and delete, then re-build
project.
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
h) Step Eight
Fixed bellow error –
the superclass javax.servlet.http.httpservlet was
not found on the java build path
In the Web, Java EE API should
be added. Add it to pom.xml (project object model)
<!-- Version information will be stored here -->
<properties>
<javaee.version>7.0</javaee.version>
</properties>
<dependencies>
<!-- JAVA EE -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee.version}</version>
<dependency>
</dependencies>
i) Step Nine
Add this to pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<finalName>assignment</finalName>
</build>
After adding, right click on
the project – maven – update project – OK.
Then has changed.
j) Step Ten
Bellow error also can be seen
Go and search web.xml mkyong and copy and paste
bellow code.
Then right click on the project – properties –
project facets – uncheck dynamic web module (ensure java version is the version
you have) ok and after right click on project – maven – update project.
k) Step Eleven
Adding Spring dependency.
<properties>
<spring.version>4.3.6.RELEASE</spring.version>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
spring-webmvc depend on -> spring-web depend on -> spring-context depend on -> spring-core depend on - spring-core
bean
l) Step Twelve
Configure the front controller
In the web.xml add bellow configuration
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Archetype Created Web Application</display-name>
<!-- Configure front controller -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
m) Step Thirteen
Create a new xml file with name
dispatcher-servlet.xml : right click
on WEB-INF and create it.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
<context:component-scan base-package="com.lahiru.controller"/>
<context:component-scan base-package="com.lahiru"/>
<beanid="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- max upload size in bytes -->
<property name="maxUploadSize" value="20971520"/><!-- 20MB -->
<!-- max size of file in memory (in bytes) -->
<property name="maxInMemorySize" value="1048576"/><!-- 1MB -->
</bean>
<!-- Loading static resources -->
<mvc:resources location="/assets/"mapping="/resources/**"/>
<mvc:annotation-driven/>
</beans>
n) Step Fourteen
a) o) Step Fifteen
Adding JSTL dependency
<!-- JSTL -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
Pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lahiru</groupId>
<artifactId>assignment</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>assignment Maven Webapp</name>
<url>http://maven.apache.org</url>
<!-- Version information will be stored here -->
<properties>
<javaee.version>7.0</javaee.version>
<spring.version>4.3.6.RELEASE</spring.version>
<hibernate.version>5.2.7.Final</hibernate.version>
</properties>
<dependencies>
<!-- JAVA EE -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee.version}</version>
<scope>provided</scope>
</dependency>
<!-- JUNIT -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- SPRING -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.6.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
<!-- JSTL Dependency -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jackson2-provider -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>3.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<finalName>assignment</finalName>
</build>
</project>
d)
In the page, we have to do
bellow configuration.
Add mvc name space. Configure
to load static resourse. Add spring tag library. Create three variable name
css, js and images using spring:url element. Replace the css, ja and image path
with the variable name.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:url var="css" value="/resources/css" />
<spring:url var="js" value="/resources/js" />
<spring:url var="images" value="/resources/images" />
<c:setvar="contextRoot" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>HOTEL SYSTEM</title>
<!-- Bootstrap core CSS -->
<link href="${css}/bootstrap.min.css" rel="stylesheet">
<!-- MyTheam -->
<link href="${css}/bootstrap-readable-theme.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="${css}/myapp.css" rel="stylesheet">
</head>
<body>
</body>
</html>
Comments
Post a Comment