1. 程式人生 > >eclipse為SSH框架.xml檔案新增自動提示功能

eclipse為SSH框架.xml檔案新增自動提示功能

.xsd .dtd檔案要從jar包檔案中解壓獲取

一、spring

用eclipse,在匯入相應的包後(有人說不導包也有提示,因為預設的eclipse匯入了jdk的包),eclipse會有程式碼提示功能。
那麼XML檔案能不能也這樣呢?其實也是可以的,只不過導包的地方不一樣。下面以spring為例(雖然Myeclipse6.5中已經集成了,這裡只是示範說明)。

[html] view plaincopyprint?
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <beans
  3. xmlns="http://www.springframework.org/schema/beans"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xmlns:p="http://www.springframework.org/schema/p"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<?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

選擇:選中“User Specified Entries”,點選“Add...”按鈕

填入:

location: 請選擇本地檔案系統上SPRING_HOME\schema\beans\spring-beans-3.0.xsd 檔案

二、hibernate

  在編輯 *.hbm.xml 檔案時,myeclipse 帶有自動提示功能,但 eclipse 是沒有自動提示功能的。需要自己手工加上:
          1、開啟專案中任意一個 *.hbm.xml 檔案,看一下檔案頭,形如以下:

[html] view plaincopyprint?
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"    
  3. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<?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.配置檔案:

[html] view plaincopyprint?
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <!DOCTYPE struts PUBLIC  
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"  
  4.     "http://struts.apache.org/dtds/struts-2.3.dtd">
<?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檔案
Key Type: 選擇URI