2012-07-11 39 views
0

如何獲取當前項目的路徑:這是一個使用maven原型創建的動態web應用程序。我想使用不同的代碼,但我總是得到日食(C:\ Users \ Amira \ Desktop \ eclipse \ eclipse)的路徑 或路徑((C:\ software \ apache-tomcat-7.0.28 \ apache-tomcat-7.0.28 \ wtpwebapps \ TestProjectUI)如何獲取jsp頁面中eclipse項目的路徑

但我想在我的工作區中的項目路徑:C :\用戶\阿米拉\ junoWorkspace \ TestProjectUI

任何想法可以理解 謝謝

這裏是我的jsp:

<body> 

<% 
if (request.getParameter("btnSubmit") != null) //btnSubmit is the name of your button,not id of that button. 
{ 

    String className = request.getParameter("testclass"); 
    System.out.println(className); 
    String[] command = {"CMD", "/C", "mvn -Dtest=" + className + " test"}; 
    ProcessBuilder probuilder = new ProcessBuilder(command); 

    //You can set up your work directory 
    probuilder.directory(new File("C:\\Users\\Amira\\junoWorkspace\\TestProjectUI")); 

    Process process = probuilder.start(); 

    //Read out dir output 
    java.io.InputStream is = process.getInputStream(); 
    InputStreamReader isr = new InputStreamReader(is); 
    BufferedReader br = new BufferedReader(isr); 
    String line; 
    System.out.printf("Output of running %s is:\n", Arrays.toString(command)); 
    while ((line = br.readLine()) != null) { 
     System.out.println(line); 
    } 

    //Wait to get exit value 
    try { 
     int exitValue = process.waitFor(); 
     System.out.println("\n\nExit Value is " + exitValue); 
    } catch (InterruptedException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 
%> 

     <html:file properties="tonFichier" name="tonForm"/> 


     <p> Please specify a Test :<br> 
      <input type="file" name="testclass" size="40" > 
     </p> 
     <div> 
      <input type="submit" id="btnSubmit" name="btnSubmit" value="Execute Test"/> 

     </div> 
    </form> 
</body> 
+0

路徑,爲什麼?這個問題的答案可能會有所幫助! – 2012-07-11 20:14:09

+0

@PaulVargas我正在運行一個maven測試命令,所以我必須先訪問maven項目的路徑 – 2012-07-11 20:19:05

回答

1

每當我有這樣一個問題,我打印出所有的System.getProperties(),看看是否有一個有我想要的信息。這可能是你在這裏可以做的最好的事情,因爲Eclipse提供的唯一信息將通過一個屬性來實現。如果您沒有提供某個提供的屬性中的信息,您可以將其作爲啓動配置的一部分自行提供,則可以在啓動配置中使用workspace_loc變量。

相關問題