File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference b/w 'main method' and 'run on server'...

 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

This is really very serious problem for me. It is very common that a method takes file name as a string and do some processing. I also made a method that does the same. But the problem is when I run my program from main method it runs properly but When I run it on server (web environment) it throw FileNotFoundException because it searches file some where else (probably where the server is). I solved this problem with help of one of the ranchers (sorry, don't remember name!!), Now I am passing input stream to that method (did some modification in method) and I am preparing input stream from class loader (through getResourceAsStream() method), and its working fine in both the cases, because now it is searching file into folders that are in class path.

I hope I am clear till this point.

Now I have a written a method that validate XML against XSD:



It takes XML file correctly because I am passing input stream that I am taking it through class loader.... problem is with XSD. I have no control on XSD. I mean, it takes XSD file name from XML, and searches XSD file from server folder (if I run program in web environment) and obviously not get XSD file and throw FileNotFoundException for XSD file. I am really confuse what should I do .

I hope problem is clear...

If there is some way where I can pass input stream for XSD also, then my problem may be solve...

Any help is really greatful.

Thanks a lot.
[ August 02, 2005: Message edited by: rathi ji ]
 
Manzar Zaidi
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would try geting a InputStream from a file passwing in the file argument like this.

File file=new File("http://DTDlocation.com/dtd.xml");
InputStream fis=new FileinputStream(file);

I can then use this stream for any practical purpose.
 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Saiyed Zaidi:
I would try geting a InputStream from a file passwing in the file argument like this.

File file=new File("http://DTDlocation.com/dtd.xml");
InputStream fis=new FileinputStream(file);

I can then use this stream for any practical purpose.


You are not getting my question, please read my post again.
Thanks.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:


You are not getting my question, please read my post again.
Thanks.


Not sure whether I have understood the question. Why dont you put the XSD file name as a servlet config parameter in web.xml ? This will make sure that any name can be given for the XSD?
 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Pradip. You are right. I tried this code also..



so that I can specify XSD file myself instead of validator takes it from XML file. In this case I am facing two problems:

1]


This gives error. I am not able to understand why because error comes only in case of web environment.

2] When I run it through 'main method' (In web environment it gives above error), it needs absolute path of XSD that I can't be sure.


Still confuse what to do??

Please help...

Thanks a lot.
[ August 02, 2005: Message edited by: rathi ji ]
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be helpful

http://www.xml.com/pub/a/2005/07/06/jaxp.html?page=2

This requires JAXP 1.3.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic