【问题标题】:How to get the path of an eclipse project in jsp page如何在jsp页面中获取eclipse项目的路径
【发布时间】:2012-07-11 13:06:43
【问题描述】:

如何获取我当前项目的路径:它是一个使用 maven archetype 创建的动态 Web 应用程序。

我想在 scriptlet 代码中检索我的 jsp 页面中的路径,我使用了不同的代码,但我总是得到 eclipse 的路径 (C:\Users\Amira\Desktop\eclipse\eclipse) 或者tomcat上web应用的路径((C:\software\apache-tomcat-7.0.28\apache-tomcat-7.0.28\wtpwebapps\TestProjectUI)

但我想要我的工作区中的项目路径:C:\Users\Amira\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>

【问题讨论】:

  • 路径,为了什么?这个问题的答案可能会有所帮助!
  • @PaulVargas 我正在运行一个 maven 测试命令,所以我必须先访问 maven 项目的路径

标签: java jsp servlets maven scriptlet


【解决方案1】:

每当我遇到这样的问题时,我都会打印出所有的System.getProperties(),看看是否有一个包含我想要的信息。这可能是您可以在这里做的最好的事情,因为 Eclipse 提供的唯一信息将来自属性。如果您在提供的属性之一中没有信息,您可以自己提供它作为启动配置的一部分,您可以在启动配置中使用 workspace_loc 变量。

【讨论】:

    猜你喜欢
    • 2023-04-08
    • 2011-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    • 2014-11-20
    • 2016-08-24
    相关资源
    最近更新 更多