我的小应用程序可以在Eclipse上完美运行,但是当我尝试从命令行调用其jar时却出现了问题。该问题看起来像是要保留放置一些属性文件的资源文件夹。
java.io.FileNotFoundException: file:*****************************\EasyDeployment\target\EasyDeployment-0.0.1-SNAPSHOT.jar!\ssh.properties
(the syntax of the file name and the directory name or the value label it is not correct) // I translate this part that was in my native language
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at Configuration.PropertiesMenager.getAllKeys(PropertiesMenager.java:91)
at GraphicInterface.SshChooser.initialize(SshChooser.java:101)
at GraphicInterface.SshChooser.<init>(SshChooser.java:62)
at GraphicInterface.SshChooser$1.run(SshChooser.java:49)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
我的结构:
我的参考文献:
public final static String SSH_PROPERTIES = "ssh.properties";
public final static String PORT_PROPERTIES = "port.properties" ;
public final static String CMD_PROPERTIES = "cmd.properties" ;
public final static String CONF_PROPERTIES = "configuration.properties";
调用这些属性的方法的示例:
public String getPropertiyByKey(String key, String propFile) throws IOException {
Properties prop = new Properties();
FileInputStream objFileInputStream = null;
objClassLoader = getClass().getClassLoader();
String result = "";
try {
System.out.println(propFile);
objFileInputStream = new FileInputStream(objClassLoader.getResource(propFile).getFile());
prop.load(objFileInputStream);
result=prop.getProperty(key);
} catch (Exception e) {
e.printStackTrace();
} finally {
objFileInputStream.close();
}
return result;
}
答案 0 :(得分:1)
始终使用exports.triggerNotification = async function({title,body,token,data,collapseKey,color,sound,tag}) {
const payload = {
android: {
data: {
...data, // extra data
title: title,
body: body
},
notification: {
title: title,
body: body,
icon: 'ic_notification',
color: color,
sound: sound,
tag: tag
},
collapseKey: tag
},
apns: {
"headers":{
"apns-collapse-id":tag,
"apns-priority": "10"
},
payload: {
aps: {
threadId: tag,
sound: sound,
alert: {
title: title,
body: body,
}
}
}
},
data: {
...data, // extra data
title: title,
body: body
},
token:token,
notification: {
title: title,
body: body
}
};
return await admin.messaging().send(payload);
}
而不是getResourceAsStream()
导入文件
getResource()
您可以找到说明here