• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

XML files in src/main/java are not getting added in war file  RSS feed

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having xml files in src/main/java under package com.src.A. These .xml files are not getting added while created a war file.But if i try to run the project from tomcat integrate with eclipse its able to run.After creating a war and deploying in on web apps it does't find those .xml in that package?

After creating war file from maven i don't see those xml file in that pakage.

Q1)Please let me know what should be added in war plugin to include those xml file?


 
Saloon Keeper
Posts: 10211
216
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because Maven doesn't copy anything from the src/main/java folder. It just tells the compiler that's where the source files are, and that the compiler should put the compiled files somewhere else. Since XML files aren't compiled, they don't result in files anywhere else.

Put your XML file under src/main/resources. Maven is configured by default to treat this directory as a source directory from which it will copy the contents to the target.
 
Bartender
Posts: 20728
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:That's because Maven doesn't copy anything from the src/main/java folder. It just tells the compiler that's where the source files are, and that the compiler should put the compiled files somewhere else. Since XML files aren't compiled, they don't result in files anywhere else.

Put your XML file under src/main/resources. Maven is configured by default to treat this directory as a source directory from which it will copy the contents to the target.



Actually, don't.

Put it under src/main/webapp. The src/main/resource directory is what's used for JAR files. The src/main/webapp subtree will be copied verbatim into the WAR by the Maven WAR plugin. For example, to configure log4j, you'd have a src/main/webapp/WEB-INF/classes/log4j.xml file (or if you prefer, log4j.properties).
 
Stephan van Hulst
Saloon Keeper
Posts: 10211
216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The webapp folder is for web application sources. If the files aren't source files (HTML, CSS, JavaScript, images, etc.) they should probably go under src/main/resources. They will be copied to the WEB-INF/classes folder of the WAR, where they can be accessed from the by code and where they can't be accessed publicly.
 
Tim Holloway
Bartender
Posts: 20728
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that's unnecessarily complicated. You'll almost always have static resources, so stuff in src/main/webapp. And since that entire subtree gets copied - including src/main/webapp/WEB-INF/web.xml (which is not in the classpath) and src/main/webapp/WEB-INF/classes, you have an exact image of what non-compiled resources are going to go into the WAR and not have to remember "this from Column A and that from Column B".
 
Stephan van Hulst
Saloon Keeper
Posts: 10211
216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it comes down to personal taste. I like the distinction, because I can quickly see that "this stuff is internal configuration" and "this stuff is to be hosted publicly". Using the resources folder also abstracts away the 'implementation detail' that internal configuration must be located under WEB-INF/classes. Indeed, doing it this way even displays the package a resource is in as an actual package in NetBeans, whereas under the "Web pages" view it becomes indistinguishable from publicly hosted files.

At any rate, I don't have a very strong reason that somebody should use one over the other, but I don't think it's right to discourage the use of the resources folder in web applications, especially because it was intended to be used for internal resources, and the way Maven treats it is consistent with where the files should end up in the WAR.

As a final remark, for fun I tried out what happens if I add a file src/main/webapp/WEB-INF/classes/test/test.txt and a file src/main/resources/test/test.txt with different contents. The file from the webapp folder ends up in the WAR. I don't know if that's because the resources folder is processed first, and then the file is overwritten, or if the webapp folder is processed first and Maven ignores files that already exist in the target.
 
Tim Holloway
Bartender
Posts: 20728
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the src/main/resources move is core Maven. But stuff like web.xml, which is neither in the WAR's classpath nor in its display elements (and likewise infrastructure files such as faces-config.xml), require a source that can be simply copied tot the product's destination location. And since WEB-INF/classes is part of the WEB-INF target, it's not unreasonable to simply copy everything under webapps without exception.

At any rate, I think I now understand why both sources are used, but the webapps folder includes everything from the resource folder, but the reverse is not true.

One thing IBM taught me by bad example, however, is that if you can get your information from one place you're going to end up screaming your lungs out. So I've made it a practice that there be one definitive source for everything. "Treasure hunts" are no fun when there's a deadline.
 
And inside of my fortune cookie was this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!