We help IT Professionals succeed at work.

Netbeans puts Build in the web application "getRealPath()"

maxmohave asked
Medium Priority
Last Modified: 2013-12-14
Dear Experts, I have a web  app build using Netbeans 6.1, Java and Tomcat 6.0. This web app I call pbuilder for productBuilder. The web app has the following structure according the "projects" view of netbeans:

     Web Pages

I want to store I my  "secure" files under admin. I put files there like "certification.xml".
Now, in the admin directory I have a file called "viewTest.jsp: with the following scriplet:

String relativePath = request.getServletPath();  //   gives value of /admin/viewTest.jsp
           relativePath = path.substring(0,path.indexOf("viewTest.jsp")); // gives /admin/
 String path = application.getRealPath(relativePath);

the value for path on my computer is "c:\netbeans\6.1\pbuilder\build\web\admin"

The problem is I have NOT stored my "certification.xml" file in this subdirectory so later on when I use path to try and find where I have "certification.xml" I get a missing file.

I also don't see build in the "pbuilder.war" distribution. Can someone explain why this is happending and best practice to get to my "admin" directory?

Thank you,
String path = application.getRealPath(path);
Watch Question


P.S., I should of read my question over once. I apologize. Again, the problem is I'm expecting that the path my all my stuff under admin will be: c:\netbeans\6.1\pbuilder\web\admin but when I run this program netbeans says my path is c:\netbeans\6.1\pbuilder\build\web\admin.

It adds "build".  I didn't epect this, and also I don't think "build" will show in the pbuilder.war distribution.

thanks Max
Have you only tested this on your develment machine? when you deploy the .war file the build directory will be your only directory under webapps. but it will not have the name "build" it will probably have the path "c:\program files\tomcat 6.0\webapps\pbuilder\".

if getRealPath() is called now the file structure for admin returned would be
 "c:\program files\tomcat 6.0\webapps\pbuilder\web\admin". you have the right idea it is just the build directory confusing you.

deploy your war file on a different machine and read the System.out.println()'s in the tomcat log file you will understand better then.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


I'll use this approach.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.