how to run a java class in another folder with jar file

i'd like to run a java class on other folder, i have a mysqlcon.jar on the current path and a PetsGUI.class on ./classes/

when i try to run it by doing

java -cp .:mysqlcon.jar -d classes/PetsGUI

i receive

classes/PetsGUI not found

if i move mysqlcon.jar on classes and type

java -cp .:mysqlcon.jar PetsGUI

on classes/ it runs, so the code is correct. what's the correct command to run it?

Upvotes: 0

Views: 258

Answers (1)

JB Nizet
JB Nizet

Reputation: 691635

So you need the jar file, and the classes directory in the classpath:

java -cp ./classes:mysqlcon.jar PetsGUI

java doesn't expect a file path as argument. It expects the fully quelified name of a class. And that class is then searched on the classpath.

Upvotes: 1

Related Questions