wood burning stoves*
The moose likes I/O and Streams and the fly likes Location to place the xml file inside the .ear for JAXBinding? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Location to place the xml file inside the .ear for JAXBinding?" Watch "Location to place the xml file inside the .ear for JAXBinding?" New topic
Author

Location to place the xml file inside the .ear for JAXBinding?

Murali Vijay
Greenhorn

Joined: Jan 05, 2011
Posts: 12

Hi friends,

I've multi module Maven2 project. My EAR has a .jar(EJBs) and .war(web content) file.
Inside my EJB i've a JAXB unmarshalling code(xml to java).

At runtime, if i've my xml file outside my .ear file say Ex. F:\\temp\\elements.xml - the below code works fine.


Now i need to place my xml inside the EAR file. Kingly suggest me the location.

Note: I tried placing the xml inside src/main/resource/elements.xml and I called using the below code

but it throws FileNotFoundException.

Thanks
Vijay
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

If you're using Maven, you should put your file into src/main/resources of the project in which this Java code is in src/main/java. Maven will take care of getting the file into the classpath for you. Then change your code to:



I'm pretty sure that will work.
Murali Vijay
Greenhorn

Joined: Jan 05, 2011
Posts: 12

Hi Greg,
The below code is not compiling at all


if I've change the code like
and tested in the local setup, it works fine.

But still the above code is not working when I build my .ear.
If I try to findout the URL of the xml in my Maven project using the below codeim getting only null.
Murali Vijay
Greenhorn

Joined: Jan 05, 2011
Posts: 12

My ear structure is as below

project.ear
|
|----APP-INF
|----META-INF
|
|----project-core.jar
| |
| |--com (folder containing my EJB, from where I will access the elements.xml file)
| |--elements..xml
| |--elements.xsd
| |__ .... and resource files
|
|----project-web.war
|
|---- ... and other files
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

OK, then try:



That's working for me in an EJB class where I've put elements.xml at the root level inside the EJB jar.
Murali Vijay
Greenhorn

Joined: Jan 05, 2011
Posts: 12

Hi Greg, it works fine.
Thanks for your support
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

Shucks, twarn't nothin'!

(The patois is in keeping with the theme of JavaRanch.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Location to place the xml file inside the .ear for JAXBinding?