没有资源在使用javac手动编译时加载。

huangapple go评论66阅读模式
英文:

No Resources are loaded when compiling manually with javac

问题

我想要手动使用javac编译Java代码。我正在使用getClass().getClassLoader().getResource("...")加载多个图像。如果我在IDE中运行我的代码,一切都正常。但是,当我尝试使用javac编译时,没有加载资源。有没有办法指定包含所有资源的文件夹?我已经尝试过--add-module,但也没有成功。

我的编译命令如下:javac -d ./out main/ai/*.java main/logic/*.java main/gui/*.java main/network/*.java && java -classpath ./out logic.Launcher

英文:

I want to manually compile Java-Code with javac. I'm using multiple Images loaded with getClass().getClassLoader().getResource("...") If I run my Code in an IDE everything works fine. But when I'm trying to compile with javac no Resources are loaded. Is there a way to specify the Folder which contains all my Resources? I already tried --add-module but this didn't work either.
My command for compiling looks like the following: javac -d ./out main/ai/*.java main/logic/*.java main/gui/*.java main/network/*.java && java -classpath ./out logic.Launcher

答案1

得分: 3

解决方案是将我的资源文件夹路径包含在类路径中。我只需要添加-classpath path/to/my/res,所以我的工作命令看起来像这样:javac -d ./out main/ai/*.java main/logic/*.java main/gui/*.java main/network/*.java && java -classpath ./out:./res logic.Launcher

英文:

The solution was to just include the path to my Resource Folder in the classpath. I just had to add -classpath path/to/my/res So my working command looks like this: javac -d ./out main/ai/*.java main/logic/*.java main/gui/*.java main/network/*.java && java -classpath ./out:./res logic.Launcher

huangapple
  • 本文由 发表于 2020年8月7日 23:16:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63304614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定