eclipse为SSH框架.xml文件添加自动提示功能

一、spring

 

用eclipse,在导入相应的包后(有人说不导包也有提示,因为默认的eclipse导入了jdk的包),eclipse会有代码提示功能。<wbr></wbr>
那么XML文件能不能也这样呢?其实也是可以的,只不过导包的地方不一样。下面以spring为例(虽然Myeclipse6.5中已经集成了,这里只是示范说明)。<wbr></wbr>

<?xml version="1.0" encoding="UTF-8"?>
<beans
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">



进入:window -> Preference... -> MyEclipse -> Editors -> XML ->XML Catalog<wbr></wbr>

选择:选中“User Specified Entries”,点击“Add...”按钮<wbr></wbr>

填入:<wbr></wbr>

location: 请选择本地文件系统上SPRING_HOME\schema\beans\spring-beans-3.0.xsd 文件<wbr></wbr>
Key Type: 选择Schema Location<wbr></wbr>
Key:http://www.springframework.org/schema/beans/spring-beans-3.0.xsd<wbr></wbr>

点击确定<wbr></wbr>

将spring配置文件关闭再重新打开即可。可以使用Eclipse XML Editor打开这些xml文件。

二、hibernate

 

在编辑 *.hbm.xml 文件时,myeclipse 带有自动提示功能,但 eclipse 是没有自动提示功能的。需要自己手工加上:
1、打开项目中任意一个 *.hbm.xml 文件,看一下文件头,形如以下:

 

<?xml version="1.0" encoding="utf-8"?>    
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">



找到http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd(视 hibernate 版本不同有所不同)。
2、将项目中用到的 hibernate-core-4.1.7.Final.jar解压缩,找到解压缩后的 org 文件下的 hibernate 文件下的 hibernate-mapping-3.0.dtd 文件。
3、eclipse -> Window -> Preferences -> Web and XML -> XML Catalog,选择 XML Catalog Entries 的 Add... 按钮,在弹出的 Add XML Catalog Entry 对话框里,Location 里选择第二步里得到的 hibernate-mapping-3.0.dtd,Key Type 选择 URI,Key 里输入第一步里得到的http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd。OK。
再打开 eclipse 中的 *.hbm.xml 文件,编辑时就可以像 myeclipse 中那样拥有自动提示功能了。

 

三、struts2

1.配置文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">

2.在struts安装包里找struts-2.3.dtd文件

3、eclipse -> Window -> Preferences -> Web and XML -> XML Catalog,选择 XML Catalog Entries 的 Add... 按钮,在弹出的 Add XML Catalog Entry 对话框里,

将llib目录下的struts2-core-2.3.4.1.jar解压缩(struts-2.3.4.1-all\struts-2.3.4.1\lib\struts2-core-2.3.4.1),找到里面的struts-2.3.dtd。


location: 请选择本地文件系统上STRUTS_HOME\struts-2.3.4.1\lib\struts2-core-2.3.4.1\struts-2.3.dtd文件<wbr><br style="text-align:left; line-height:25px; background-color:rgb(255,255,255); font-family:Helvetica,Tahoma,Arial,sans-serif"><span style="text-align:left; line-height:25px; background-color:rgb(255,255,255)">Key Type: 选择URI<wbr></wbr></span></wbr>
Key:http://struts.apache.org/dtds/struts-2.3.dtd