Question

I created a maven war project and added javaEE API and openCSV. in eclipse I can see both jars, import classes and use them without any compilation errors.

but when I run the app using tomcat and trying to save a CSV file I get this exception:

java.lang.NoClassDefFoundError: au/com/bytecode/opencsv/CSVWriter

JavaEE api works fine.

I tryed to add compile but it didn't do any good.

this is my pom:

<modelVersion>4.0.0</modelVersion>
<groupId>com.training</groupId>
<artifactId>DevProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>
    <dependency>
        <groupId>net.sf.opencsv</groupId>
        <artifactId>opencsv</artifactId>
        <version>2.3</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

This is the code that throws the exception: CSVWriter writer = new CSVWriter(new FileWriter("file.csv"));

Any ideas?

Was it helpful?

Solution

The default java ee api's are um...messed up.

They are not meant to actually run stuff but only to compile stuff, they don't actually have any content because of some copyright or whatever issue that I forgot about.

So when you define the dependency you should state:

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

Note that additional "scope" and add an actual implementation to your runtime.

Alternatively (what I often do to allow for testcases) you could include an actual implementation like that of jboss.

OTHER TIPS

Try this:

  1. Right click on the eclipse project containing your pom
  2. Click on Properties
  3. Click on Deployment Assembly

Then check that your Maven Dependencies are in the list and that the deploy path in front of them is WEB-INF/lib

Click the Add... button if necessary then Click Apply and OK buttons.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top