我想知道是否可以运行程序而不将其打包到罐子里。
例如我们有这个:
.keypress()
这可能吗?主要方法应该从命令行或类似方法执行。
答案 0 :(得分:2)
您可以从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 (.).
答案 1 :(得分:0)
将包含类文件的所有(子)目录添加到类路径中,并使用带有main
方法的类作为java可执行文件的参数。
目录结构是您的包结构。
java -cp ./:./AppRoot:./AppRoot/Misc:./AppRoot/YetAnotherFolder AppRoot.Main
如果解析了所有依赖关系并且在类路径上,这应该有效。