2016-09-01 7 views
0

私は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メインクラスを見つけるか、ロードできませんでした。何が欠けている。

+0

「JAVA_LOCATION」と「JAR_LOCATION」の値は何ですか?そして、どうやってこれを動かしているの?エラーメッセージは、Javaが '-jar'という名前のクラスを実行しようとしていると考えていることを意味します。間違ったコマンドを指定しているところです。 – Jesper

+0

@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

+0

finalOutputMSG = exec(cmd)を使用しました。上記の問題文で述べた方法で – Rubal

答えて

0

ソリューション:

String[] cmd = {JAVA_LOCATION, " -jar ", JAR_LOCATION, " " + inputFile, " -dir ", ".isc", " -out xml"}; 

私はそうは、端末に乗って、それがうまく働いたコンソールに印刷された値を置き換えて、コマンドを実行しました。 解決方法:使用するコマンドには、末尾にスペースを入れないでください。 Linuxでの端末は「LS」のようなコマンドを解釈しますが、Javaで/任意のプログラミング言語は、それは次のパラメータcmdarray

public Process exec(String[] cmdarray) 
      throws IOException 

の場合ので、lsのために解釈していないので、それがあるように、コマンドを取ります。

String[] cmd = {JAVA_LOCATION, "-jar", JAR_LOCATION, inputFile, "-dir", ".isc", "-out", "xml"}; 
関連する問題