tomcat - how to create War file for a RESTful web service developed in eclipse IDE -


i ve created sample rest web service writes data in xml file. have hard coded path xml file written. want know how declare local path of file in web.xml file servlet parameter , how path there , use in codebe . need create war file service needs deployed in tomcat. war file should take parameter web.xml file. used eclipse ide develop web service. can tell me how above things ?

here have attached servlet code present inside web.xml file.

<servlet>   <servlet-name>jersey rest service</servlet-name> <servlet-class>   com.sun.jersey.spi.container.servlet.servletcontainer </servlet-class> <init-param>     <param-name>com.sun.jersey.config.property.packages</param-name>     <param-value>com.sample.service</param-value>   </init-param>   <init-param>     <param-name>filepath</param-name>     <param-value>filepath value</param-value>   </init-param>   <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping>   <servlet-name>jersey rest service</servlet-name>   <url-pattern>/api/*</url-pattern> </servlet-mapping> 

com.sample.service package have rest web service class.

assuming created dynamic web project in eclipse, right-click on

project name, > export > war file

and fill in details asks for.

in web.xml, can define filepath below

<servlet>   <servlet-name>myservletname</servlet-name>   <servlet-class>com.mycompany.myservlet</servlet-class>   <init-param>   <param-name>filepath</param-name>   <param-value>d:\hard-coded-path.xml</param-value>   </init-param>   </servlet>  

*updated correct answer per comments *

you're getting nullpointerexception on getservletcontext().getinitparameter("filepath") because context not injected web service method.

and in web service, use code path , write using @context annotation

 @get @produces("text/plain") public string dostuff(@context servletconfig sc) {       string xmlpath = "output filepath is: " + sc.getinitparameter("filepath");     return xmlpath; } 

see here usage , examples of @context


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -