Java 运行 没有罐子
Java run without jar
我想知道是否可以 运行 不将程序打包到 jar 中。
例如我们有这个:
-AppRoot
Main.class
-Misc
Math.class
OtherTools.class
-YetAnotherFolder
UsefulFunctions.class
这可能吗?主要方法应该从命令行或类似的方式执行。
将包含 class 文件的所有(子)目录添加到 classpath 并使用 class 和 main
方法作为 [=20= 的参数] 可执行文件。
目录结构就是你的包结构。
java -cp ./:./AppRoot:./AppRoot/Misc:./AppRoot/YetAnotherFolder AppRoot.Main
如果所有依赖项都已解决并且在 class 路径上,这应该可以工作。
您可以运行从 AppRoot 目录
javac -cp Misc/*:YetAnotherFolder/* Main.java //To compile
java -cp Misc/*:YetAnotherFolder/* Main // To run
下面是一些文档
-classpath classpath
-cp classpath
Specifies a list of directories, JAR archives, and ZIP archives to search for class files. Class
path entries are separated by colons (:). Specifying -classpath or -cp overrides any setting of the
CLASSPATH environment variable.
If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the cur-
rent directory (.).
我想知道是否可以 运行 不将程序打包到 jar 中。
例如我们有这个:
-AppRoot
Main.class
-Misc
Math.class
OtherTools.class
-YetAnotherFolder
UsefulFunctions.class
这可能吗?主要方法应该从命令行或类似的方式执行。
将包含 class 文件的所有(子)目录添加到 classpath 并使用 class 和 main
方法作为 [=20= 的参数] 可执行文件。
目录结构就是你的包结构。
java -cp ./:./AppRoot:./AppRoot/Misc:./AppRoot/YetAnotherFolder AppRoot.Main
如果所有依赖项都已解决并且在 class 路径上,这应该可以工作。
您可以运行从 AppRoot 目录
javac -cp Misc/*:YetAnotherFolder/* Main.java //To compile
java -cp Misc/*:YetAnotherFolder/* Main // To run
下面是一些文档
-classpath classpath
-cp classpath
Specifies a list of directories, JAR archives, and ZIP archives to search for class files. Class
path entries are separated by colons (:). Specifying -classpath or -cp overrides any setting of the
CLASSPATH environment variable.
If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the cur-
rent directory (.).