私はJava UNOプロジェクトのOS:Ubuntu 14で作業しています。jarファイルを使ってexecを呼び出して、そのjarファイルのサブコマンドの一部を実行しています。エラーメインクラスを見つけられませんでした-jar
String finalOutputMSG = "";
String[] cmd = {JAVA_LOCATION, " -jar ", JAR_LOCATION, " " + inputFile, " -dir ", ".isc", " -out xml"};//java location provides java location, jar location provides jar location, inputfile contains input file's location -dir provides output directory with name .isc, -out is output file with file format for output is xml
同様のコマンドは、すべてのエラーを示すことなく、しかし、私は、ファイルをインポートし、.xmlに例えば.xlsxの別の形式に変換しようとしている場合には適切に走ったエラーを与えています。それが機能するコマンドでは、私はすでに入力ファイルから出力を生成しています。 Netbeansの エラーによって描か
finalOutputMSG = exec(cmd);
/**
* exec() is executed and outputs are displayed
*
* @param String[] command passed to jar
* @return output message containing outputs or output message
*/
private static String exec(String[] cmd) {
String outputMSG = "";
Process proc = null;
try {
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectErrorStream(true);//any error output generated by subprocesses merged with the standard output,
//read using the Process.getInputStream()
///* Start the process */
proc = pb.start();
if (debug) {
System.out.println("Process started !");
}
outputMSG = getOutput(proc);
if (debug) {
System.out.println("outputMSG " + outputMSG);
}
} catch (IOException e) {
if (debug) {
System.out.println("Exception in exec " + e.getMessage());
JOptionPane.showMessageDialog(null, "Exception in exec ");
}
// StringBuilder append = appendToFile.append("Exception in exec ").append(e.getMessage());
} catch (Exception e) {
if (debug) {
System.out.println("Exception in exec " + e.getMessage());
JOptionPane.showMessageDialog(null, "Exception in exec ");
}
} finally {
///* Clean-up */
proc.destroy();
if (debug) {
System.out.println("Process ended !");
}
}
return outputMSG;
}
/**
* Reads output from current process
*
* @param current process
* @return output read in current process
*/
private static String getOutput(Process p) {
StringBuilder outStream = new StringBuilder();
if (debug) {
System.out.println("StringBuilder initialized in getOutput");
}
try {
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
if (debug) {
System.out.println("BufferedReader initialized in getOutput");
}
String line = null;
if (debug) {
System.out.println("in.readLine() in getOutput abt to be read");
}
while ((line = in.readLine()) != null) {
outStream.append(line);
if (debug) {
System.out.println("line in getOutput " + line);
System.out.println("outStream in getOutput " + outStream);
}
outStream.append("\n");
}
} catch (IOException e) {
if (debug1) {
System.out.println("IOException in getOutputs " + e.getMessage());
}
} catch (Exception ex) {
if (debug1) {
System.out.println("Exception in getOutputs" + ex.getMessage());
}
}
return outStream.toString();
}
エラーメッセージ:、私はこの問題について検索しましたが、有用な任意の助けを見つけることができませんでした、私は理解できませんでした
-jarメインクラスを見つけるか、ロードできませんでした。何が欠けている。
「JAVA_LOCATION」と「JAR_LOCATION」の値は何ですか?そして、どうやってこれを動かしているの?エラーメッセージは、Javaが '-jar'という名前のクラスを実行しようとしていると考えていることを意味します。間違ったコマンドを指定しているところです。 – Jesper
@Jesper /home/agnisys01/.openoffice/4/user/uno_packages/cache/uno_packages/svrgyc4k.tmp_/Cal.oxt/images/jresdir/jre_lin/bin/java -jar /home/agnisys01/.openoffice/4/ユーザー/ uno_packages/cache/uno_packages/svrgyc4k.tmp_/Cal.oxt/lib/Batch.jar /home/agnisys01/Desktop/agnisys02Backup/Cal/testcases/ExcelTest1/ODStEST/fullVariant/full_variant_feature_excel.xlsx -dir/home/agnisys01/Desktop/agnisys02Backup/Cal/testcases/ExcelTest1/ODStEST/fullVariant/.ids -out xmlこれはサンプルが渡されたもので、同様のコマンドはちょうど-outで出力を生成するために正常に動作しています。コマンドは間違っていません。 – Rubal
finalOutputMSG = exec(cmd)を使用しました。上記の問題文で述べた方法で – Rubal