Google Guice - Environment Setup


Advertisements

Let us look into setting up the environment for Guice, before proceeding into its functionalities.

Local Environment Setup

This section guides you on how to download and set up Java environment on your machine. Please follow the steps mentioned below to set up the environment.

Java SE is freely available from the link Download Java. Download a version based on your operating system. Then, follow the instructions to download Java and run the .exe file to install Java on your machine. Once you installed Java, you would need to set environment variables to point to correct installation directories.

Setting up the Path for Windows 2000/XP

We are assuming that you have installed Java in c:\Program Files\java\jdk directory −

  • Right-click on 'My Computer' and select 'Properties'.

  • Click on the 'Environment variables' button under the 'Advanced' tab.

  • Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.

Setting up the Path for Windows 95/98/ME

In case, you have installed Java in c:\Program Files\java\jdkdirectory, edit the 'C:\autoexec.bat' file and add the following line at the end: 'SET PATH=%PATH%;C:\Program Files\java\jdk\bin'.

Setting up the Path for Linux, UNIX, Solaris, FreeBSD

Environment variable PATH should be set to point to where the Java binaries have been installed. You may refer to your shell documentation for more information.

For example, if you use bash as your shell, then you would add the following line to the end: '.bashrc: export PATH=/path/to/java:$PATH'

Popular Java Editors

To write your Java programs, you need a text editor. There are many sophisticated IDEs available in the market. But for now, you can consider one of the following −

  • Notepad − On Windows machine you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad.

  • Netbeans − It is a Java IDE that is open-source and free which can be downloaded from https://www.netbeans.org/index.html.

  • Eclipse − It is also a Java IDE developed by the eclipse open-source community and can be downloaded from https://www.eclipse.org/.

Google Guice Environment

Download the latest version of Google Guice and related jar files.

At the time of writing this tutorial, we have copied them into C:\>Google folder.

OS Archive name
Windows guice-4.1.0.jar;aopalliance-1.0.jar;guava-16.0.1.jar;javax.inject-1.jar
Linux guice-4.1.0.jar;aopalliance-1.0.jar;guava-16.0.1.jar;javax.inject-1.jar
Mac guice-4.1.0.jar;aopalliance-1.0.jar;guava-16.0.1.jar;javax.inject-1.jar

Set CLASSPATH Variable

Set the CLASSPATH environment variable to point to the Guice jar location. Assuming, you have stored Guice and related jars in Google folder on various Operating Systems as follows.

OS Output
Windows Set the environment variable CLASSPATH to %CLASSPATH%;C:\Google\guice-4.1.0.jar;C:\Google\aopalliance-1.0.jar;C:\Google\guava-16.0.1.jar;C:\Google\javax.inject-1.jar;.;
Linux export CLASSPATH=$CLASSPATH:Google/guice-4.1.0.jar:Google/aopalliance-1.0.jar:Google/guava-16.0.1.jar:Google/javax.inject-1.jar:.
Mac export CLASSPATH=$CLASSPATH:Google/guice-4.1.0.jar:Google/aopalliance-1.0.jar:Google/guava-16.0.1.jar:Google/javax.inject-1.jar:.
Advertisements