Home / Tutorials / Environment Setting for J2EE development in ubuntu/debian

Environment Setting for J2EE development in ubuntu/debian

Lets see how to rapidly set up base stuff for Java web-application development. Please note that you don’t have to install each application mentioned here, one item from every content’s section (see below) will probably be enough. Also in some sections you can find tabs with different ways of installation, usually it’s installation from repository and installation from tarballs. Repository way is much easier, but might require more traffic and disk space, and vice versa for tarballs. Please select tabs that are more appropriate for you.

Content

  1. JDK:
  2. Building Tools:
  3. Web & Application Servers:
  4. IDE:
  5. DBMS:
  6. How to change default JVM

 

JDK installation

Before it’s too late I’d like to say that if you can’t answer the question “What is JDK?”, you probably better start from Java SE and postpone Java EE stuff.

Which JDK to choose? I noticed that most developers (including me) prefer Oracle JDK over OpenJDK, but I can’t provide hard evidence why it’s better, in general they’re pretty much the same. So it’s your choice which one to use.

Oracle JDK Installation

Automated Oracle JDK 7 installation script for major Linux distributions is provided in my article Install Oracle JDK 7 .

OpenJDK Installation

To install OpenJDK 7 execute the command in terminal*:

To check if openJDK was installed fine execute following command:

If everything is good you will see something like

If installation finished without errors, but a different version of JVM is shown, after installing other tools open this simple guide to change it to openjdk-7 version.

* If you are not using Ubuntu, and you don’t know who are sudoers, please execute commands here as super user (root). For this type su - in terminal, and input root’s password, you should know it. When you are done here please don’t use that terminal, just close it. As super user you can skip typing sudo.

Building tools installation

Which building tool to use? As for me Maven and Ant are pretty much different tools. Maven is easier and more convenient to use for typical projects, and it’s not only building tool. Ant is more flexible and harder to use, I think it’s possible to say that it’s more low-level tool. Personally I worked with Ant first.

Ant Installation

  • To install Ant execute the following command in terminal:

    It might happen that Ant installation will rewrite your default Java version (you can check it executing java -version in terminal). If so, after installing other tools you can find a simple guide to change it back in the very end of this article.

  • You can download binaries from Apache’s site. In this case you will download only about 5MB. And it will not rewrite default java version, but you will have to update Ant manually. Run terminal, change directory to where your downloaded tar.gz file is and execute following commands

To check if Ant was installed successfully execute following command:

You should see something like

Maven Installation

  • To install Maven’s package execute the following commands in terminal:

    It might happen that Maven installation will rewrite your default Java version (you can check it executing java -version in terminal). If so, after installing other tools you can find a simple guide to change it back in the very end of this article.

  • You have an option to download and install Maven from Apache’s site. In this case you will download only about 5MB. And it will not rewrite default java version, but you will have to update it manually. For this download the latest Maven version from here as binary tar.gz.

    Run terminal, change directory to where your downloaded tar.gz file is and execute following commands

Let’s check if Maven was properly installed. Run in terminal

If everything’s OK, you should see something like

Server installation

While you don’t use full stack of Java EE technologies (including EJB, JNDI, etc.), you may use containers like Tomcat or Jetty. They let you deploy web-applications that use JSP & Servlet API. Containers should work for you for most projects.

Tomcat Installation

dd

  • To install Tomcat 7 from repository execute the following command in terminal:

    It might happen that Tomcat installation will rewrite your default Java version (you can check it executing java -version in terminal). If so, after installing other tools you can find a simple guide to change it back in the very end of this article.

  • Download Tomcat from Apache’s site. In this case you will download only about 8MB. And it will not rewrite default java version, but you will have to update Tomcat manually.

    Run terminal, change directory to where your downloaded tar.gz file is and execute following commands (after the first sudo-wrapped command you can copy-past others at once).

  • Download Tomcat from Apache’s site. In this case you will download only about 8MB. And it will not rewrite default java version, but you will have to update Tomcat manually.

    Be aware that Eclipse doesn’t support the 8th version at present, so you will have to deploy your applications manually.

    Run terminal, change directory to where your downloaded tar.gz file is and execute following commands (after the first sudo-wrapped command you can copy-past others at once).

To check if Tomcat was installed correctly launch your web browser and visit address http://localhost:8080/. If everything is fine you will see page like a following:

Now tomcat is a daemon in your system and will start up with every loading of your system. You can stop it, start it and restart it executing following commands (change tomcat7 to tomcat8 if you installed the 8th version)

JBoss AS and Wildfly Installation

I wrote two articles about automatical installation of these two application servers. The only two things you need to do is to execute two commands (to download and to run script that installs application server). Follow one of these links:

  • Install JBoss AS 7
  • Install Wildfly 8

Be aware that Wildfly is just a new name for JBoss AS starting from version 8.

Eclipse Installation

  1. Download Eclipse from the official Eclipse’s website. Choose “Eclipse IDE for Java EE Developers” edition instead of “Eclipse IDE for Java Developers” because the last one is just for Java SE and isn’t very suitable for creation web-applications.
  2. Uncompress downloaded archive into folder you are used to use as folder for user-installed applications. Run terminal, change directory to where your downloaded tar.gz file is and execute the following commands
  3. Add a link to Eclipse in your Applications menu:
    1. For some reason Ubuntu doesn’t have Main Menu editor nowadays by default. So I recommend to install it. It will help you to add your own launchers to main menu.
    2. Menu ⇒ Main Menu. You can launch menu pressing Win key in both Gnome 3 (Debian) and Unity (Ubuntu).
      Main Menu with Alacarte selected
    3. Programming ⇒ New Item
      Eclipse: Main Menu dialog
    4. Fill the fields like this:
      Eclipse: Launcher dialog
      and press Close;
    5. Eclipse item should have appeared in your menu. Press ‘Close’ button to close Main Menu editing dialog.
      Eclipse: Main Menu dialog
    6. For some reason I had to reboot machine after adding this launcher using alacarte in Ubuntu before it appeared. Maybe you too.
  4. Run Eclipse and check if you’re able to run a simple java application (Hello world, for example)

Tomcat integration with Eclipse

  1. Run Eclipse. Add Tomcat server into a workspace doing following:
    1. Choose
      and click ‘Next >’
    2. Set Tomcat Installation Directory: /opt/tomcat7 (or /opt/tomcat8, or /usr/share/tomcat7 if installed from repo)
    3. Click Finish. I had some ‘permission denied’ error, but after pressing Finish button again everything became good. If installed from repo, you will have error related with missed config files instead. The same trick with pressing Finish one more time should work.
  2. Copy configurations in order to avoid that ‘permission denied’ or ‘missed config file’ problems: *
    Take into account that Tomcat configurations in Eclipse and in /opt/tomcat7/ are different now.
  3. If you installed Tomcat from repository, please concat policy files into one file, otherwise Eclipse will complain:
  4. Start server involving context menu of Tomcat in Servers tab (from the bottom Eclipse’s panel) and clicking Start.
    If everything is good you’ll see several lines in your Console tab after this action with only INFO and maybe WARN levels. If you got errors try to refresh Server first, selecting it in left panel and pressing F5 button.
  5. In case if your 8080 port is occupied with some application (like JBoss, Glassfish, another Tomcat, etc.) you need to replace all references to 8080, 8005, 8009 ports with some another unoccupied ones (for instance 9090, 9005, 9009). Do this by changing file Servers/Tomcat v7.0 Server at localhost-config/server.xml in the following way:Execute command: *
    and use replace (Ctrl+H) to change ports. After this restart Eclipse.
  6. Open your favourite browser, type http://localhost:9090/ and press Enter.
    Error 404 is a good sign 🙂
  7. Additionally you can create Dynamic web-application for checking purpose, but hardly does it concern installation topic, so I won’t describe it here.

* My workspace is ~/workspace/ folder, change commands if your one differs.

MySQL

While it’s hard to imagine development of Java web-application without JDK, server, and friendly some building tool, it’s quite possible not to have relational database. But it’s easy enough to install MySQL. Decide if you need it now.

To install MySQL execute the command:

and input a password for MySQL’s root user.

To check if MySQL server was installed fine run the command:

and enter password for your root account. Then you should see mysql> prompt. Type quit to exit from it.

How to change default JVM

Fortunately there’s a script that can change your default JVM. You can download and run this script executing commands:

It should open dialog where you can select version of JVM that you want to be your default one.

Dialog for changing default JVM

Press OK, and check that your default JVM has been changed:

About cmadmin

Web Developer & Designer | Android App Developer

Leave a Reply

Your email address will not be published. Required fields are marked *

Login


Username
Create an Account!
Password
Forgot Password? (close)

Sign Up


Username
Email
Password
Confirm Password
Want to Login? (close)

Forget Password?


Username or Email
(close)
%d bloggers like this:
SHARE
OR
SUBSCRIBE
To get latest new / tutorial / technology / development information subscribe with us.
ARE YOU READY? GET IT NOW!
Lets Get Updated with latest trends & tutorials!
Your Information will never be shared with any third party.
Ready for latest tutorials & tools !
OR SUBSCRIBE WITH