Create a tomcat project using Eclipse Pleiades All in One

Introduction

Overview

Operating environment

Development environment construction: Eclipse installation

Eclipse Pleiades All in One is compatible with Eclipse in Japanese and includes software required for Java Servlet development such as JDK and Tomcat. First, download and launch Eclipse Pleiades All in One and install Tomcaat Plagin.

  1. Go to the following Pleiades (a tool for Japaneseizing Java apps) site and click "Eclipse 2020". ⇒ Moves to the page where the list of "Download" buttons is lined up. https://mergedoc.osdn.jp/

  2. Click the "Download" button on the combination of "Windows 64bit", "Full Edition" and "Java". ⇒ pleiades-2020-06-java-win-64bit-jre_20200702.zip will be downloaded.

  3. When the download is complete, unzip it to any folder and double-click eclipse \ eclipse.exe to start Eclipse. (You will be required to enter the workspace folder path at startup, but leave the default settings.)

  4. Execute the Eclipse main menu "Help"> "Eclipse Marketplace" to launch the "Eclipse Marketplace" dialog.

  5. In the "Search" field, enter "Tomcat" and press the "Go" button.

  6. Select "Eclipse Tomcat Plugin 9.1.4" and press the "Install" button.

  7. Select "I accept the terms of the Terms of Use" and press the "Finish" button.

  8. When the Certificate Dialog "Do you trust these certificates?" Is displayed, check the certificate issuer and press the "Accept Selection" button.

  9. After restarting Eclipse, the Tomcat icon will appear in the menu in addition to the Eclipse main menu icon.

Eclipse initial settings

Initialize Eclipse before creating a project. If you set it once at the beginning, you do not need to set it from the next time.

  1. Execute "Window"> "Settings" in the main menu to start the "Settings" dialog.

  2. First, set up Tomcat. Select "Tomcat" from the tree on the left.

  3. Set the Tomcat folder in the "Tomcat" home. (Set "tomcat \ 9" under the folder where you unzipped pleiades-2020-06-java-win-64bit-jre_20200702.zip.)

  4. Check "Server.xml" in "Context declaration mode" and set the path of Server.xml in the "Configuration file" field. (Set "tomcat \ 9 \ conf \ server.xml" under the folder where you unzipped pleiades-2020-06-java-win-64bit-jre_20200702.zip.)

  5. Press the "Apply" button.

  6. Next, assume that the environment you are deploying to is Linux, and configure it to run on Linux. Select General> Workspace from the tree on the left.

  7. Under Text File Encoding, check Other and select UTF-8.

  8. Under New Text File Line Delimiter, check Other and select Unix.

  9. Press the "Apply" button.

  10. Press the "Apply and Close" button.

Project creation

When creating a new project and setting Server.xml.

  1. Execute the main menu "File"> "New"> "Project" to launch the "New Project" dialog.

  2. Click the Java> Tomcat Project node in the tree.

  3. Enter the "Project Name" and click the "Next" button.

  4. Check the path in the "Context Name" field and press the "Finish" button. (The path in the "Context name" field is the root part of the URL path when accessing the WEB server.) http: // localhost: 8080 / {path in the" context name "field}

  5. Confirm that the following line is added to "conf \ server.xml" under the Tomcat installation folder. If this line is not registered in Server.xml, the WEB screen will not be displayed even if you access the WEB server. ([Example] C: \ apache \ apache-tomcat-9.0.37 \ conf \ server.xml)

~~~
  1. By default, it is set to use port 8080. If you want to set other than port 8080, change the following part.

<Connector port = "8080" protocol = "HTTP / 1.1" ★ Change the "8080" part to the port number you want to set. connectionTimeout="20000" redirectPort="8443" useBodyEncodingForURI="true" /> ~~~

Servlet creation

Implements Servlet processing.

  1. Select the top node of the tree on the Package Explorer, right-click and click New> Class in the pop-up menu.

  2. Enter the class name in the "Name" field and "javax.servlet.http.HttpServlet" in the "Superclass" field, and click the "Finish" button. (Here, enter "SampleServlet" in the "Name" field, and leave the settings other than the "Name" field and "Superclass" field as default.) ⇒ "sample"> "SampleServlet.java" node is added to the tree on "Package Explorer".

    package sample;
    
    import javax.servlet.http.HttpServlet;
    
    public class SampleServlet extends HttpServlet {
    
    }
    
  3. Select the tree node "SampleServlet.java" on the "Package Explorer" and click "Source"> "Method Override / Implementation" on the main menu to launch the "Method Override / Implementation" dialog. ..

  4. Check "HttpServlet"> "doGet" and press the "OK" button to generate doGet () and doPost (). doGet () works when it receives a GET method. The GET method operates when the WEB server is accessed from the client's WEB browser. Also, doPost () works when it receives a POST method. The POST method works when data is sent from the client's web browser form to the web server.

    package sample;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class SampleServlet extends HttpServlet {
    
    	@Override
    	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    

// TODO auto-generated method stub super.doGet(req, resp); }

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

// TODO auto-generated method stub super.doPost(req, resp); }

}
~~~
  1. Add the following import process.

    package sample;
    
    import java.io.IOException;
    

import java.io.PrintWriter; // Add ~~~

  1. Modify the implementation of doGet () as follows. I am creating a web page that is displayed on the client's web browser when the client accesses the web server.

    	@Override
    	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    

// TODO auto-generated method stub //super.doGet (req, resp); // Comment out

// ↓ Add from here // Perform character encoding to prevent garbled Japanese characters resp.setContentType("text/html; charset=UTF-8");

// Create a web screen to be displayed on the client's web browser PrintWriter out = resp.getWriter(); out.println(""); out.println(""); out.println("sample"); out.println(""); out.println(""); out.println ( "

Hello Hello </ h1>"); out.println(""); out.println(""); out.close(); // ↑ Add up to here } ~~~

web.xml creation

Create web.xml. web.xml is a file that configures the Servlet container.

  1. Select the tree node "WEB-INF" on "Package Explorer", right-click and click the pop-up menu "New"> "Other" to launch the "New" dialog.

  2. Click XML> XML File to launch the New XML File dialog.

  3. Enter "web.xml" in the "File name" field and click the "Finish" button. ⇒ A tree node "web.xml" is added on "Package Explorer".

  4. Select the tree node "web.xml" on "Package Explorer", right-click and click the pop-up menu "Open Next"> "General Text Editor".

    <?xml version="1.0" encoding="UTF-8"?>
    
  5. Add the following code to web.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    
    

<!-↓ Add from here-> sample sample.SampleServlet

	<servlet-mapping>
		<servlet-name>sample</servlet-name>					<!-- Servlet name -->
		<url-pattern>/servlet</url-pattern>					<!-- URL pattern -->
	</servlet-mapping>
</web-app>

<!-↑ Add up to here-> ~~~

Build

For builds, enable automatic builds so that they build automatically.

  1. Select the top node of the tree on the Package Explorer, right-click and click Refresh on the pop-up menu. ⇒ The file structure of the tree on "Package Explorer" is automatically updated to the current state.

  2. Select the top node of the tree on the Package Explorer, right-click and click the pop-up menu Build Project to build.

  • If you check "Project"> "Build automatically" in the main menu, it will be built automatically and this pop-up menu will disappear.

Run

Run it when you can build it. First, use Eclipse to start a web server on Windows and access it from a web browser.

  1. Click the icon "Restart Tomcat" on the main menu.

  2. When you start the browser and access the following URL, the client sends the GET method to the server and the following WEB page is displayed. http://localhost:8080/sample/sevlet

debug

If you want to debug, do the following:

  1. Right-click and click the pop-up menu "Switch Breakpoints" to set a breakpoint and press F8 (Run).

  2. Start your browser and access the following URL to break at the location where you set the breakpoint. You can also step out with the F6 key and step in with the F5 key. http://localhost:8080/sample/sevlet

WAR file creation

Create a WAR file (a collection of files necessary for the operation of the WEB application) to deploy (make it available).

  1. Click Project> Properties on the main menu to launch the Properties dialog.

  2. Select the tree node "Tomcat", open the "WAR Export Settings" tab, and press the "Browse" button to launch the "Open" dialog.

  3. Enter the WAR file name to be saved in the "File name" field and click the "Open" button.

  4. When the path of the WAR file to be saved is reflected in the "WAR file to export" field, click the "Apply and close" button.

  5. Select the top node of the tree on "Package Explorer", right-click and execute "Tomcat project"> "Create WAR file according to project settings".

  6. A WAR file will be generated in the path set in the "WAR file to export" field.

Export project

Make a backup of your project before deleting it.

  1. Stop Tomcat.

  2. Select the top node of the tree on the Package Explorer, right-click and click the pop-up menu Export to launch the Export dialog.

  3. Select General> File System and press the Next button.

  4. Check the check box of the project.

  5. Enter the export destination path in the "Destination Directory" field and click the "Finish" button.

Delete project

Delete the project and delete the settings in Server.xml.

  1. Stop Tomcat.

  2. Select the top node of the tree on the Package Explorer, right-click and click the pop-up menu Delete to launch the Delete Resource dialog.

  3. Check "Delete project content from disk (irreversible)" and click the "OK" button.

  4. When the Remove Project Context Definition from Server.xml dialog opens, press the OK button.

Project import

When importing a project, import the backed up project.

  1. Create a project according to the "Create project" item.

  2. Select the top node of the tree on the Package Explorer, right-click and click the pop-up menu Insport to launch the Insport dialog.

  3. Select General> File System and press the Next button.

  4. Check the check box of the project.

  5. Enter the import destination path in the "From the following directory" field and click the "Finish" button.

  6. When asked "Are you sure you want to overwrite?", Select "No All".

Deployment environment

From here, prepare for deployment. Here, we will deploy to Ubuntu.

  • Ubuntu 20.04 LTS
  • OpenJDK 11
  • Tomcat 9

Deployment environment construction ①: OpenJDK 11 installation

First, install Java.

  1. Install OpenJDK 11.

    $ sudo apt-get install openjdk-11-jdk
    
  2. Check the Java version you have installed.

$ java --version openjdk 11.0.8 2020-07-14 OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04) OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing) ~~~

Deployment environment construction ②: TOMCAT installation

Then install TOMCAT.

  1. Access the following site and click "Tomcat 9" in the "Download" item on the left. http://tomcat.apache.org/download-80.cgi

  2. Click "tar.gz" under "Core" in "Binary Distributions". ⇒ "apache-tomcat-9.0.37.zip" will be downloaded. https://tomcat.apache.org/download-90.cgi

  3. When the download is complete, unzip it to any directory. Here, unzip to / opt.

    $ sudo tar zxvf apache-tomcat-9.0.37.tar.gz -C /opt
    
  4. Make sure it is unzipped to / opt.

    $ ls /opt/apache-tomcat-9.0.37/
    BUILDING.txt  CONTRIBUTING.md  LICENSE  NOTICE  README.md  RELEASE-NOTES  RUNNING.txt  bin  conf  lib  logs  temp  webapps  work
    

Deploy

When the deployment environment is ready, deploy it.

  1. The default setting of tomcat is root user because no user other than root user has execute permission.

    $ sudo su
    
  2. Copy the created WAR file to the folder under webapps of TOMCAT.

    # mv sample.war /opt/apache-tomcat-9.0.37/webapps
    
  3. Start TOMCAT.

    # cd /opt/apache-tomcat-9.0.37/bin
    # sh startup.sh
    
  4. When you start a web browser and access the following URL, the client sends the GET method to the server and the following web page is displayed. http: // {IP address of the deployed PC}: 8080 / sample / servlet

  5. Exit TOMCAT.

    # sh shutdown.sh
    

Recommended Posts

Create a tomcat project using Eclipse Pleiades All in One
Create a Jetty project using Eclipse
Create a Java project using Eclipse
Eclipse Pleiades All in One for Mac released
eclipse all in one installation
Create a base for your batch processing project in Eclipse.
Create a Servlet program in Eclipse
Create a memo app with Tomcat + JSP + Servlet + MySQL using Eclipse
English translation of Pleiades All in One
Create a simple batch processing framework in Eclipse.
[Eclipse / Tomcat] Servlet + JSP in Maven webapp project
[CentOS, Eclipse] Load a library file in a C project
How to create a Spring Boot project in IntelliJ
Java development environment construction (Mac + Pleiades All in One Eclipse 4.7 + Spring Boot + Gradle (Buildship))
Create a fortune using Ruby
Using Amateurs UML in Eclipse
Install tomcat plugin in eclipse
How to create a new Gradle + Java + Jar project in Intellij 2016.03
The story that Tomcat suffered from a timeout error in Eclipse
[Android] Create a calendar using GridView
Build a Tomcat 8.5 environment with Pleiades 4.8
Create a database in a production environment
Create a new app in Rails
Create a filtering function using acts-as-taggable-on
Create a Maven project with a command
Java-database connection Java-MySQL connection ③-2: How to set CLASSPATH to the build bus of Eclipse (Pleiades All in One) / September 2017
Create a Spring Boot project in intellij and exit immediately after launching
How to create a query using variables in GraphQL [Using Ruby on Rails]
Creating a project (and GitHub repository) using Java and Gradle in IntelliJ IDEA
Try to create a browser automatic operation environment using Selenide in 5 minutes
Make the context root a project folder in an Eclipse dynamic web project
Create a web environment quickly using Docker
Building a Lambda development environment in Eclipse
Create a TODO app in Java 7 Create Header
Create a RESTful API service using Grape
Deploy a Tomcat-based Eclipse project on Heroku
Create a prefectural select bar using active_hash
Create a login function using Swift's Optional
[Java] [POI] Create a table in Word and start a new line in one cell
Create an animation in which characters emerge for a moment using molecular dynamics