java定位项目包怎么弄,java – 在jar包中定位资源

我有一个静态类,在类中,图像被加载到Buffered

Image对象中,如下所示:

File groundTopImageFile = new File("src/main/resources/ground - grass top.png");

现在,当我使用Maven2创建一个可执行jar时,一切正常,除了它找不到图像文件.我检查了jar,图像文件都放在了jar的根目录中,所以我尝试使用:

File groundTopImageFile = new File("ground - grass top.png");

但没有成功.同样,我不能再在Eclipse中使用相同的代码了.有没有办法在jar和Eclipse中使这个工作?

这是我的Pom.xml文件:

4.0.0

com.WetWindmill

Sheepness

Sheepness

0.0.1-SNAPSHOT

Equilibrium reaction visualized with sheep :)

junit

junit

4.4

test

org.slf4j

slf4j-log4j12

1.5.8

org.apache.maven.plugins

maven-compiler-plugin

1.6

1.6

org.apache.maven.plugins

maven-dependency-plugin

unpack-dependencies

generate-resources

unpack-dependencies

org.apache.maven.plugins

maven-jar-plugin

controller.Sheepness

com.WetWindmill.Sheepness

under development

www.WetWindmill.com/Projects/Sheepness/

${basedir}/target/dependency

${basedir}/src/main/resources

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值