1

I want to specify the path dynamically. myapp/CopyFolder and myapp/RunFolder's are inside application like myapp/WEB-INF. The code I have given below is in .java file(in eclipse) and in .class file(in tomcat inside myapp/WEB-INF/classname/packagename/). My deployment is in tomcat.

 try {
        functionNamesObject.Integration(
                ".txt",
                path+"\\CopyFolder",
                path+"\\RunFolder",
                "app.exe",
                "Input.txt"
        );

I want path to be dynamic when I call above function. I tried with getResource("MyClass.class") ,new File("").getAbsolutePath(); and System.getProperty("user.dir") but no use. Is there any other way?

5
  • I answered this in another one of your questions. CopyFolder won't exist by default on an installation. You will need to create it manually. As such you will know where you create it, so hard code it into your app. Commented Sep 10, 2013 at 16:11
  • do you want to know the deployment directory (webapps/application) or the WEB-INF folder of your deployed app? Commented Sep 10, 2013 at 16:28
  • @Katona I want to know deployment directory (webapps/application) Commented Sep 10, 2013 at 16:40
  • @SotiriosDelimanolis yes I have to create CopyFolder and RunFolder then I will place the files I want to use there. Commented Sep 10, 2013 at 16:41
  • @niren I think you can get it with getServletContext.getRealPath("") in your servlet. Commented Sep 10, 2013 at 16:45

1 Answer 1

1

You can get the path value as below:

URL resource = getClass().getResource("/");
String path = resource.getPath();

This will return the absolute path to to your myApp/WEB-INF/classes directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.