Even if I looked it up, it didn't come out easily, so I made a note.
$ javac -d /path/to/build/dir/ /path/to/javafiles
$ java -cp /path/to/classfiles/ main.Main
Suppose it is such a hierarchy.
.
└── src
├── app
│ └── App.java
└── hoge
├── Hoge.java
└── fuga
└── Fuga.java
Compile everything. Specify the output destination directory of the generated file with -d.
$ javac -d build src/*/*.java src/*/*/*.java
It will be like this.
.
├── build
│ ├── app
│ │ └── App.class
│ └── hoge
│ ├── Hoge.class
│ └── fuga
│ └── Fuga.class
└── src
├── app
│ └── App.java
└── hoge
├── Hoge.java
└── fuga
└── Fuga.java
The build directory contains the class files properly packaged.
$ java -cp build app.App
Specify the classpath with -cp. The classpath is the root directory for finding class files. Since it is in build, specify it.
In the app.App part, specify the class that contains the main method, including the package name and delimited by dots.
that's all.
Recommended Posts