Hemanth's Scribes

cli

Eclipse on Ubuntu for J2EE

Author Photo

Hemanth HM

Thumbnail

“Install or update Eclipse to have Eclipse Web Tools Platform (WTP).”

Eclipse can be configured on Ubuntu (8.4) as follows:

1. Stop all apache and tomcat servers or any other if running on your host:

/etc/init.d/apache2 stop
/etc/init.d/tomcatX.X stop

P.S: You need to be root or use sudo.

2. Create a new dynamic web project:

  • Click on New > Projects > Dynamic web project
  • Enter the name, click finish

3. Add a new server on your localhost:

  • Click on the server tab
  • Right click and select New Server
  • Select Basic >> J2EE Preview at localhost (or any other appropriate for your need)

4. Test your server by starting it:

  • Right click, start
  • If any conflicts in the port, change the port of your local server

5. Create a Servlet in your project directory:

Try this ever famous “Hello World!!” (Add HTML Tags if required):

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
       
        out.println("Hello World!");
    
    }
}

6. Right click on your server and select add or remove projects and add your current project

7. Run as >> Run on Server

P.S: If you find any errors as cannot import javax.servlet.*; go to project properties >> Java build >> Add external jar and add Servlet.jar. I downloaded it from here.

8. Learn, Run and be Happy :)

#java#linux
Author Photo

About Hemanth HM

Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.