您的位置:首页 > 编程语言 > Java开发

MyEclipse Struts Config Editor打开struts-config.xml时错误的解决方法

2010-10-15 22:26 423 查看
  最近几天在MyEclipse中建立工程时,没有使用MyEclipse中的Add Struts Capabilities来加入Struts支持,而是手工进行了配置。

  1、将Struts所需的jar文件copy到WEB-INF/lib目录下

  2、在工程中新建了一个名为"config"的Source Folder,在此文件夹中建立Struts的配置文件struts-config.xml

  3、修改WEB-INF目录下的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- Struts配置 -->
<servlet>
<servlet-name>Action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/classes/struts-config.xml</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 默认页面配置 -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


  然后双击struts-config.xml,准备进行修改,但此时发现默认的MyEclipse Struts Config Editor编辑器打开该文件时出现错误:“org.eclipse.ui.PartInitException: Project newsjq is not configured as a MyEclipse Web-Struts Project. Therefore the MyEclipse Struts Editor may not be used with struts-config.xml. The default XML Editor has been used to open the file instead. ”,此时MyEclipse默认用其MyEclipse XML Editor打开该文件了。

  如何解决这个问题呢?在网上搜索了一下,发现网友巴士飞扬的博客上有一个方法非常有效,用编辑器打开该工程文件夹下的.project文件,在<natures></natures>之间增加一个<nature>com.genuitec.eclipse.cross.easystruts.eclipse.easystrutsnature</nature>配置即可。

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>struts</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.genuitec.eclipse.ast.deploy.core.deploymentnature</nature>
<nature>com.genuitec.eclipse.j2eedt.core.webnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>com.genuitec.eclipse.cross.easystruts.eclipse.easystrutsnature</nature>
</natures>
</projectDescription>


  然后就可以用MyEclipse Struts Config Editor打开该struts-config.xml文件了,这时会在struts-config.xml所在的文件夹(这里为config)下产生一个.struts-config.mex文件,这样在MyEclipse Struts Config Editor中就可以使用其Design视图模式了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