Springws 简明教程
Spring WS - Environment Setup
在本教程中,我们将了解在基于 Windows 和 Linux 的系统上设置 Spring-WS 的过程。只需执行几个简单的步骤,而无需任何复杂的设置程序,即可轻松安装 Spring-WS,并将其与你当前的 Java environment 和 MAVEN 集成。安装时需要用户管理。
In this Chapter, we will understand the process of setting up Spring-WS on Windows and Linux based systems. The Spring-WS can be easily installed and integrated with your current Java environment and MAVEN by following a few simple steps without any complex setup procedures. User administration is required while installation.
System Requirements
下表列出了系统要求,而后面的步骤将引导我们完成环境设置过程。
The following table lists out the system requirements, while the subsequent steps will guide us through the environment setup procedure.
JDK |
Java SE 2 JDK 1.5 or above |
Memory |
1 GB RAM (recommended) |
Disk Space |
No minimum requirement |
Operating System Version |
Windows XP or above, Linux |
现在让我们继续执行安装 Spring-WS 的步骤。
Let us now proceed with the steps to install Spring-WS.
Step 1: Verify the Java Installation
首先,你需要在系统上安装 Java 软件开发工具包 (SDK)。要验证这一点,请根据你所使用的平台执行以下两个命令中的任何一个。
To begin with, you need to have Java Software Development Kit (SDK) installed on your system. To verify this, execute any of the following two commands depending on the platform you are working on.
如果 Java 安装已正确完成,则它将显示 Java 安装的当前版本和规范。以下表中给出了一个示例输出。
If the Java installation has been done properly, then it will display the current version and specification of your Java installation. A sample output is given in the following table.
Platform |
Command |
Sample Output |
Windows |
Open command console and type − >java -version |
Java version "1.7.0_60" Java ™ SE Run Time Environment (build 1.7.0_60-b19) Java Hotspot ™ 64-bit Server VM (build 24.60-b09,mixed mode) |
Linux |
Open command terminal and type − $java -version |
java version "1.7.0_25" Open JDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64) Open JDK 64-Bit Server VM (build 23.7-b01, mixed mode) |
-
We assume the readers of this tutorial have Java SDK version 1.7.0_60 installed on their system.
-
In case you do not have Java SDK, download its current version from https://www.oracle.com/technetwork/java/javase/downloads/index.html and have it installed.
Step 2: Set your Java Environment
将环境变量 JAVA_HOME 设置为指向 Java 在你的机器上安装的基本目录位置。
Set the environment variable JAVA_HOME to point to the base directory location where Java is installed on your machine.
S.No. |
Platform & Description |
1 |
Windows Set JAVA_HOME to C:\ProgramFiles\java\jdk1.7.0_60 |
2 |
Linux Export JAVA_HOME=/usr/local/java-current |
将 Java 编译器位置的完整路径附加到系统路径。
Append the full path of Java compiler location to the System Path.
S.No. |
Platform & Description |
1 |
Windows Append the String "C:\Program Files\Java\jdk1.7.0_60\bin" to the end of the system variable PATH. |
2 |
Linux Export PATH=$PATH:$JAVA_HOME/bin/ |
如上所述,从命令提示符执行命令 java -version 。
Execute the command java -version from the command prompt as explained above.
Step 3: Download Maven archive
从 https://maven.apache.org/download.cgi 下载 Maven 3.3.3。
Download Maven 3.3.3 from https://maven.apache.org/download.cgi
OS |
Archive name |
Windows |
apache-maven-3.3.3-bin.zip |
Linux |
apache-maven-3.3.3-bin.tar.gz |
Mac |
apache-maven-3.3.3-bin.tar.gz |
Step 4: Extract the Maven archive
将归档文件解压到你想安装 Maven 3.3.3 的目录。将从归档文件创建子目录 apache-maven-3.3.3。
Extract the archive, to the directory you wish to install Maven 3.3.3. The subdirectory apache-maven-3.3.3 will be created from the archive.
OS |
Location (can be different based on your installation) |
Windows |
C:\Program Files\Apache Software Foundation\apache-maven-3.3.3 |
Linux |
/usr/local/apache-maven |
Mac |
/usr/local/apache-maven |
Step 5: Set Maven environment variables
将 M2_HOME、M2 和 MAVEN_OPTS 添加到环境变量。
Add M2_HOME, M2 and MAVEN_OPTS to the environment variables.
OS |
Output |
Windows |
Set the environment variables using system properties. M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.3.3 M2=%M2_HOME%\bin MAVEN_OPTS=-Xms256m -Xmx512m |
Linux |
Open command terminal and set environment variables. export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.3 export M2=$M2_HOME/bin export MAVEN_OPTS=-Xms256m -Xmx512m |
Mac |
Open command terminal and set environment variables. export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.3 export M2=$M2_HOME/bin export MAVEN_OPTS=-Xms256m -Xmx512m |
Step 6: Add Maven bin directory location to the system path
现在将 M2 变量附加到系统路径。
Now append M2 variable to the System Path.
OS |
Output |
Windows |
Append the string ;%M2% to the end of the system variable, Path. |
Linux |
export PATH=$M2:$PATH |
Mac |
export PATH=$M2:$PATH |
Step 7: Verify Maven installation
现在打开控制台,执行以下 mvn 命令。
Now open the console, execute the following mvn command.
OS |
Task |
Command |
Windows |
Open Command Console |
c:> mvn --version |
Linux |
Open Command Terminal |
$ mvn --version |
Mac |
Open Terminal |
machine:< joseph$ mvn --version |
最后,验证以上命令的输出,输出应类似于以下内容 −
Finally, verify the output of the above commands, which should be something as shown below −
OS |
Output |
Windows |
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T17:27:37+05:30) Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.3.3 Java version: 1.7.0_75, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.7.0_75\jre Default locale: en_US, platform encoding: Cp1252 |
Linux |
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T17:27:37+05:30) Maven home: /usr/local/apache-maven/apache-maven-3.3.3 Java version: 1.7.0_75, vendor: Oracle Corporation Java home: /usr/local/java-current/jdk1.7.0_75/jre |
Mac |
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T17:27:37+05:30) Maven home: /usr/local/apache-maven/apache-maven-3.3.3 Java version: 1.7.0_75, vendor: Oracle Corporation Java home: /Library/Java/Home/jdk1.7.0_75/jre |
Step 8: Setup Eclipse IDE
本教程中的所有示例都是使用 Eclipse IDE 编写的。建议读者在其机器上安装最新版本的 Eclipse。要安装 Eclipse IDE,请从以下链接 https://www.eclipse.org/downloads/ 下载最新的 Eclipse 二进制文件。下载安装程序后,将二进制发行版解压到一个方便的位置。
All the examples in this tutorial have been written using the Eclipse IDE. It is recommended that the readers should have the latest version of Eclipse installed on their machine. To install the Eclipse IDE, download the latest Eclipse binaries from the following link https://www.eclipse.org/downloads/. Once the installation is downloaded, unpack the binary distribution into a convenient location.
例如,在 Windows 上的 C:\eclipse ,或在 Linux/Unix 上的 /usr/local/eclipse ,最后相应设置 PATH 变量。Eclipse 可以通过在 Windows 机器上执行以下命令启动,或者你也可以简单地双击 eclipse.exe。
For example in C:\eclipse on windows, or /usr/local/eclipse on Linux/Unix and finally set the PATH variable appropriately. Eclipse can be started by executing the following commands on the windows machine, or you can simply double click on eclipse.exe.
%C:\eclipse\eclipse.exe
Eclipse 可以在 UNIX(Solaris、Linux 等)机器上通过执行以下命令启动 −
Eclipse can be started by executing the following commands on the UNIX (Solaris, Linux, etc.) machine −
$/usr/local/eclipse/eclipse
启动成功后,如果一切正常,则应显示以下屏幕 −
After a successful startup, if everything is fine then it should display the following screen −

