0

I am trying to compile my java file but it is giving error: error:package doesn't exist

Project Directory structure:

project/src/test/java/com/mypack/Test.java

My test file include:

import org.apache.ibatis.jdbc.ScriptRunner;
import org.h2.tools.Server;

I am doing: javac Test.java at location src/test/java/com/mypack but it is not resolving the dependencies and giving package doesn't exist error.

error: package org.apache.ibatis.jdbc does not exist
import org.apache.ibatis.jdbc.ScriptRunner;
error: package org.h2.tools does not exist
import org.h2.tools.Server;
Yatin Kanyal
  • 195
  • 1
  • 13
  • You have not provided the actual javac command or the actual error message. However, given the path you show, the sourcepath should be 'src/test/java' and you should be compiling the com.mypack.Test.java class. – Tom Drake Aug 19 '20 at 17:37
  • i tried this but it didn't work. I tried javac com/mypack/Test.java at src/test/java – Yatin Kanyal Aug 19 '20 at 17:40
  • You will have better luck getting an answer if you post the details . Please include the exact javac command, exact error message, and the 'current directory' if you are using relative paths in your javac command. Based on your updated question, its pretty clear that ibatis is not on your classpath – Tom Drake Aug 19 '20 at 17:45

1 Answers1

1

I don't what build system you are using but realizing that you are using javac i guess you are manually compiling it. Please make sure including other libraries as well. Please see the link this might help you how to include libraries in java without using an IDE

  • Isn't it possible that my class path will include all the jar files used in my project just as Intellij do? – Yatin Kanyal Aug 20 '20 at 06:21
  • In intellij too we need to manually add jar in the project and then when we compile using intellij, it itself lauches javac command with -classpath (Automatic). To resolve that too you can you build system like gradle or maven but i think u wont need that if you are just making scrap programs to test basic things. – Divya Prakash Varshney Aug 20 '20 at 13:14
  • i have the dependecies under build.gradle file. – Yatin Kanyal Aug 21 '20 at 08:06