Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create .class files from the command line with package dependencies

So I have the following structure:

HelloWorld
  -> Package1
      -> Class1.java
  -> Package2
      -> Class2.java 

I am trying to complile Class2.java from the command line using:

javac -classpath ../equinox.jar Package2/Class2.java

But i keep on getting the error : package Package1 does not exist

How can I fix this?

like image 504
cxzp Avatar asked Apr 18 '26 12:04

cxzp


1 Answers

Include the current directory in the compilation path

javac -classpath ../equinox.jar:. Package2/Class2.java

Explanation: because the -classpath argument is used the current directory is no longer automatically used in the classpath so needs to be added explicitly.

See the Java programming language compiler for a full description of all command line options

like image 99
Reimeus Avatar answered Apr 21 '26 02:04

Reimeus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!