How to set up an XML development environment

黄舟
Release: 2017-02-18 15:42:39
Original
1297 people have browsed it

[Introduction] The best way to learn xml is to start with simple development, practice boldly, and proceed step by step. The beauty of XML can only be deeply understood during the development process. It is impossible to learn XML without development. Therefore, to learn XML, you should first establish an XML development environment. Let me introduce to you

The best way to learn xml is to start with simple development, practice boldly, and proceed step by step. The beauty of XML can only be deeply understood during the development process. It is impossible to learn XML without development. Therefore, to learn XML, you should first establish an XML development environment. Let me introduce to you how to establish an XML development environment based on java. Since I don't have access to linux right now, all the examples are done on Windows. However, all the software introduced here can be used on Linux and Windows, and the usage is similar. And except for Sun's JRE, it is all open source software, and anyone can use it for any purpose, even redistribution for commercial purposes. JRE is also free to download and use, but there is no source code. If you have experience using these software on Linux, I hope you can contribute to everyone.

Establishing an XML development environment requires the following steps:
1. Install Java runtime environment
2. Install a Java compiler.
3. Install a jsp Container.
4. Install a taglib that supports XSLT.
5. Install an XML Parser.
6. Install a browser that supports XSLT.
7. Install an XML file editor (optional).


step 1. Install Java runtime environment
It is recommended to use Sun's JRE 1.3, which can be downloaded from here:
http://www.php.cn/
Note: It is not JDK 1.3, all we need is JRE 1.3

After downloading JRE 1.3, run the installation program, assuming it is installed under C:\JRE1.3. Then you need to set three environment variables.
JAVA_HOME=C:\JRE1.3
CLASSPATH=.;C:\JRE1.3\lib\rt.jar
PATH=%PATH%;C:\JRE1.3\bin

If it is Windows 95/98/me, put the environment variable settings in Autoexec.bat, then restart the machine. For Windows NT/2000, just set them in "My Computer/Properties".


Step 2: Install a Java compiler.
It is recommended to use IBM's jikes, an efficient open source Java compiler. The homepage of jikes is at
http://www.php.cn/
The latest version is 1.1.3, which can be downloaded from here:
http://www.php.cn/
Download After decompressing, you will get a jikes.exe and place it in any directory in the PATH environment variable, such as C:\JRE1.3\bin

Edit a simple hello world program and try it:

// hello.java
public class hello {
public static void main(String [] args) {
System.out.PRint("hello, world!\n");
}
}
Copy after login

Then compile
jikes hello.java

If hello.class is generated, it can be used.


Step 3. Install a JSP Container.
It is recommended to use Jakarta’s Tomcat 3.2.1. Tomcat 3.2.1 can be downloaded from here:
http://www.php.cn/
You need to download the jakarta-tomcat-3.2.1.zip file
If you are on Windows NT/2000 Install it under the Win32/i386 directory, and jk_nt_service.zip in the win32/i386 directory.

Decompress after downloading, assuming it is placed in C:\tomcat
Then you need to set an environment variable
TOMCAT=C:\tomcat

In order to enable Tomcat to use jikes, You need to do a little hack, the method is as follows:
Add parser.jar, jaxp.jar, webserver.jar in tomcat's lib directory to the environment variable CLASSPATH, make it effective and then perform the following steps:
cd \ tomcat\src\org\apache\tomcat\context
Edit the file WebXmlReader.java, remove the comments before

// sw.addInitParam("jspCompilerPlugin", "org.apache.jasper.compiler.JikesJavaCompiler");
Copy after login




and then compile
jikes WebXmlReader.java

Create a temporary directory and use the jar tool (can be obtained from the JDK) to decompress webserver.jar
mkdir t
cd t
jar xvf ..\webserver.jar
Replace the WebXmlReader*.class under org\apache\tomcat\context with the WebXmlReader*.class just compiled and generated
Then repackage:
jar cf webserver.jar .
Replace Tomcat's webserver.jar with the new webserver.jar

Edit the web.xml in Tomcat's conf directory and change

Copy after login

外的注释去掉。

编辑 Tomcat 的 bin 目录中的 tomcat.bat,将所有的 tools.jar 替换为 rt.jar
启动 tomcat,运行 bin 目录中的 startup.bat。
使用浏览器做一下测试,访问
http://www.php.cn/:8080
如果 JSP 和 Servlet 的例子都能编译和运行,Tomcat 就可以用了。
停止 Tomcat 用 shutdown.bat

