The Maven Convention
Anything that is placed within the "src/main/resources" folder will be accessible from the classpath. In the case of a web application (deployed WAR), the content will will be generated into the "WEB-INF/classes" section of the WAR file.
In this case, I have a lucene directory copied here:
Fig 1: View from within Eclipse |
package com.mycompany; import java.io.File; import javax.servlet.ServletContext; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; @Path("/path") public class MyREST { @javax.ws.rs.core.Context ServletContext context; @GET @Path("/get") @Produces(MediaType.APPLICATION_JSON) public Object getit(@@QueryParam("text") String text) { String fullPath = context.getRealPath("/WEB-INF/classes/lucene"); logger.info("Acquired Lucene Path from Context (path = %s, exists = %s)", fullPath, new File(fullPath).exists()); // perform the query logic ... // return the JSON result } }
Note the use of the ServletContext to access the resource.
The generated WAR file looks like this:
Fig 2: Maven-generated WAR file |
References
- [StackOverflow] Files under src/main/resources go into WEB-INF/classes
- [StackOverflow] Additional configuration for the Maven POM
- You can specify directories and files relative to the POM that should also be copied into the WEB-INF/classes directory.
Nice post. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated posts…
ReplyDeleteData Science course in Chennai
Data science course in bangalore
Data science course in pune
Data science online course
Data Science Interview questions and answers
Data Science Tutorial
Awesome post with lots of data and I have bookmarked this page for my reference. Share more ideas frequently.
ReplyDeleteDevOps certification in Chennai
DevOps Training in Chennai
AWS Training in Chennai
Data Science Course in Chennai
ccna course in Chennai
Python Training in Chennai
R Programming Training in Chennai
Angularjs Training in Chennai
RPA Training in Chennai
Blue Prism Training in Chennai
This comment has been removed by the author.
ReplyDeleteAttend The Data Scientist Courses From ExcelR. Practical Data Scientist Courses Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Scientist Courses. Data Scientist Courses
ReplyDeleteThank you for sharing wonderful information with us.Really useful for everyone data scientist courses
ReplyDeleteThanks for sharing this information. I really like your blog post very much. You have really shared a informative and interesting blog post with people..
ReplyDeletedata science institutes in hyderabad
I have bookmarked your site since this site contains significant data in it. You rock for keeping incredible stuff. I am very appreciative of this site.
ReplyDeletedata analytics training in hyderabad