• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Problem accessing a file resource from a web app on Tomcat server

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I want to develop a web app using grails ,which should invoke/execute a VBScript file. I have placed VBScript file in WEB_INF/resources folder.

I am using Runtime.getRuntime().exec() to invoke the VBscript .

I am accessing the VBSCript either by using
def vbPath = getServletContext().getRealPath("WEB-INF/resources/" + "calling.vbs");
or
String path = new File(getServletContext().getRealPath("WEB-INF/resources/" + "calling.vbs")).getAbsolutePath()
The above path values are working fine on Jetty server. but the same is not working on Tomcat. Though the above path values are returring the corrct values on both cases.

For local(Jetty) deployment the path value returning is : C:\Grails\workspace\MyProject\web-app\WEB-INF\resources\calling.vbs
On Tomcat deployment tha path vaue returning is : C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\MyProject-0.1\WEB-INF\resources\calling.vbs

I am thinking that, we can not access a file from Servlet/Web .
Could you please some one advise me how to accesss a file from a webservice on tomcat. It may be a local resource or WEB-INF folder resource on deployment machine.

Thanks.

 
Bartender
Posts: 21726
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the J2EE standard, a deployed webapp is a WAR (or EAR) file, both of which are in JAR (ZIP) format.

The getRealPath() method is therefore treacherous, since there's no actual filesystem path to resources that are stored within the WAR, only a path to the WAR itself.

While Tomcat often does "explode" WARs into actual directories and files, it's not a good idea to create webapps that depend on this. You are better off putting your script in an external directory and directing the webapp to that location. If you prefer, you can make the actual filesystem path of that script or its directory be a configuration option (in web.xml) or a JNDI object.
 
prabhodh mekala
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:According to the J2EE standard, a deployed webapp is a WAR (or EAR) file, both of which are in JAR (ZIP) format.

The getRealPath() method is therefore treacherous, since there's no actual filesystem path to resources that are stored within the WAR, only a path to the WAR itself.

While Tomcat often does "explode" WARs into actual directories and files, it's not a good idea to create webapps that depend on this. You are better off putting your script in an external directory and directing the webapp to that location. If you prefer, you can make the actual filesystem path of that script or its directory be a configuration option (in web.xml) or a JNDI object.



Hi Tim,

I have placed the VBScript file on local directory , I have read it through String path = new File("C:\\TEST\\calling.vbs")).getAbsolutePath(); . On dev environment on Jetty server, the web app is working fine. But when I make a war file and deploy on Tomcat server, the web app never works.

Please could you provide some sample example on how to do it?

Thanks
 
Tim Holloway
Bartender
Posts: 21726
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While technically, there's nothing wrong with what you coded (although I prefer the "unix" filename syntax to avoid Backshlash Hell), it's kind of overkill. All you should need is:


Add suitable environmental settings, exception handlers, and stdio redirectors as needed.

Calling getAbsolutePath() on a File created from an absolute path just does a lot of work and then undoes it. getCanonicalPath() might be different, but that method doesn't get used as often.
 
prabhodh mekala
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I have noticed a strange behaviour with Tomcat 7.0.23. First I have installed the Tomcat 7(Windows service installer), I have deployed my web application on the Tomcat server. My web application failed to access the local resource file. My application main functionality is : it executes a VBScript, the VBScript inturn calls another Execl file. The Excel file converts the given excel sheets into xml files.
so the flow is WebApp > Runtime.getexec(VBScript) > Excel file > Exel file to XML.

VBScript and Excel files are placed in war file. I am reading the path of these files using getServletContext.getRealPath("\").

But fortunately I have downloaded the Tomcat 7(zipped version). I have extracted the zip version and started the tomcat manually. Now I have deployed my web app on the zipped version of tomcat, my application works as expected. It was executing the VBSCript file, then Exel file then converted the given exel sheet XML.

So now my question is "is there any difference between tomcat.exe vs tomcat.zip versions". How can I make my application running on the Tomcat7(exe or Wiondows Service Installer). Because our deployment server is Tomcat(Windows Service Installer version).

Your help could be appreciated.

Thanks,
Regards,
Prabhodh.
 
I was her plaything! And so was this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!