Book Image

SPRING COOKBOOK

Book Image

SPRING COOKBOOK

Overview of this book

Table of Contents (19 chapters)
Spring Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Installing Java, Maven, Tomcat, and Eclipse on Ubuntu


We will first install Java 8. Then, we will install Maven 3, a build tool similar to Ant, to manage the external Java libraries that we will use (Spring, Hibernate, so on). Maven 3 also compiles source files and generates JAR and WAR files. We will also install Tomcat 8, a popular web server for Java web applications, which we will use throughout this book. JBoss, Jetty, GlassFish, or WebSphere could be used instead. Finally, we will install the Eclipse IDE, but you could also use NetBeans, IntelliJ IDEA, and so on.

How to do it…

Install Java first, then Maven, Tomcat, and Eclipse.

Installing Java

  1. Add this PPA (Personal Package Archive):

    sudo add-apt-repository -y ppa:webupd8team/java
    
  2. Refresh the list of the available packages:

    sudo apt-get update
    
  3. Download and install Java 8:

    sudo apt-get install –y oracle-java8-installer
    
  4. Test whether it's working:

    $ java -version
    java version "1.8.0_40"
    Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
    Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25…
    

Installing Maven

  1. Download Maven from the Apache website http://maven.apache.org/download.cgi. Choose the Binary zip file of the current stable version:

  2. Uncompress the downloaded file and move the resulting folder to a convenient location (for example, ~/bin).

  3. In your ~/.bash_profile file, add a MAVEN HOME environment variable pointing to that folder. For example:

    export MAVEN_HOME=~/bin/apache-maven-3.3.1
  4. Add the bin subfolder to your PATH environment variable:

    export PATH=$PATH:$MAVEN_HOME/bin
  5. Open a new terminal and test whether it's working:

    $ mvn –v
    Apache Maven 3.3.1 (12a6b3...
    Maven home: /home/jerome/bin/apache-maven-3.3.1
    Java version: 1.8.0_40, vendor: Oracle Corporation
    
    

Installing Tomcat

  1. Download Tomcat from the Apache website http://tomcat.apache.org/download-80.cgi and choose the Core binary distribution.

  2. Uncompress the downloaded file and move the extracted folder to a convenient location (for example, ~/bin).

  3. Make the scripts in the bin subfolder executable:

    chmod +x bin/*.sh
  4. Launch Tomcat using the catalina.sh script:

    $ bin/catalina.sh run
    Using CATALINA_BASE:   /Users/jerome/bin/apache-tomcat-7.0.54
    ...
    INFO: Server startup in 852 ms
    
  5. Tomcat runs on the 8080 port by default. Go to http://localhost:8080/ to check whether it's working.

Installing Eclipse

  1. Download Eclipse from http://www.eclipse.org/downloads/. Choose the Linux 64 Bit version of Eclipse IDE for Java EE Developers.

  2. Uncompress the downloaded file and move the extracted folder to a convenient location (for example, ~/bin).

  3. Launch Eclipse by executing the eclipse binary:

    ./eclipse

There's more…

Tomcat can be run as a background process using these two scripts:

bin/startup.sh
bin/shutdown.sh

On a development machine, it's convenient to put Tomcat's folder somewhere in the home directory (for example, ~/bin) so that its contents can be updated without root privileges.