英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论