Package not found; Javac

This is annoying.

I have such a directory structure

-lib
   --some jar files

-packageName
   --Main.java
   --SomeOtherPackage
      --SomeOtherJavaClass.java

Main.java imports SomeOtherPackage. And both java files use jars in lib.

What I am doing is adding jar files independently in CLASSPATH. And then run: javac packageName / Main.java

but it gives an error that the package was not found SomeOtherPackage. Shouldn't dependency be automatically detected and built SomeOtherPackage? What will be the javac and classpath command for the above case?

thank

+3
source share
2 answers

A common practice is to add the package root to the classpath.

When you are already in the root directory of the package, use -cp .. For instance.

cd /path/to/all/packages
javac -cp . packageName/Main.java

JAR , ; ( * nix, :) :

javac -cp .;lib/file.jar packageName/Main.java

, .bat ( in * nix a .sh). IDE, java/javac ..

+3

packageName CLASSPATH, SomeOtherPackage

0

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


All Articles