0

I am trying to compile and run a .java file using classes that are present in a jar file located in a separate directory.

PROJECT

├───build

│ └───IN HERE

├───checkstyle

├───doc

│ └───yourusername

├───lib

└───src

This is the directory structure, the .jar file is in the lib directory, and my .java file is in "IN HERE". I am completely unsure of how to import the classes from the .jar to my file. I have seen both import package.name;, and simply package name;.

I have the absolute path for both "IN HERE" and "lib" within my system classpath environment variable, but nothing still seems to work.

The java file is simply:

package dnd.models;
//import java.lang.Throwable;

public class Dungeon {

    public static void main(String [] arg){

        //ArrayList
        //private double roll;
        System.out.println("hello world");

    }

}

The .jar is entitled dnd.jar and supposedly has the packages dnd.die and dnd.models.

I have tried compiling and running as the following from the main PROJECT folder:

javac Dungeon.java

javac: file not found: Dungeon.java

Usage: javac <options> <source files>

use -help for a list of possible options

This seems odd to me because the classpath should prompt it to look through the classpath folders, should it not? After that I attempted to use "IN HERE" as my working directory to compile/run, but then I get this error:

javac Dungeon.java --This works

java Dungeon.java

Error: Could not find or load main class Dungeon

I have also tried with commands like javac -cp .;MYDIRS\PROJECT\lib\dnd.jar Dungeon.java

But they do not work either. I have tried dozens of different ways of formatting these kinds of statements, so I am hoping there is something obvious I missed as this is majorly holding me up.

I would expect the java to compile and recognize the package and print hello world without any errors. Anything helps, I'm at a loss.

pcopp
  • 21
  • 4

0 Answers0