Java 外部jar在启动后崩溃

Java 外部jar在启动后崩溃,java,freeze,launcher,Java,Freeze,Launcher,我目前正在开发一款2D小游戏,因为我很懒,不想总是把游戏的最新版本发送给我的朋友,所以我制作了一个启动器,通过从FTP服务器下载最新版本来更新游戏,如果他们的版本过时了。这个很好用。但游戏本身也有问题 这是我开始游戏的方式: File file = new File(directory + sep + "thegalidor.jar"); Desktop desktop = Desktop.getDesktop(); if(!isOffline){ //If the player has no

我目前正在开发一款2D小游戏,因为我很懒,不想总是把游戏的最新版本发送给我的朋友,所以我制作了一个启动器,通过从FTP服务器下载最新版本来更新游戏,如果他们的版本过时了。这个很好用。但游戏本身也有问题

这是我开始游戏的方式:

File file = new File(directory + sep + "thegalidor.jar");
Desktop desktop = Desktop.getDesktop();
if(!isOffline){ //If the player has no connection they can still play the game in offline-mode
  if(!txtUser.getText().isEmpty() && txtPw.getPassword() != null){
    if(Downloader.getCanLogin(txtUser.getText(), txtPw.getPassword())){ //The player has to login first, if they have a connection to the FTP-Server
      try {
        desktop.open(file);
        System.exit(0);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
} else {
  try {
    desktop.open(file);
    System.exit(0);
  } catch(IOException e){
    e.printStackTrace();
  }
}
dircetory变量设置为user.home+游戏文件保存的目录。sep变量只是操作系统特定的file.separator。游戏启动时没有任何问题,我可以按原样玩游戏。我可以加载保存文件或启动新的保存文件。但当我试图保存游戏时,它只是冻结,没有任何输出

这是我的保存方法:

public static void saveGame() {
  URL resource = Main.class.getResource(saveFile);
  File file;
  BufferedWriter bw;

  try {
    file = new File(resource.toURI());

    file.delete();
    file.createNewFile();

    bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));

    Level level = gsManager.getClientLevel();

    bw.write(level.getPath());
    bw.newLine();

    bw.write(level.getPlayer().getXPos() + " " + level.getPlayer().getYPos() + " " + level.getPlayer().getHealth());

    bw.close();
  } catch (IOException | URISyntaxException e) {
    e.printStackTrace();
  }
}
保存文件在游戏jar中,当我在没有启动器的情况下启动游戏时,一切都正常工作,只有当我使用启动器启动游戏,然后想要保存游戏时,它才会冻结。
有什么方法可以阻止我的游戏一直冻结吗?

你不能在运行时编辑jar中的内容。eclipse在调试模式下如何工作,但这似乎是个问题,谢西姆对此不确定,但我不知道eclipse是否真的制作了一个jar来运行文件。没有真正的理由这么做。仅供参考,它在Eclipse中运行的原因是Eclipse没有从项目生成jar,而是运行bin目录中的文件。因此,类路径中资源的文件操作在Eclipse中工作。但它们在分布式应用程序中不起作用。这是我必须训练我所有的开发者的东西。不能混合使用类路径资源和文件操作。