2016-09-01 7 views
0

Java UNO 프로젝트, OS : Ubuntu 14에서 작업 중입니다. jar 파일을 통해 jar 파일의 일부 하위 명령으로 실행되도록 명령을 전달하여 exec를 호출합니다. .오류 메인 클래스를 찾을 수 없거나로드 할 수 없습니다. -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 

유사 명령은 오류를 표시하지 않고 있지만 파일을 가져오고, 오류를주고 다른 형식으로 예를 들어 .XLSX .XML에로 변환하려고 경우에 제대로 달렸다. 명령이 작동하면 이미 입력 파일의 출력을 생성했습니다. 넷빈즈 오류에 의해 설명

 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이 예제가 전달되었습니다. 비슷한 명령이 출력을 생성하기 위해 정상적으로 실행 중이면 값이 변경됩니다. 그래서 명령은 잘못이 아닙니다. – Rubal

+0

finalOutputMSG = exec (cmd)를 사용했습니다. 그것을 실행하는 방법에 문제가 성명에서 위에 언급 된 – Rubal

답변

0

해결책 :

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

내가 콘솔에 인쇄하고 명령이 너무 터미널에 도착 실행 된 값을 대체, 그것은 괜찮 았는데. 해결 방법 : 사용할 명령에 끝에 공백이 없어야합니다. 리눅스 터미널은 "ls"의 같은 명령을 해석하지만, 자바/모든 프로그래밍 언어, 그것은 다음과 같은 매개 변수 cmdarray 인수

public Process exec(String[] cmdarray) 
      throws IOException 

의 경우에, 그래서 LS에 대한 해석하지 않기 때문에 그대로 명령을한다 .

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