Configuring JAR file class paths

Recently, I just created a Java project using Eclipse that requires 2 JAR files (phiget21.jar and mysql.jar)

Everything works fine when I run the program in Eclipse, and I noticed that the jar files are saved in the "lib" folder.

Soon I will transfer the program from my computer so that it can be used on other machines, so I decided to create a batch file to compile all classes and then run it.

However, I am having problems locating jar files. In the batch file, I need the command: set classpath =.: ..; mysql.jar: ../ phidget21.jar, before compiling Java classes?

I read that dots (...) have something to do with directories, but are not quite sure how to implement them.

My program is currently saved in the following places:

Project / src / .java files (.jar files are also placed here, and also I thought this might simplify the task)

Project / lib / .jar Files

Any help would be greatly appreciated!

+4
source share
2 answers

when setting the class path, one dot (.) means the current directory. Since jar files are in the current directory, you just need to go to your current directory using the cd command on the DOS command prompt, and then use

set classpath = .;filename.jar;another filename.jar 

Here. represents the current directory, and a semicolon separates each class path.

You can even set the path to multiple jar files using the wild card * character, which can be read as all .

+5
source

You need something like

 java -classpath lib/foo.jar:. com.company.Program 

you can also use wildcards with java 6. see here

so it will be higher

 java -classpath lib/*:. com.company.Program 
0
source

Source: https://habr.com/ru/post/1402898/


All Articles