安装SpringExt以查看schema文件

11 篇文章 0 订阅
2 篇文章 0 订阅

1 SpringExt插件有什么用?

    SpringExt扩展了Spring的schema机制,使得开发者可以借助schema来扩展框架的功能。然而使用schema来编写配置文件时,我们面临一个问题:XML编辑器到哪里去找到schema?例如,我们在Eclipse中打开一个典型的Webx配置文件:
     
<?xml version="1.0" encoding="UTF-8" ?>
<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:services="http://www.alibaba.com/schema/services"
xmlns:loaders="http://www.alibaba.com/schema/services/resource-loading/loaders"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.alibaba.com/schema/services
<strong><span style="color:#ff0000;">http://localhost:8080/schema/services.xsd</span></strong>
http://www.alibaba.com/schema/services/resource-loading/loaders
<strong><span style="color:#ff0000;">http://localhost:8080/schema/services-resource-loading-loaders.xsd</span></strong>
http://www.springframework.org/schema/beans
<strong><span style="color:#ff6666;">http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd</span></strong>
">
...
</beans:beans>

        一般Eclispe会用一个XML编辑器来打开这类文件,然后试着从schemaLocation中取得所需要的schemas,并用它们来验证文件。然而,Webx/SpringExt的schema并不存在于网络上的任何一个地方,而是存在于jar包中,或是在内存中自动生成的。显然XML编辑器不能从这样的schemaLocation中得到什么。
        因此,当我们试图验证(validate)XML文件的时候,编辑器会警告:无法取得schema或DTD。当我们试图让Eclipse自动提示语法信息时,Eclipse会无所适从。

       SpringExt提供了两种插件,可用来解决这个问题:Maven插件,和Eclipse插件。
       • Maven插件 —— 你可以使用它,在localhost本机上启动一个监听8080端口的SchemaServer,通过它就可以访问到所有的schemas。
       • Eclipse插件 —— 通过它,XML编辑器可以直接取得所有schemas的内容。除此之外,Eclipse插件也提供了更多的便利功能,例如:自动引入或清除某个mespace/schema 定义。

2 Maven插件

     通过SpringExt Maven插件,你可以在localhost本机上启动一个监听8080端口的SchemaServer,通过它就可以访问到所有的schemas。这种机制适合于任何一种支持   schema验证的XML编辑器。

2.1 在pom文件中定义插件

    (什么是pom文件? 出门右转 http://blog.csdn.net/ltianchao/article/details/43492743)
       在使用Maven插件之前,必须在要使用插件功能的项目的pom.xml文件中作出定义。如果是多模块的项目(multi-modules),下面的内容必须定义在根项目(即pom项目)  中。
      
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
...
<properties>
...
<springext-plugin-version>1.2</springext-plugin-version>
</properties>
...
<build>
<plugins>
...
<plugin>
<groupId>com.alibaba.citrus.tool</groupId>
<artifactId>springext-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>com.alibaba.citrus.tool</groupId>
<artifactId>springext-maven-plugin</artifactId>
<version>${springext-plugin-version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project

2.2启动schema服务器

     首先确保该项目当前并没有运行。在项目根目录下,执行:
    
mvn springext:run

   上述命令执行以后,打开浏览器,输入网址http://localhost:8080/schema就可以看到类似下面的内容:

         如果这时你重新打开刚才的XML配置文件(最好重启eclipse以清除缓存),就可以看到Eclipse已经能够弹出语法提示了。

 2.3 导出schema

          在项目 根目录下执行:
          
mvn springext:export
         上述命令执行以后,将生成一个target/schemas文件夹,里面包含了所有的可用的schemas。

 2.4 Maven插件的可选参数

         笔者暂时对这部分没兴趣。想要了解的同学可以查阅本文最后的 参考资料。

 3 Eclipse 插件

 3.1 安装插件

        运行Eclipse,从Help菜单中,打开Eclipse Marketplace。
        搜索关键词webx,找到Webx/SpringExt Plugin,点击Install按钮。

      
     
     怎么样,图大吧。

   3.2利用插件编辑webx/springext配置文件

     安装完成Eclipse插件以后,然后打开任何一个Webx/SpringExt的配置文件。你会发现,打开的是一个稍微有点不同的XML编辑器。
     


      自动语法提示 —— 在键入时,eclipse会自动弹出语法提示;或者,你也可以通过eclipse的快捷键来激活语法提示(完全类似于编辑Java代码)。
      引入Namespaces —— 在键入时,eclipse会提示你引入可用的namespaces。每个namespace代表一个SpringExt Configuration Point或Spring的一个可扩展功能。引入一个namespace,就会创建一个xmlns条目,以及相应的schemaLocation。

参考资料  :

   《Webx3 教程》:http://www.openwebx.org/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值