Java 可运行jar中的FileNotFoundException

Java 可运行jar中的FileNotFoundException,java,xml,eclipse,jar,nullpointerexception,Java,Xml,Eclipse,Jar,Nullpointerexception,我有一个在eclipse launcher中工作得很好的应用程序,但在可执行jar中没有,我已经将src复制到jar和.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

我有一个在eclipse launcher中工作得很好的应用程序,但在可执行jar中没有,我已经将src复制到jar和.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)
以及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>

0.0.0.0
1099
打赌
0.0.0.0
src/main/resources/bets.temp
打开
6136
管理
管理
EN
config.xml在jar的resources文件夹中,所以我不知道会发生什么,谢谢。


解决方案是将src文件夹粘贴到jar文件旁边,我也使用WinRar将其粘贴到jar文件中。这是因为config xml中有一行指向src/resources作为所需资源的路径

什么是ConfigXML?ConfigXML写得很糟糕。这在jar文件中永远不会起作用。jar中的对象不是文件,您不能使用文件API访问它们。这不是解决方案,而是一种变通方法!资源文件夹的内容将位于jar文件中,但至少在使用maven构建的情况下,位于jar文件的“根”和类路径中。您的配置文件也可以执行类似于
classpath:bets.temp
的操作吗?这是一个非常糟糕的解决方案。@Ivonet配置xml就像一个创伤,为了保持我的心智健全,我已经在我的内心深处封存了它。@softwareener我不知道您还要求xml配置文件做什么。
<?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>