jgp
jgp

Reputation: 2091

Maven classpath issue in test

I am banging my head against the wall on this one...

My app runs well when deployed, really, I wonder why I need tests :).

mvn test gives me:

Tests run: 5, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.008 sec <<< FAILURE!
testAddTo_Email(org.red_angus.utils.mail.test.MailMessageTest)  Time elapsed: 0.007 sec  <<< ERROR!
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/internet/InternetAddress
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)

Here is an abstract of the POM:

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

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>javax.mail-api</artifactId>
        <version>1.5.1</version>
    </dependency>

    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>mailapi</artifactId>
        <version>1.5.1</version>
    </dependency>

    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>smtp</artifactId>   
        <version>1.5.1</version>
    </dependency>

    <dependency>
        <groupId>net.htmlparser.jericho</groupId>
        <artifactId>jericho-html</artifactId>
        <version>3.3</version>
    </dependency>

Help me save my weekend ;)

Upvotes: 0

Views: 124

Answers (1)

Jean Logeart
Jean Logeart

Reputation: 53829

From an other answer on SO:

The javax:javaee-api is only intended for compiling against, not for running against, including unit tests. If you need classes suitable for running against, you really need a full Java EE application server.

That's why it works when your app is deployed on a real app server and not while running tests.

Upvotes: 2

Related Questions