StrutsTestCase 找不到/WEB-INF/web.xml [英] StrutsTestCase The /WEB-INF/web.xml was not found

查看:57
本文介绍了StrutsTestCase 找不到/WEB-INF/web.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在netbeans7.0下使用StrutsTestCase2.4和struts1.3
运行testCase时,显示:

I use StrutsTestCase2.4 under netbeans7.0 with struts1.3
When running testCase, it shows:

Error initializing action servlet
javax.servlet.UnavailableException: The /WEB-INF/web.xml was not found.

我在谷歌上搜索了这个问题,建议通过 setContextDirectory(new File("../web"));:

I've googled this problem and it is suggested to be solved by setContextDirectory(new File("../web"));:

protected void setUp() throws Exception
{
    super.setUp();
    setContextDirectory(new File("../web"));
 }

但我不太确定 new File() 的位置应该是什么.
我的文件树是

But I am not quite sure what the location of new File() should be.
My File tree is

|───build
│   ├───test
│   │   └───classes
│   │       └───com
│   │           └───stolon
│   │               ├───common
│   │               ├───database
│   │               ├───helpers
│   │               └───struts
│   └───web
│       ├───META-INF
│       └───WEB-INF
│           ├───classes
│           │   └───com
│           │       └───stolon
│           │           ├───algorithm
│           │           ├───database
│           │           ├───helpers
│           │           ├───servlet
│           │           ├───structures
│           │           └───struts
│           └───lib
├───nbproject
│   └───private
├───src
│   ├───conf
│   └───java
│       └───com
│           └───stolon
│               ├───algorithm
│               ├───database
│               ├───helpers
│               ├───servlet
│               ├───structures
│               └───struts
├───test
│   └───com
│       └───stolon
│           ├───common
│           ├───database
│           ├───helpers
│           └───struts
└───web
    ├───META-INF
    └───WEB-INF

我的测试文件在 test-com-stolon-struts 下.

My test file is under test-com-stolon-struts.

推荐答案

我刚刚遇到了这个问题.当测试运行时,WEB-INF/web.xml(可能还有 struts-config.xml 等)必须在你的类路径上.确保 netbeans 将/build/web/放在测试类路径上.

I just ran in to this. WEB-INF/web.xml (and probably struts-config.xml, etc.) must be on your classpath when the tests are running. Make sure netbeans is putting /build/web/ on the test classpath.

如果您使用的是 maven,您需要添加 WEB-INF/*.xml 作为测试资源.

If you were using maven, you would add WEB-INF/*.xml as a test resource.

    <testResources>
        <testResource>
            <directory>WEB-INF</directory>
            <targetPath>/WEB-INF</targetPath>
            <includes>
                <include>*.xml</include>
            </includes>
        </testResource>
    </testResources>

这篇关于StrutsTestCase 找不到/WEB-INF/web.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