Search code examples
javaservletsmavenjunithttp-unit

java ee api is missing on project classpath while using httpunit for servlet testing in maven


I want to run the servlet testing example available here using maven. Javaee web api should be declared as provided:

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>httpunit</groupId>
        <artifactId>httpunit</artifactId>
        <version>1.7</version>
        <scope>test</scope>
    </dependency>

However, one of the tests in the example throws ServletException. NetBeans complains that java ee api is missing on project classpath. How does one solve this issue?

EDIT

It is not a NetBeans issue, it is a maven issue.


Solution

  • Now this is the most debilitating issue I have ever faced in my Java days. And it is followed by the most ridiculous workaround I have ever seen, ever:

    <dependency>
        <groupId>httpunit</groupId>
        <artifactId>httpunit</artifactId>
        <version>1.7</version>
        <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    

    Yes, permute the declaration of dependencies in the pom.xml (see here for "why") and make javaee-web-api last.