在 Windows NT/2000 下,可以把 tomcat 安装为一个 service,方法如下:
将 Tomcat 的 conf 目录下的 wrapper.properties 拷出来并编辑。将其中的两个变量
wrapper.tomcat_home
wrapper.java_home
分别设置为 TOMCAT 和 JRE 的安装路径,将所有的 tools.jar 替换为 rt.jar。
然后运行
jk_nt_service -I Tomcat wrapper.properties
其中 Tomcat 是我们安装的 service 的名称。
进入控制面板中启动 Tomcat service。Tomcat service安装后设置为手工启动,你可以修改 Tomcat service 的属性使其成为自动启动。

删除 Tomcat service 用:
jk_nt_service -R Tomcat


步骤4。安装一个支持 XSLT 的 taglib。
推荐使用 Jakarta Taglibs 中做 XSLT 的 XSL Taglib
其页面在 http://www.php.cn/
从该页面上下载 XSL Taglib 的 snapshot。你也可以下载全部的 Jakarta Taglibs,Jakarta Taglibs 的范围很广,但是这里我们要用到的仅仅是其中的 XSL Taglib。

下载完后解压缩,将其中的 xsl-examples.war 和 xsl-doc.war 这两个文件拷到 Tomcat 的 webapps 目录下,然后重新启动 Tomcat。使用浏览器访问
http://www.php.cn/:8080/xsl-examples/
运行页面中的 Apply.jsp,如果没有出错,显示了一个有很多表格的页面,XSL Taglib 就可以用了。
XSL Taglib 的文档也装好了,在
http://www.php.cn/:8080/xsl-doc/

你可以从这个例子出发,一步一步地开始写你自己的 XML 处理程序。比如你可以在 Tomcat 的 server.xml 中添加一个新的 Context


Copy after login

其中的 path-to-your-work-directory 是你的开发目录。将 Tomcat 的 webapps/xsl-examples 目录下的内容原封不动的拷到你的开发目录,以这个程序为参考开始写你自己的 XML 处理程序。

关于如何使用 JSP 做 XML 开发可以参考 Sun 的 whitepaper ,在:http://www.php.cn/
讲的基本上就是我上面告诉你的这种方法。


步骤5。安装一个 XML Parser。
做完了步骤3 和 步骤4,你已经有了两个可用的 XML Parser 了,那就是 Tomcat 本身使用的 Sun 的 JAXP 和 XSL Taglib 使用的 xml.apache.org 的 Xerces。JAXP 包括两个文件 parser.jar 和 jaxp.jar,Xerces 只有一个文件 xerces.jar,这几个文件可以从 Tomcat 的目录下找到。
推荐使用 Xerecs 这个 XML Parser,因为它目前已经可以支持 XML Schema,并且它是 open source 软件。但是这完全是出于个人喜好,Sun 的 XML Parser 也是非常出色的。决定使用哪个 XML Parser 后将其文件加入到 CLASSPATH 中。但是不要同时使用两个 XML Parser。CLASSPATH 生效后你就可以在你的 Java 程序中使用 JDOM 和 SAX 的 API 处理 XML 文件了。

关于 JDOM 和 SAX 适用的场合和用法的例子可以从这里找到:http://www.php.cn/


步骤6。安装一个支持 XSLT 的浏览器。
这一步并不是必须的,因为我们现在已经可以在 Server 端使用 XSL Taglib 将 XML 文件转换为 HTML 格式后发给 Browser,所以实际上你可以使用任何你喜欢的浏览器。但是安装一个支持 XSLT 的浏览器可以方便我们的学习。虽然现在我们需要在 Server 端做 XSLT,但是将来支持 XSLT 的浏览器流行了之后我们甚至连这一步都可以省掉,直接把 XML 和 XSL 文件发给浏览器就行了。这样就可以大大减轻 Server 端的负担,因为做 XSLT 可不是一件轻松的工作。

推荐使用 Mozilla 0.8。说到这里,你可能又要问了,为什么不使用 IE 4/5 呢?IE 4/5 不是也可以做 XSLT 吗?除了个人喜好以外,我可以举出 3 个使用 Mozilla 的理由:
首先 Mozilla 支持的 XSLT 版本比 IE 4/5 要新,IE 4/5 支持的 XSLT 不是正式版本,而是一个草稿。即:http://www.php.cn/ ,而 Mozilla 支持的 XSLT 是 XSLT 的正式版本。即:http://www.php.cn/ 。
其次 Mozilla 中的 XML 应用不仅包括 XSLT,还包括 RDF,XUL,SVG,MathML 等等,所以 Mozilla 对 XML 的支持从广度和深度上都要超过 IE 4/5。
第三 XML FAQ 的作者对 Mozilla 推崇有加,认为 Mozilla 对 XML 的支持在鲁棒性上比 IE 4/5 要好得多。

