[JAVA] [Note] Struts2 environment construction using Gradle in Eclipse


Build an environment for Struts2 with the Gradle project in Eclipse. (For some reason, I got a prefix = "s" related error from the dynamic web project and it didn't work, so I used the Gradle project)


** ① Create a Gradle project. ** ** The project name is appropriate (Struts2_gradle in this case), and click the "Finish" button. SnapCrab_新規 Gradle プロジェクト_2017-6-18_9-14-40_No-00.png

** ② Make the folder structure of the dynamic project. ** ** Right-click the created Struts2_gradle → click "Properties". Click "Project Facets" from the list on the left, then click "Convert to Facet Form ...". Check "Dynamic Web Module" and click "OK". SnapCrab_Struts2_gradle のプロパティー_2017-6-18_9-19-33_No-00.png

** ③ Rewrite build.gradle. ** ** Rewrite "build.gradle" existing in Struts2_gradle project as follows.


 * This build file was auto generated by running the Gradle 'init' task
 * by 'nobu' at '17/06/18 8:36' with Gradle 2.14.1
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/2.14.1/userguide/tutorial_java_projects.html

// Apply the java plugin to add support for Java
apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.

// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.21'

    // Declare the dependency for your favourite test framework you want to use in your tests.
    // TestNG is also supported by the Gradle Test task. Just change the
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
    // 'test.useTestNG()' to your build script.
    testCompile 'junit:junit:4.12'
    compile "org.apache.struts:struts2-core:"
    compile "javax.servlet:javax.servlet-api:3.1.0"

task copyDependencies(type:Copy) {
    copy {
        from configurations.runtime
        into 'WebContent/WEB-INF/lib'

** ④ Add the library. ** ** Right-click on the Struts2_gradle project → click “Gradle” → click “Refresh Gradle Project”.

** ⑤ Create a folder / file as shown below. ** **

Folder structure

├── build.gradle
├── src
│   └── main
│       └── java
│           └── com
│               └── tutorialspoint
│                   └── struts2
│                       └── HelloWorldAction.java
└── WebContent
    ├── HelloWorld.jsp
    ├── index.jsp
    └── WEB-INF
        ├── logging.properties
        ├── web.xml
        └── classes
            └── struts.xml

** ⑥ Rewrite the contents of the file. ** **


package com.tutorialspoint.struts2;

public class HelloWorldAction {
	private String name;

	public String execute() throws Exception {
		return "success";

	public String getName() {
		return name;

	public void setName(String name) {
		this.name = name;


<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<title>Hello World</title>
Hello World, <s:property value="name"/>


<%@ page language="java" contentType="text/html; charset=UTF-8"
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
	<h1>Hello World From Struts2</h1>
	<form action="hello">
		<label for="name">Please enter your name</label><br/>
		<input type="text" name="name" />
		<input type="submit" value="Say Hello" />


org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = \


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
id="WebApp_ID" version="3.0">


<?xml version="1.0" encoding="UTF-8"?>
	"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
	"http://struts.apache.org/dtds/struts-2.0.dtd	">
<constant name="struts.devMode" value="true" />
	<package name="helloworld" extends="struts-default">
		<action name="hello"
				<result name="success">/HelloWorld.jsp</result>

** ⑦ Execute the project. ** ** Right-click Struts2_gradle → click "Run" → "Run on Server". Then the following screen will appear. SnapCrab_Hello World - Google Chrome_2017-6-18_9-42-59_No-00.png

[WAR file]

I uploaded the WAR file of the project created this time to GitHub. GitHub_nobu1234(Struts_gradle)

[Reference site]

tutorialspoint_Struts2 → Contents of Java file and xml file Try Struts2 (1) → Add Struts2 library to build.gradle Copy the dependent library with Gradle → How to add the library to WEB-INF / lib [Note!] Make a WAR with Gradle → Add servlet-api to build.gradle due to Servlet related error in jsp file

Recommended Posts

[Note] Struts2 environment construction using Gradle in Eclipse
[Environment construction] Eclipse installation
Allow development in Eclipse environment using iPLAss SDK
[Java] Environment construction procedure for developing struts 1.3 with Eclipse
JavaFX environment construction in Java 13
Using Amateurs UML in Eclipse
Java development environment construction (Mac + Pleiades All in One Eclipse 4.7 + Spring Boot + Gradle (Buildship))
◆ Spring Boot + gradle environment construction memo
Building a Lambda development environment in Eclipse
Rails API server environment construction using docker-compose
Batch implementation in RubyOnRails environment using Digdag
Run jooby's Eclipse development environment on Gradle
[Note] Execute java program in the integrated development environment Eclipse-I tried using git
[For beginners] I tried using DBUnit in Eclipse
[For beginners] I tried using JUnit 5 in Eclipse
Environment construction procedure for using PowerMock with JUnit
[Rails] Run LINEBot in local environment using ngrok
Kaggle environment construction using official Docker and vscode
[Ubuntu 18.04] Environment construction for using PyTorch with RTX3090
Prepare for log output using log4j in Eclipse.
Development environment construction using IntelliJ IDEA + Maven + Tomcat 9
Resolve "Cannot resolve symbol" in IntelliJ projects using Gradle
Support out of support in docker environment using centos6
Django development environment construction using Docker-compose (personal memorandum)
Tips for generating files for eclipse projects in Gradle
I stumbled when I tried using neo4j in the jenv environment, so make a note
[Java] Environment construction
Java environment construction
MVC in Eclipse.
[Spring] Environment construction
Docker environment construction
[LeJOS] Let's program mindstorm-EV3 in Java [Environment construction part 2]
[Mac] VS Code development environment construction (Java, Gradle, Node.js)
Automatically generate DDL using [jpa-schema-gradle-plugin] plugin in Spring × Gradle
[Note] Build a Python3 environment with Docker in EC2
Until building Spring-Boot using Eclipse on Mac (Gradle version)
Ruby on Rails environment construction using VirtualBox, Vagrant, cyberduck
Database environment construction with Docker in Spring boot (IntellJ)
Construction of data analysis environment using Docker (personal memorandum)