简体   繁体   English

Eclipse:使用导入项目的Struts Actions

[英]Eclipse: use Struts Actions of imported Project

I have 2 Dynamic Web Projects: 我有2个动态Web项目:

  • cms CMS
  • Demo 演示

Using Struts2 I want project Demo to use actions of the project CMS. 使用Struts2,我希望项目Demo使用项目CMS的操作。

In Demo's "Java Build Path" configuration, in the "Project" tab I added the CMS project. 在演示的“ Java构建路径”配置中,在“项目”选项卡中,添加了CMS项目。

在此处输入图片说明

Now in the struts.xml of Demo I have 现在在演示的struts.xml ,我有

<action name="hello" class="cms.helloworld.action.HelloWorldAction" method="execute">

where the package cms.helloworld.action is a CMS project package. 其中,程序包cms.helloworld.action是CMS项目程序包。

在此处输入图片说明

Eclipse see it correctly, in fact with ctrl + right click on the class name it open me the correct Java file. Eclipse可以正确看到它,实际上使用ctrl + 右键单击它的类名可以为我打开正确的Java文件。

Now, in Demo's deployment assembly configuration I added the CMS project, so that also Tomcat can find the relative classes. 现在,在Demo的部署程序集配置中,我添加了CMS项目,以便Tomcat也可以找到相对的类。

在此处输入图片说明

But when I run the project on tomcat server the log says: 但是,当我在tomcat服务器上运行项目时,日志显示:

Grave: Dispatcher initialization failed Unable to load configuration. Grave:调度程序初始化失败无法加载配置。 - action -动作

Caused by: Action class [cms.helloworld.action.HelloWorldAction] not found 原因:找不到动作类[cms.helloworld.action.HelloWorldAction]

It can't find the action on CMS project. 它找不到对CMS项目的操作。

What am I doing wrong? 我究竟做错了什么?

You should merge two projects into one, and put struts.xml into src . 您应该将两个项目合并为一个,然后将struts.xml放入src As far as I remember Eclipse is not able to reference another web project as module, ie you have to copy WebContent manually during build, that is why you shouldn't reference other web projects and a main project is not a Java EE project. 据我所知,Eclipse无法将另一个Web项目作为模块引用,即您必须在构建期间手动复制WebContent ,这就是为什么您不应该引用其他Web项目并且主项目不是Java EE项目的原因。 You should also take into account that Tomcat server is not able to handle Java EE projects if you decide to develop one, for this purpose you should choose full featured Java EE Application server. 如果您决定开发Tomcat服务器,则还应考虑到Tomcat服务器无法处理Java EE项目,为此,您应该选择功能齐全的Java EE应用程序服务器。 Even that you have an option to only one web module. 即使这样,您也只能选择一个Web模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM