1

I want to convert smooks xml-java, so that i need to load source file from mobeeadmin.war/WEB-INF/sample.xml.

Smooks smooks = new Smooks("/WEB-INF/sample.xml");

It is throwing following exception:

    java.io.IOException: Failed to access data stream for resource [/WEB-INF/sample.xml]. Tried (in order):
    10:10:14,113 ERROR [stderr] (http-localhost-127.0.0.1-8080-2)   File System: E:\WEB-INF\sample.xml
    10:10:14,114 ERROR [stderr] (http-localhost-127.0.0.1-8080-2)   File System: E:\jboss-as-7.1.1.Final\bin\WEB-INF\sample.xml
    10:10:14,117 ERROR [stderr] (http-localhost-127.0.0.1-8080-2)   Classpath: /WEB-INF/sample.xml
    10:10:14,125 ERROR [stderr] (http-localhost-127.0.0.1-8080-2)

By default it looks in File System: E:\jboss-as-7.1.1.Final\bin\WEB-INF\sample.xml .I want load from E:\jboss-as-7.1.1.Final\standalone\deployments\myproject.war\WEB-INF\sample.xml.
subodh
  • 6,136
  • 12
  • 51
  • 73
nag
  • 647
  • 6
  • 25
  • 43
  • Check this out:- [Load from classpath](http://stackoverflow.com/a/15320902/2024761) – Rahul Mar 26 '13 at 09:26
  • Thank you @R.J I checked this one,I need to load from smooks object only for that i have to pass either String or InputStream? – nag Mar 26 '13 at 09:39
  • Just pass the String and load it in the constructor. – Rahul Mar 26 '13 at 09:41
  • @R.J yes i have tries it but wont work.even i have tries like this Smooks smooks = new Smooks(this.getClass().getResourceAsStream("/WEB-INF/smooksProfileChangeConfig_xmlToJava.xml")); it throughing null. – nag Mar 26 '13 at 09:52
  • first, forget the constructor thingy. Next, make your path like this:- `/smooksProfileChangeConfig_x‌​mlToJava.xml`. that WEB-INF is not required. That's what is given there in that link. – Rahul Mar 26 '13 at 09:55
  • @R.J i checked this one also .its not allowing smooks in jboss 7.1.x one more this same code is working in fantastic in jboss 4.1.2 in seam. – nag Mar 26 '13 at 09:58
  • @R.J is there any possible to change default path of jboss 7.1.X? – nag Mar 26 '13 at 09:59
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/26920/discussion-between-r-j-and-nag) – Rahul Mar 26 '13 at 09:59
  • @nag I'm not sure how many times I have to tell you that you need to use a java.io.InputStream and get the InputStream from the deployments class loader. What you're doing will not work if you have smooks defined as a module. Also note that AFAIK `WEB-INF` is not on the CP. – James R. Perkins Mar 26 '13 at 15:32

1 Answers1

0
  1. What Smooks takes as a String is a file name. If you take a relative one it's interpreted relative to the start location of your java application. But of course you could take an absolute one too. So E:/data/sample.xml should just work fine.
  2. /WEB-INF/sample.xml can't be on the classpath, as WEB-INF then would be a package name. But those must not contain dashes. In fact it's a resource file of your web application and you can get a stream to load it by ServletContext.getResourceAsStream(java.lang.String path). As JBoss7 is Servlet 3.0 compilant you can get the ServletContext from the HttpServletRequest. However some modern Frameworks give you neither.
  3. If you'd like to get your file from the class path you could move it to WEB-INF/classes and load it via a classloader. However, java is pretty picky with the right one. Most reliable is the ContextClassloader (it's now in the root package):

         Thread.currentThread().getContextClassLoader().getResourceAsStream("sample.xml");
    
Bernd Ebertz
  • 1,317
  • 8
  • 10