Step 9: Setup Apache Tomcat
我们可从 https://tomcat.apache.org/ 下载最新版本的 Tomcat。一旦下载好安装程序,将二进制发行版解压缩到方便的位置。例如,对于 Windows 机器中的 C:\apache-tomcat-7.0.59 ,或者 Linux/Unix 机器中的 /usr/local/apache-tomcat-7.0.59 ,然后设置 CATALINA_HOME 环境变量指向安装位置。
We can download the latest version of Tomcat from https://tomcat.apache.org/. Once the installation is downloaded, unpack the binary distribution into a convenient location. For example in the C:\apache-tomcat-7.0.59 on a windows machine, or in the /usr/local/apache-tomcat-7.0.59 on a Linux/Unix machine and then set the CATALINA_HOME environment variable pointing to the installation locations.
Tomcat 可通过在 Windows 机器上执行以下命令启动,或者只需双击 startup.bat 即可
Tomcat can be started by executing the following commands on a windows machine, or you can simply double click on startup.bat
%CATALINA_HOME%\bin\startup.bat
or
C:\apache-tomcat-7.0.59\bin\startup.bat
Tomcat 可通过在 UNIX(Solaris、Linux 等)机器上执行以下命令启动 −
Tomcat can be started by executing the following commands on UNIX (Solaris, Linux, etc.) machine −
$CATALINA_HOME/bin/startup.sh
or
/usr/local/apache-tomcat-7.0.59/bin/startup.sh
启动成功后,与 Tomcat 一同包含的默认 Web 应用程序将可通过访问 http://localhost:8080/ 获得。如果一切正常,则应显示以下屏幕 −
After a successful startup, the default web applications included with Tomcat will be available by visiting – http://localhost:8080/. If everything is ok, then it should display the following screen −

关于配置和运行 Tomcat 的更多信息,可以在此处包含的文档中以及 Tomcat 网站 https://tomcat.apache.org 中找到
Further information about configuring and running Tomcat can be found in the documentation included here, as well as on the Tomcat website − https://tomcat.apache.org
Tomcat 可通过在 Windows 机器上执行以下命令停止 −
Tomcat can be stopped by executing the following commands on a windows machine −
%CATALINA_HOME%\bin\shutdown
or
C:\apache-tomcat-7.0.59\bin\shutdown
Tomcat 可通过在 UNIX(Solaris、Linux 等)机器上执行以下命令停止 −
Tomcat can be stopped by executing the following commands on the UNIX (Solaris, Linux, etc.) machine −
$CATALINA_HOME/bin/shutdown.sh
or
/usr/local/apache-tomcat-7.0.59/bin/shutdown.sh
一旦完成最后这一步,便可以继续进行第一个 Web 服务示例了,我们将在下一章中讨论它。
Once we are done with this last step, we are ready to proceed for the first Web Services Example, which we will discuss in the next chapter.