Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven test fails with NoClassDefFoundError for ANTLR class

Tags:

java

maven

antlr

I am using main/resources/antlr-4.2-complete.jar external library. I already included it on my classpath. But when I run test goal, inside eclipse I receive following message

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.048 sec <<< FAILURE!
checkGrammar(br.com.stoneage.GrammarTest)  Time elapsed: 0.011 sec  <<< ERROR!
java.lang.NoClassDefFoundError: org/antlr/v4/runtime/CharStream

So I know that test goal is not looking for antlr-4.2-complete.jar. How can I solve this?

Here is my POM file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>br.com.stoneage</groupId>
  <artifactId>SASInterpreter</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>SASInterpreter</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

   </dependencies>
</project>
like image 821
p.magalhaes Avatar asked Oct 19 '22 21:10

p.magalhaes


1 Answers

Based on your comments, I would strongly recommend you declare your dependency on the ANTLR JAR in your POM.

One of the primary benefits of using something like Maven is that you no longer need to link to physical JARs on your disk. Instead, you tell Maven you want to use ANTLR, with a statement such as:

<dependency>
    <groupId>org.antlr</groupId>
    <artifactId>antlr4</artifactId>
    <version>4.2</version>
    <!-- If you only need the JAR in test, add the following line too -->
    <scope>test</scope>
</dependency>

Use tools such as http://mvnrepository.com/artifact/org.antlr/antlr4/4.2 to search for other JARs you need.

It sounds like you need to read up about Maven. It's a really cool product, but you can't really start a project without some basic know-how.

like image 187
Duncan Jones Avatar answered Oct 22 '22 10:10

Duncan Jones