0

I have the following structure in my directory :

PROJECT
  - classes
      tunnelvisionlabs
          postgresql
              PostgreSqlLexer.class
              PostgreSqlLexerAtnSimulator.class
              PostgreSqlLexerUtils.class
  - lib
      antlr-4-7.jar

  - BasicTest.java

In BasicTest.java, i have these imports:

package com.tunnelvisionlabs.postgresql.test;

import com.tunnelvisionlabs.postgresql.PostgreSqlLexer;
import com.tunnelvisionlabs.postgresql.PostgreSqlLexerUtils;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Token;
import org.junit.Assert;
import org.junit.Test;

I try to compile with the following command :

javac -cp .:./lib/* BasicTests.java 

I get these errors :

BasicTests.java:28: error: cannot find symbol
import com.tunnelvisionlabs.postgresql.PostgreSqlLexer;
                                      ^
  symbol:   class PostgreSqlLexer
  location: package com.tunnelvisionlabs.postgresql
BasicTests.java:29: error: cannot find symbol
import com.tunnelvisionlabs.postgresql.PostgreSqlLexerUtils;
                                      ^
  symbol:   class PostgreSqlLexerUtils
  location: package com.tunnelvisionlabs.postgresql

In the PostgreSqlLexer and PostgreSqlLexerUtils classes, i have this package declared at the beginning:

package com.tunnelvisionlabs.postgresql;

What do i need to do for my program to find these classes ? I tried adding the classes directory in lib and using the same command as before, so that the classpath also contains the classes directory, but it doesn't change anything.

StuYYY
  • 97
  • 2
  • 12

1 Answers1

0

If I read your project structure correctly, the source folder where BasicTest.java sits is at the same level as the lib folder. If so, then you can using the following javac classpath:

javac -cp .:lib/* BasicTests.java
            ^^^ lib/ is already where you are calling this

Review the following reference answer for more information:

Including all the jars in a directory within the Java classpath

Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263