OK,说了这么多,现在转到正题上来,如何使 Mozilla 0.8 支持 XSLT?
首先,从这里下载 Mozilla 0.8:http://www.php.cn/
最新的是 0.8.1 版,但是这个版本安装了支持 XSLT 的模块后无法运行,所以目前还只能使用老一点但是比较慢的 0.8 版。
如果你不想再要其它诸如 SVG/MathML 的功能的话,最方便的方法是使用做好的 .exe 文件安装。
安装完毕后,启动 Mozilla,访问这个页面:http://www.php.cn/
页面里有一个 Install 按钮,点击这个按钮就可以安装实现 XSLT 功能的 TransforMiiX 模块。
重新启动 Mozilla,访问上面提到的那个页面。点击上面 simple example 的链接。如果看到的结果与点击 look like 链接看到的结果相同,那么你的 Mozilla 就已经能够支持 XSLT 了。

关于如何配置 Mozilla 0.8 支持 Java Plug-in 请参考我发在 XML 版的另一篇帖子:基于 Mozilla 的 XML 客户端解决方案,这里就不多说了。


步骤7。安装一个 XML 文件的编辑器。
这一步就更不是必须的了。你听说过现在还有人使用 vi 做 HTML 页面吗?我就见过这样的人,那就是于明俭老师。在于老师的个人主页上有样一句醒目的话:Just vim it ! 实际上你可以使用任何你喜欢的编辑器来编辑 XML 文件,但是为了方便那些习惯使用 WYSIWYG 编辑器的朋友,我还是推荐几个比较好的 XML 编辑器:
1。XML Spy:一个功能很全的 XML 编辑器,有试用版可以下载。
http://www.php.cn/
2。EditML Pro:另一个功能比较全的 XML 编辑器。
http://www.php.cn/
3。PSGML for Emacs:Emacs,我就不用说什么了吧?
http://www.php.cn/



这里只是为了锦上添花再介绍一些其它的知识,使用这些知识我们可以建造一个更为强大的开发环境。

步骤8。安装一个比较好的 JSP Framework
推荐使用 Struts。Struts 是 Jakarta 项目的一个子项目,目的是开发一个基于 MVC 设计模式的 JSP Framework。在 Struts 的框架内做开发可以有效地分离 Web 应用的表示层和实现层,提高代码的可重用性。基于 MVC 设计模式的开发也就是所谓的 Model 2 开发模式。目前该项目已接近完成,最新的版本是 1.0-beta-1。

关于什么是 MVC 设计模式可以参考机械工业出版社的《设计模式》这本书。关于 Struts 的用法,可以参考我翻译的《Struts 用户指南》,在文章荟萃里:http://www.php.cn/

从这里下载 Jakarta Struts:
http://www.php.cn/
你需要下载 jakarta-struts-1.0-b1.zip 这个文件。
将其解压缩,然后将其中的 struts-example.war,struts-documentation.war 这两个文件拷到 Tomcat 的 webapps 目录下,然后重新启动 Tomcat。使用浏览器访问
http://www.php.cn/:8080/struts-example/
运行页面里的 MailReader 程序,如果能正确注册就可以用了。
Struts 的文档也装好了,在
http://www.php.cn/:8080/struts-documentation/

关于如何在自己的开发目录中使用 Struts,请参考 Struts 所带的文档。Java 版里有一些关于 Struts 的讨论,使用论坛的搜索功能可以找到。


步骤9。建立与 Apache 的连接
这已经是老生长谈了,我介绍一下最简单的方法,使用 mod_jk 建立与 Apache 的连接。
假设你已经安装好了 Apache,从 这里下载 mod_jk:
http://www.php.cn/
你需要下载 mod_jk.zip 这个文件。
将其解压缩,得到一个 mod_jk.dll,拷到 Apache 安装目录下的 modules 目录中。
修改 Apache 的配置文件 httpd.conf,加入以下两行:

Include C:/tomcat/conf/mod_jk.conf-auto
JkMount /*.do ajp12
Copy after login

其中“C:/tomcat”是 Tomcat 的安装目录。
将 index.jsp 加到 DirectoryIndex 中,即:

DirectoryIndex index.html index.jsp
Copy after login


如果 ServerName 前有注释,打开 ServerName 前的注释,将其设置为 localhost,即:
ServerName localhost

重新启动 Apache,访问这个页面:
http://www.php.cn/
如果能列出 jsp 和 servlet 目录,Tomcat 和 Apache 的连接就建好了。                    

    

 以上就是 如何建立一个 XML 的开发环境的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!