如何将直接访问的资源打包到jar文件中
我最近在Slick2D开发了一款游戏,我直接访问了我的所有图像,例如
Image i = new Image("address.png");
而不是使用将加载资源或使用输入流的类。
我想知道是否仍然可以将所有资源加载到jar中,我将/res
文件夹添加到我的buildpath并使用jarsplice添加我的库和本机但是jar将无法运行,因为它无法找到图像。
Image i = new Image("address.png");
正在查看运行应用程序的根文件系统。 如果要使用jarfile中包含的资源,必须执行以下操作:
Image i = new Image(getClass().getResource("/res/address.png").toURI()); // In case your Image object accepts URI as parameters
编辑
Image i = new Image(getClass().getResource("/res/address.png").toExternalForm()); // Since your object only accept Strings