简体   繁体   English

如何从Maven项目中的资源映射中获取文件

[英]How to get files from resources map in Maven project

I have structure of project like this: 我有这样的项目结构:

在此处输入图片说明

and try to create Label with image using this code 并尝试使用此代码创建带有图像的标签

bAddTheme = new Label("Add theme",
                      new ImageView(new Image("images/addTheme.png")));

after compling get error like "Invalid URL: Invalid URL or resource not found". 编译后,将收到类似“无效的URL:无效的URL或找不到资源”之类的错误。 How correctly to write path to file? 如何正确写入文件路径?

Try this: 尝试这个:

bAddTheme = new Label("Add theme",
                      new Image(getClass().getClassLoader().getResource("addTheme/sif.png").toExternalForm()));

@aribeiro怎么说我认为:

new Image("com/GVArt/images/addTheme.png"). Try looking at your folder structure outside of your IDE in order to understand it clearly.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM