我有一个相当简单的Java程序,具有以下结构:
/src/main/java/ (all the classes in here)
/src/main/resources (marked as resource root in IntelliJ, one png file in here)
/pom.xml
我构建我的Maven项目的方式有点变通办法(因为我无法使IntelliJ&#s的工件系统工作)。我有一个运行/调试配置,使用命令行构建项目:install
(希望我能够很好地解释这一点)。
除了包含.png
文件外,一切正常。
奇怪的是,文件实际上已添加到可执行文件jar
中,但不知何故最终程序似乎根本没有使用它。它可以通过以下方式访问:
BufferedImage image = ImageIO.read(new File(getClass().getResource(url).toURI()));
同样,最终的程序完全正常,除了图像在任何点都不可见。有什么帮助吗?
编辑:png
位于jar
的根文件夹中,提供的URL是一个字符串,它只是png
文件的名称。我应该补充一点,该程序在IntelliJ-Run环境中运行良好(包括png
),但不使用可执行文件jar
。
答案 0 :(得分:1)
在这里找到了对我有用的答案: Access .png image in .jar file and use it
不得不使用
ImageIO.read(new File(getClass().getResource(url).toURI()));
而不是
jar
因为图片位于//read the phone book and put the good value in the string
void Read_ADMIN_PHONE_NUMBER(){
String ADMIN_PHONE_NUMBER;
delay(1000);
sendATcommand("AT+CPBS=\"SM\"", 500) ; //Select the SIM phonebook
sendATcommand("AT+CPBR=1,99", 100) ; // To read ALL phonebook +CPBR: 1,"690506990",129,"ANDROID"---- exemple de reponse copier du serial monitor
if (1 == sscanf(fonaInBuffer, "+CPBR: %*s", &ADMIN_PHONE_NUMBER)) {
Serial.println(F("*****"));
Serial.println(ADMIN_PHONE_NUMBER);
} else {
Serial.println(F("**bad***"));
}
delay(2000);
}
。