0


I am coding in simple text document and executing java code with command line with javac command. i want to use jar file which is in directory like /abc/public/assi1 and i have code which is in directory like /abc/assi1. I am including the jar file with import statement in the class myClass.java which is in directory /abc/assi1/myClass.java i am getting errors.

It is not recognizing the things which are in the jar file.

Could some one please help in this.

Thanks

2
  • Use a proper IDE and all your problems might be magically solved. Commented Mar 1, 2012 at 14:26
  • If you really insist in using it like that, you need to add your custom .jar to both compile and runtime classpath... Commented Mar 1, 2012 at 14:27

2 Answers 2

4

You can compile your code like this from the directory /abc/assi1:

 javac -cp .:/abc/public/assi1/your.jar -d . your-java-class.java 

Then you can run your code like this from the directory /abc/assi1:

 java -cp .:/abc/public/assi1/your.jar your-java-class 

-cp option sets the class path for you on command line. It adds the required jar file and the current directory . into your class path.

Sign up to request clarification or add additional context in comments.

Comments

2

The jar has to be inside your java path.

You have to write something like this.

javac -classpath \path\to\lib.jar src.java 

1 Comment

and also the anwser from anubhava for runtime, mine is only for the compiler.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.