[JAVA] Spring5 MVC Web application development with Visual Studio Code Maven template creation

Introduction

Please refer to here for environment construction.

I couldn't find a way to create a Java 11 project directly, so I'll create a Java 8 project first. After creating, change to Java 11 settings.

environment

OS:Windows 10 Pro 64bit Editor:Visual Studio Code 1.42.1 JDK:AdoptOpenJDK 11.0.6+10 x64 Apache Maven:v3.6.3

Creating a template

I think that you can also enter the command of Visual Studio Code, but this time I will create it by entering the command at the command prompt. Open a command prompt and move to the folder where you want to create the template. This time, create it in "D: \ JAVA \ Project".

mvn archetype:generate -DinteractiveMode=false -DarchetypeGroupId=pl.org.miki -DarchetypeArtifactId=java8-quickstart-archetype -DgroupId=com.example -DartifactId=hello -Dversion=1.0-SNAPSHOT -Dpackage=com.example -Dpackaging=jar

Line breaks for readability.

mvn archetype:generate
 -DinteractiveMode=false
 -DarchetypeGroupId=pl.org.miki
 -DarchetypeArtifactId=java8-quickstart-archetype
 -DgroupId=com.example
 -DartifactId=hello
 -Dversion=1.0-SNAPSHOT
 -Dpackage=com.example
 -Dpackaging=jar

The places to be specified arbitrarily are as follows. -DgroupId It will be the group ID. It is for identifying the creator, company, organization, etc.

-DartifactId It will be the artifact ID. I think it can be called the project name.

-Dversion You can specify the version. Unless you are particular about it, I think "1.0-SNAPSHOT" is fine.

-Dpackage The basics are the same as "-DgroupId".

D:\JAVA\Project>mvn archetype:generate -DinteractiveMode=false -DarchetypeGroupId=pl.org.miki -DarchetypeArtifactId=java8-quickstart-archetype -DgroupId=com.example -DartifactId=hello -Dversion=1.0-SNAPSHOT -Dpackage=com.example -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.1.2:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.1.2:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.1.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] Archetype [pl.org.miki:java8-quickstart-archetype:1.0.0] found in catalog remote
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: java8-quickstart-archetype:1.0.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.example
[INFO] Parameter: artifactId, Value: hello
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.example
[INFO] Parameter: packageInPathFormat, Value: com/example
[INFO] Parameter: compilerMode, Value: simple
[INFO] Parameter: package, Value: com.example
[INFO] Parameter: groupId, Value: com.example
[INFO] Parameter: testLibrary, Value: junit
[INFO] Parameter: artifactId, Value: hello
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Project created from Archetype in dir: D:\JAVA\Project\hello
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.255 s
[INFO] Finished at: 2020-03-08T15:28:02+09:00
[INFO] ------------------------------------------------------------------------

It is created with such a folder structure.

D:.
└─src
    ├─main
    │  └─java
    │      └─com
    │          └─example
    └─test
        └─java
            └─com
                └─example

Changes to pom.xml

Change java.version to 11.

Change before


<java.version>1.7</java.version>

After change


<java.version>11</java.version>

I like war for packaging, so change it to war.

Change before


<packaging>jar</packaging>

After change


<packaging>war</packaging>

This is the modified pom.xml.

pom.xml


<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
	<artifactId>hello</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>war</packaging>

 
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>11</java.version>
	</properties>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
</project>

Summary

This completes the template creation.

Reference / Exhibition

Create a Java 8 project with Maven https://qiita.com/mkamotsu/items/98c6d721a87a74f2b36f

Recommended Posts

Spring5 MVC Web application development with Visual Studio Code Maven template creation
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 2/3 [Page creation 1/2]
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 3/3 [Page creation 2/2]
Spring5 MVC Web App Development with Visual Studio Code Hello World Creation
Spring5 MVC web application development with Visual Studio Code SQL Server connection
Spring Boot2 Web application development with Visual Studio Code Hello World creation
Spring5 MVC Web application development with Visual Studio Code Environment construction (Installation of JDK11, Maven, Tomcat, Visual Studio Code)
Spring Boot2 Web application development with Visual Studio Code SQL Server connection
Build WebAPP development environment with Java + Spring with Visual Studio Code
Start web application development with Spring Boot
Build Java program development environment with Visual Studio Code
[Spring Boot] Web application creation
Java web application development environment construction with VS Code (struts2)
Use PlantUML with Visual Studio Code
Inquiry application creation with Spring Boot
Web application creation with Nodejs with Docker
Run WEB application with Spring Boot + Thymeleaf
A record of setting up a Java development environment with Visual Studio Code
I tried printing a form with Spring MVC and JasperReports 2/3 (form template creation)
Introduction to Java development environment & Spring Boot application created with VS Code
Experience .NET 5 with Docker and Visual Studio Code
Configure Spring Boot application with maven multi module
[Jakarta EE 8 application development with Gradle] 2. Project creation
Getting started with Java programs using Visual Studio Code
Why can I develop Java with Visual Studio Code?
Roughly the flow of web application development with Rails.
[Oracle Cloud] Create a development environment for OCI Java SDK (Visual Studio Code, Maven, CentOS)
Web application development memo with MVN, Tomcat, JSP / Servlet with VScode
To receive an empty request with Spring Web MVC @RequestBody
Web application development article summary
Java in Visual Studio Code
Web application built with docker (1)
Comparison of WEB application development with Rails and Java Servlet + JSP
How to use PlantUML with Visual Studio Code (created on October 30, 2020)
Let's make a book management web application with Spring Boot part1
Let's make a book management web application with Spring Boot part3
I tried connecting to MySQL using JDBC Template with Spring MVC
Let's make a book management web application with Spring Boot part2
[Probably the easiest] WEB application development with Apache Tomcat + Java Servlet
What I learned from doing Java work with Visual Studio Code