1

最近アプリケーションを作成し、これを c:/my/folder/app.jar に正常にジャーリングしました。次のケース [スタートアップ #1] では魅力的に機能します。

  • コマンドを開く
  • cd to c:/my/folder
  • java -jar app.jar

しかし、これを行うと、機能しません [スタートアップ #2]:

  • コマンドを開く
  • cd から c:/my/
  • java -jar フォルダー/app.jar

app.jar には、アプリケーションで実行しようとする .exe ファイルが含まれているため:

final Process p = Runtime.getRuntime().exec("rybka.exe");

ファイル rybka.exe が見つからないため、例 2 では機能しません。

助言がありますか?

4

3 に答える 3

4

このようなものは、より良い方法です。jar から exe を一時的な場所にコピーし、そこから実行します。jar は webstart などを介して実行可能になります。

InputStream src = MyClass.class.getResource("rybka.exe").openStream();
File exeTempFile = File.createTempFile("rybka", ".exe");
FileOutputStream out = new FileOutputStream(exeTempFile);
byte[] temp = new byte[32768];
int rc;
while((rc = src.read(temp)) > 0)
    out.write(temp, 0, rc);
src.close();
out.close();
exeTempFile.deleteOnExit();
Runtime.getRuntime().exec(exeTempFile.toString());
于 2009-08-09T11:48:02.987 に答える
1

If the jar will always be in that directory you can use a full path /my/folder/rybka.exe. If not, you can use getClass().getProtectionDomain().getCodeSource().getLocation() to find out the location of the jar and prepend that onto rybka.exe.

于 2009-08-09T09:52:41.050 に答える
1

exeを解凍してみてください

System.getProperty("java.io.tmpdir"));

この場所から実行すると、毎回動作するはずです。

ポール

于 2009-08-09T11:36:54.567 に答える