程序启动首先读取配置文件device.xml,服务器是别人写的虚拟端口,程序调试的过程中device.xml是放在当前目录,可是一旦把程序打包成jar文件,再把device.xml文件和jar文件放在相同目录下面就无法加载,并连接服务端口。请大家帮我看看程序有没有问题,没有我再继续想想其他地方是否有问题。public void loadDevice() {
    String path = System.getProperty("user.dir") + File.separatorChar + "device.xml";
    File file = new File(path);
    if(file.exists()) {
        try {

            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
   DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
   Document doc = docBuilder.parse(new FileInputStream(file));
   doc.getDocumentElement().normalize();

   NodeList listOfPara = doc.getElementsByTagName("Device");
   for(int l=0;l<listOfPara.getLength();l++) {
   Element paraElement = (Element)listOfPara.item(l);
   NodeComputer inst = new NodeComputer();
   inst.setName(paraElement.getAttribute("name"));
   inst.setIp1(paraElement.getAttribute("ip"));
   inst.setPort(Integer.valueOf(paraElement.getAttribute("port")));
   inst.setState(NodeComputer.ING);
   if(inst.connInst == null) {
       inst.connInst = new ConnInst(inst);
       inst.connInst.start();
   }
   inst.addApp(Monitor.apps);
   Monitor.devices.add(inst);
}
      MenuFactory.setType(MenuFactory.INST);
      MenuFactory.instList();
     } catch(Exception e) {
e.printStackTrace();
     }
   }

}

解决方案 »

  1.   

    看这里:
    http://yiding-he.javaeye.com/blog/176005
      

  2.   

    试试File f = new File(".");
      

  3.   

    谢谢各位啦,目前程序不是由于找不到device.xml文件造成的
      

  4.   

    经过我在不同的地方加入了打印语句,发现程序不能正常运行是由于
     if(inst.connInst   ==   null)   { 
                  inst.connInst   =   new   ConnInst(inst); 
                  inst.connInst.start(); 
          } 这里的构造新的ConnInst不正常,无法进入构造器。
    请问谁知道为什么吗?