问题
How to get the path of my current project : it's a dynamic web application created with maven archetype .
I want to retrieve the path in my jsp page in scriptlet code , i used different codes but i'm always getting the path of eclipse (C:\Users\Amira\Desktop\eclipse\eclipse) or the path of the web application on tomcat ((C:\software\apache-tomcat-7.0.28\apache-tomcat-7.0.28\wtpwebapps\TestProjectUI)
but i want the path of the project in my workspace : C:\Users\Amira\junoWorkspace\TestProjectUI
Any idea will be appreciated Thank you
Here's my 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>
回答1:
Whenever I have a problem like this, I print out all of the System.getProperties()
and see if there is one that has the information I want. This is probably the best you can do here, since the only information provided by Eclipse will come through a property. If you don't have the information in one of the provided properties, you can provide it yourself as part of your launch configuration, you can use the workspace_loc
variable in the launch config stuff.
来源:https://stackoverflow.com/questions/11440705/how-to-get-the-path-of-an-eclipse-project-in-jsp-page