0

I have a java application Test. Inside this I have two java files. A.java:

import javax.servlet.GenericServlet;

public class A
{
    GenericServlet inter;
}

To compile this I used:

javac -cp servlet-api.jar A.java

It compiled successfully. Now another java file is B.java:

import javax.servlet.GenericServlet;

public class B
{
    GenericServlet inter;
    A a = new A();
}

When I try to use:

javac -cp servlet-api.jar B.java

I get the following error:

error: cannot find symbol.
A a = new A();
^
Symbol: class A
location: class B

P.S: Please ignore the name of classes & jar files involved as it is for demo purpose only.

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • Use a proper IDE and/or a build tool like gradle. Not having to type the build command manually every time will save you a lot of trouble. – Clashsoft Jan 07 '16 at 18:54

3 Answers3

0

Use

javac -cp x.jar;. B.java

To include the current directory in the classpath, then it should work.

spi
  • 626
  • 4
  • 19
0

you usually get cannot find symbol error when you don't have that class in the classpath. you can fix this issue by adding the path of A.class in the classpath

example javac -cp servlet-api.jar; B.java

madhu
  • 51
  • 4
0

Use command: javac -cp x.jar A.java B.java include the current directory in the classpath, then it should work.