Hi All, I'm currently writing an EJB that needs to transform an xml file using xslt. It does this using another object that actually does the transforming process. What I need to know is where to place the xml/xslt files in the EAR file as the xslt file may change at a later date and so I don't want to wrap it up in a jar file if at all possible.
Thanks, where would I place the properties file though - within the ejb-jar or elsewhere within the .ear file? I need to do it this way so that I can use a relative URL.
Joined: Jun 21, 2002
Jeanne, could you supply a code snippet to show how I would access a properties file named xmlxsl.properties that is placed in a dir named 'properties' which in turn resides under the enterprise app root dir. This access is from an ejb running in oc4j.
You need to make sure that the classpath contains the xmlxsl.properties (check your container classloading architecture). This is a quick and dirty solution and there are several problems with this approach, since different containers have different classloading strategies. It also could result in very subtle bugs if different versions of the same file are part of the classpath, etc. This are few of the reasons why people prefer using the java.util.ResourceBundle. I personally used the getResourceAsStream approache several times now and I learned how to leave with it :-) Unfortunately for the latest I have no code samples to share with you, but I�m pretty sure you might find some good examples on the net. Regards.
I doubt whether any of this should be done in an EJB container. An EJB should deal with objects. I would normally expect an EJB to return a transfer object which a servlet would marshall to XML for rendering with an XSLT stylesheet. After all, this is stuff for the presentation layer, not the business logic layer.
You will still build and deploy an EAR file containing the servlet and EJB code.
Instead of doing this with loading a property file:
I cut out the whole property thing by doing this:
You won't have to change a property file when your deployment environment changes. You cut out the step of having to read a property file just to find the path (then you have to go load that too). You can put your xsl in your package structure and manage it with your code.
I use a package structure like this: com.mycompany.resources.xsl. Then I put my xsl files in there.
If you are doing J2EE development with EJBs you will need to add each xsl file to the ejb-jar as an external resource. Then they will show up in the package structure.
The squeaky wheel gets the grease. Well, that or replaced...