5

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>
Adi
  • 2,364
  • 1
  • 17
  • 23
p.magalhaes
  • 7,595
  • 10
  • 53
  • 108
  • Why do you have that JAR in `main/resources`? List it as a dependency in your POM instead and your test code can use it too. – Duncan Jones Dec 09 '14 at 11:25
  • @Duncan: If i want to use a local jar file, as a dependency: http://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-in-maven-project. right? – p.magalhaes Dec 09 '14 at 11:28
  • I'm not saying it can't be done. I'm asking **why** are you doing that? It's not the normal way to do Maven projects, so perhaps there are some reasons we need to comprehend that may affect our answers. – Duncan Jones Dec 09 '14 at 11:29
  • @Duncan: There is no reason. I am totally begginer using maven. It is my first project using maven. – p.magalhaes Dec 09 '14 at 11:32

1 Answers1

4

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.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254