开发者

StrutsTestCase The /WEB-INF/web.xml was not found

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.

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"));
 }

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
│         开发者_StackOverflow中文版  └───struts
└───web
    ├───META-INF
    └───WEB-INF

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


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.

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>


From the directory structure, it seems : setContextDirectory(new File("../../../../web"));


So, based on the tree above, the location of new File() should be "web": protected void setUp() throws Exception { super.setUp(); setContextDirectory(new File("web")); }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