File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes difference b/w 'main method' and 'run on server'... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "difference b/w Watch "difference b/w New topic
Author

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

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Oct 21, 2004
Posts: 43
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.


SCJP 1.2, SCWCD 1.4.<br />What goes around comes around ... with ver 1.1
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Feb 27, 2002
Posts: 8898

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?


Groovy
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Feb 27, 2002
Posts: 8898

This may be helpful

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

This requires JAXP 1.3.
 
jQuery in Action, 2nd edition
 
subject: difference b/w 'main method' and 'run on server'...
 
Similar Threads
passing XML as string to parser method.
finding resources in classpath
extract directory from current jar
Resource not Found error continues even after resource is removed from xml file
Understanding how to write spring ws using JAXB