[英]FileNotFoundException in runnable jar
I have an application that works perfectly in the eclipse launcher but not in the executable jar, I have copied the src into the jar and the.properties but I get this error:我有一个应用程序可以在 eclipse 启动器中完美运行,但不能在可执行文件 jar 中运行,我已将 src 复制到 jar 和 the.properties 中:
Error in ConfigXML.java: problems with src/main/resources/config.xml
java.io.FileNotFoundException: C:\Users\victo\Desktop\IS1\config.xml (The system can not find the path specified)
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 sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at configuration.ConfigXML.<init>(ConfigXML.java:84)
at configuration.ConfigXML.<clinit>(ConfigXML.java:76)
at gui.ApplicationLauncher.main(ApplicationLauncher.java:20)
null
Exception in thread "main" java.lang.NullPointerException
at java.util.Locale.<init>(Unknown Source)
at java.util.Locale.<init>(Unknown Source)
at gui.ApplicationLauncher.main(ApplicationLauncher.java:24)
These are that lines of the ApplicationLauncher.java:这些是 ApplicationLauncher.java 的行:
public class ApplicationLauncher
{
public static void main(String[] args)
{
ConfigXML c=ConfigXML.getInstance();
System.out.println(c.getLocale());
Locale.setDefault(new Locale(c.getLocale()));
System.out.println("Locale: "+Locale.getDefault());
And the ConfigXML:和 ConfigXML:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<businessLogic local="true">
<businessLogicNode>0.0.0.0</businessLogicNode>
<businessLogicPort>1099</businessLogicPort>
<businessLogicName>Bets</businessLogicName>
</businessLogic>
<database local="true">
<databaseNode>0.0.0.0</databaseNode>
<dbFilename>src/main/resources/bets.temp</dbFilename>
<dataBaseOpenMode>open</dataBaseOpenMode>
<databasePort>6136</databasePort>
<user>admin</user>
<password>admin</password>
</database>
<locale>en</locale>
</config>
The config.xml is in the resources folder of the jar so I don't know what this happens, thanks. config.xml 位于 jar 的资源文件夹中,所以我不知道会发生什么,谢谢。
The solution is to paste the src folder next to the jar file, I have pasted it inside the jar file too using WinRar.解决方法是将 src 文件夹粘贴到 jar 文件旁边,我也使用 WinRar 将其粘贴到 jar 文件中。 It is because there is a line in the config xml that points to src/resources as the path of the needed resources
这是因为配置 xml 中有一行指向 src/resources 作为所需资源的路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.