Gson 简明教程

Gson - Environment Setup

Local Environment Setup

如果你仍然想为 Java 编程语言设置本地环境,那么本部分将指导你如何在计算机上下载和设置 Java。请按照以下给出的步骤设置环境。

If you still want to set up a local environment for Java programming language, then this section will guide you on how to download and set up Java on your machine. Please follow the steps given below, 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 have installed Java on your machine, you would need to set the environment variables to point to their correct installation directories.

Setting up the Path in Windows 2000/XP

假设你已将 Java 安装在 c:\Program Files\java\jdk 目录中 −

Assuming you have installed Java in c:\Program Files\java\jdk directory −

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

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

  3. Next, alter the 'Path' variable so that it also contains the path to the Java executable. For 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 in Windows 95 / 98 / ME

假设你已将 Java 安装在 c:\Program Files\java\jdk 目录中 −

Assuming you have installed Java in c:\Program Files\java\jdk directory −

  1. 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 文档。

The 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'”末尾添加以下行。

For 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'

要编写您的 Java 程序,您将需要一个文本编辑器。市场上有许多成熟的 IDE 可用。但现在,您可以考虑以下之一 −

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

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

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

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

Download Gson Archive

gson-2.3.1.jar 下载 Gson jar 文件的最新版本。在撰写本教程时,我们下载了 gson-2.3.1.jar 并将其复制到了 C:\>gson 文件夹。

Download the latest version of Gson jar file from gson-2.3.1.jar. At the time of writing this tutorial, we downloaded gson-2.3.1.jar and copied it into C:\>gson folder.

OS

Archive name

Windows

gson-2.3.1.jar

Linux

gson-2.3.1.jar

Mac

gson-2.3.1.jar

Set Gson Environment

设置 GSON_HOME 环境变量,使其指向 Gson jar 在您的机器上存储的基本目录位置。

Set the GSON_HOME environment variable to point to the base directory location where Gson jar is stored on your machine.

OS

Output

Windows

Set the environment variable GSON_HOME to C:\gson

Linux

export GSON_HOME=/usr/local/gson

Mac

export GSON_HOME=/Library/gson

Set CLASSPATH variable

设置 CLASSPATH 环境变量以指向 Gson jar 位置。

Set the CLASSPATH environment variable to point to the Gson jar location.

OS

Output

Windows

Set the environment variable CLASSPATH to %CLASSPATH%;%GSON_HOME%\gson-2.3.1.jar;.;

Linux

export CLASSPATH=$CLASSPATH:$GSON_HOME/gson-2.3.1.jar:.

Mac

export CLASSPATH=$CLASSPATH:$GSON_HOME/gson-2.3.1.jar:.