Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Murali Vijay
Greenhorn
Posts: 12
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2993
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2993
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Greg, it works fine.
Thanks for your support
 
Greg Charles
Sheriff
Posts: 2993
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shucks, twarn't nothin'!

(The patois is in keeping with the theme of JavaRanch.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic