【问题标题】:StrutsTestCase The /WEB-INF/web.xml was not foundStrutsTestCase 找不到/WEB-INF/web.xml
【发布时间】:2011-06-07 02:58:48
【问题描述】:

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

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

这个问题我google了一下,建议setContextDirectory(new File("../web"));解决:

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

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

|───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 下。

【问题讨论】:

  • 可以通过new File().getCanonicalPath()找到文件路径。但我不知道你到底是什么意思。

标签: testing struts web.xml


【解决方案1】:

我刚碰到这个。运行测试时,WEB-INF/web.xml(可能还有 struts-config.xml 等)必须位于您的类路径中。确保 netbeans 将 /build/web/ 放在测试类路径中。

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

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

【讨论】:

    【解决方案2】:

    从目录结构看来:setContextDirectory(new File("../../../../web"));

    【讨论】:

      【解决方案3】:

      所以,根据上面的树,new File() 的位置应该是“web”: protected void setUp() throws Exception { super.setUp(); setContextDirectory(new File("web")); }

      【讨论】:

        猜你喜欢
        • 2023-03-23
        • 2014-05-13
        • 1970-01-01
        • 2011-11-19
        • 1970-01-01
        • 1970-01-01
        • 2011-01-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多