Eclipse Ide For Java Ee

Written by Nam Ha Minh
Last Updated on 07 August 2019 Print Email
In this tutorial, you will learn how to develop a simple Java Servlet using Eclipse IDE. Before moving forward, make sure you have the following pieces of software installed on your computer (clicking on the hyperlink will let you download the corresponding software):
    • JDK 7
    • Eclipse IDE for Java EE Developers (Juno 4.2)
    • Tomcat 7.0

You can use newer versions of these software programs.

Table of Content:

The mission of Eclipse EE4J is to create standard APIs, implementations of those APIs, and technology compatibility kits for Java runtimes that enable development, deployment, and management of server-side and cloud-native applications. EE4J is based on the Java EE standards, and uses Java EE 8 as the baseline for creating new standards. Eclipse IDE for Java Developers 'Servers' doesn't exist. Therefore download correct Eclipse IDE. It is Eclipse IDE for Enterprise Java Developers (Eclipse IDE for Java EE Developers). This way is easy. Tools for Java developers creating Java EE and Web applications, including a Java IDE, tools for Java EE and JSF, Mylyn and others. Eclipse IDE for Java Developers: For developing Java SE applications, which is a subset of the Java EE Developer package. To start downloading the package, click on the link 32-bit or 64-bit, depending upon the bit version of your operating system.

1. Create Dynamic Web Project

2. Create Servlet class

3. Deploy the servlet

4. Run and test the servlet

1. Create Java Dynamic Web Project

Servlet is for Java web application, so we need to create a Java EE project first. In Eclipse, make sure the current perspective is Java EE (if not, select Window > Open Perpsective > Java EE, Eclipseor hold down Ctrl + F8 and select Java EE). Click File > New > Dynamic Web Project, the New Dynamic Web ProjectEclipse ide for java ee developers 2019 appears, enter the following information:

-Project name: MyFirstServlet

-Target runtime: Apache Tomcat v7.0. If Apache Tomcat v7.0 is not available in the dropdown list, click New Runtime button. The dialog New Server Runtime Environment appears, select Apache Tomcat v7.0:

Click Next. In the next screen, click Browse button to select Tomcat installation directory:

Click Finish and Apache Tomcat v7.0 will be added to the dropdown list.

-Dynamic web module version: 3.0

-Configuration: Default Configuration for Apache Tomcat v7.0

The configuration we have chosen conforms to Servlet specification version 3.0.

Leave other stuff as default, click Finish. The MyFirstServlet project is created.

2. Create Java Servlet class

We will create a dead simple servlet class which sends the output “Hello friend!” to client.Click File > New > Servlet, the dialog Create Servlet appears. Enter the following information:

-Java package: net.codejava

-Class name: HelloServlet

The servlet being created has fully qualified name as net.codejava.HelloServletand extends HttpServlet class. Click Next to move on next screen where we can specify initialization parameters and URL mappings for the servlet:Leave this form as default. The URL mapping /HelloServlet means that this servlet will be accessible from this URL pattern: http://localhost:8080/MyFirstServlet/HelloServletClick Next to move on next screen where we can specify which methods we want to inherit from the super class HttpServlet:By default the two methods doGet()and doPost() are checked. Since we just query the servlet from a HTTP GET method, uncheck the doPost() method. Click Finish, Eclipse creates a Java class which has some skeleton code as below:

From this skeleton code, we can read out some interesting information as follow:

-The annotation @WebServlettells that the annotated class is a servlet. This annotation has been introduced since Servlet API 3.0. The URL mapping /HelloServlet is passed as a parameter of the annotation.

-HttpServlet class is the base class for all servlets that are serving client’s requests through HTTP.

-The doGet() method is overridden from the HttpServlet class, since we have chosen to override it in the dialog Create Servlet.

-The no-argument constructor HelloServlet() is generated to place initialization code. Since we don’t initialize anything, this constructor can be safely deleted.

Add the following line into the doGet()Eclipse Ide For Java Ee method:

response.getWriter().println('Hello friend!');

War thunder vr tank

So far we have the following code of the servlet HelloServlet:The doGet() method just simply sends a String “Hello friend!” to the client.And finally, we have the following structure in the Project Explorer view:Note that there is no file web.xml is created because that file can be omitted when we are using annotation for Servlet 3.0.

3. Deploy the Java Servlet

We will deploy the Eclipse Ide For Java EeMyFirstServlet application on Tomcat server. Switch to the Servers view by selecting Window > Show View > Servers from Eclipse’s main menu.If there is no server available, click on the link new server wizard…The New Server dialog appears, select Tomcat v7.0 ServerFor as shown in the following screenshot:Click Next. In the Add and Remove screen, select MyFirstServlet on the left and click Add button to move it to the right, as shown in the following screenshot:Click Finish, the MyFirstServlet application is now deployed on Tomcat server:

4. Run and test the Java servlet

Now, it’s time to start the server and test the servlet. In the Servers view, right click on the server name, and select Start. You should see some output in the Console view, and the server’s status switches from Stopped to Started:Click Window > Show View > Other….

Eclipse Ee Download

In the dialog Show View

Eclipse Ide For Java Ee Developers 4.7.3

, type “Internal” in the text field then select Internal Web Browser underneath:Click

Eclipse Ide For Java Ee Developers Mars

OK to open up the view Internal Web Browser. Type the following URL into the address bar (the port number here may be different than yours, depending on how you configured Tomcat):http://localhost:8080/MyFirstServlet/HelloServletThe servlet is invoked and we would see the text “Hello friend!” in the browser:That’s all for this tutorial! We have learnt how to develop a simple servlet – a basic step in developing Java EE applications.

Eclipse Ide For Java Ee Development

Related Java Servlet Tutorials:

Other Eclipse Tutorials:

Eclipse J2ee

About the Author:

Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.