Guice 简明教程
Google Guice - Environment Setup
Local Environment Setup
如果您仍希望为 Java 编程语言设置环境,那么本部分将指导您如何在机器上下载并设置 Java。请按照以下步骤设置环境。
If you are still willing to set up your environment for Java programming language, then this section guides you on how to download and set up Java on your machine. Please follow the following steps to set up the environment.
Java SE 在 Download Java 链接中免费提供。所以您所要做的就是根据您的操作系统下载一个版本。
Java SE is freely available from the link Download Java. So you download a version based on your operating system.
按照说明下载 Java 并运行 .exe 以在你的计算机上安装 Java。一旦在计算机上安装了 Java,就需要设置环境变量以指向正确的安装目录:
Follow the instructions to download java and run the .exe to install Java on your machine. Once you installed Java on your machine, you would need to set environment variables to point to correct installation directories:
Setting up the path for windows 2000/XP:
假设你已将 Java 安装在 c:\Program Files\java\jdk 目录中:
Assuming 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:
假设你已将 Java 安装在 c:\Program Files\java\jdk 目录中:
Assuming you have installed Java in c:\Program Files\java\jdk directory:
-
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:
环境变量 PATH 应设置为指向已安装 Java 二进制文件的位置。如果你在这方面遇到问题,请参阅 shell 文档。
Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation if you have trouble doing this.
例如,如果您用 bash 作为您的 shell,则您将向您 '.bashrc: export PATH=/path/to/java:$PATH' 的末尾添加以下行
Example, if you use bash as your shell, then you would add the following line to the end of your '.bashrc: export PATH=/path/to/java:$PATH'
Popular Java Editors:
要编写 Java 程序,您需要一个文本编辑器。市面上还有更加复杂的 IDE 可供使用。但是就目前而言,您可以考虑以下几个选择:
To write your Java programs, you will need a text editor. There are even more 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:*is a Java IDE that is open-source and free which can be downloaded from https://www.netbeans.org/index.html.
-
Eclipse: is also a Java IDE developed by the eclipse open-source community and can be downloaded from https://www.eclipse.org/.
Google Guice Environment
下载 Google Guice 最新版本及相关 jar 文件。
Download the latest version of Google Guice and related jar files.
在我们编写本教程时,已将它们拷贝到 C:\>Google 文件夹中。
At the time of writing this tutorial, we have copied them into C:\>Google folder.
OS |
Archive name |
Windows |
guice-5.0.0-BETA-1.jar;aopalliance-1.0.jar;guava-30.0-jre.jar;javax.inject-1.jar;asm-9.0.jar |
Linux |
guice-5.0.0-BETA-1.jar;aopalliance-1.0.jar;guava-30.0-jre.jar;javax.inject-1.jar;asm-9.0.jar |
Mac |
guice-5.0.0-BETA-1.jar;aopalliance-1.0.jar;guava-30.0-jre.jar;javax.inject-1.jar;asm-9.0.jar |
Set CLASSPATH Variable
设置 CLASSPATH 环境变量以指向 Guice jar 位置。我们假设您已按照如下方式将 Guice 及相关 jar 存储在不同操作系统的 Google 文件夹中。
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-5.0.0-BETA-1.jar;C:\Google\aopalliance-1.0.jar;C:\Google\asm-9.0.jar;C:\Google\guava-30.0-jre.jar;C:\Google\javax.inject-1.jar;.; |
Linux |
export CLASSPATH=$CLASSPATH:Google/guice-5.0.0-BETA-1.jar:Google/aopalliance-1.0.jar:C:\Google\asm-9.0.jar:Google/guava-30.0-jre.jar:Google/javax.inject-1.jar:. |
Mac |
export CLASSPATH=$CLASSPATH:Google/guice-5.0.0-BETA-1.jar:Google/aopalliance-1.0.jar:C:\Google\asm-9.0.jar:Google/guava-30.0-jre.jar:Google/javax.inject-1.jar:. |