问题描述:

I am using Netbeans 8.1

I am trying to create a REST web service. Initially, I followed steps to create in Netbeans from tutorials.

Now, I am trying to create a maven project but is is not working.

I created a new maven java web application and copied the java files to the maven project. Now, i receive 404 when i access the URL.

The project is dployed in Glassfish srver but the server descibes the project as web instead of web, webservices.

SOAPUI and Postman also throws 404 even when the project is deployed.

网友答案:

When any project is created in the IDE like Eclipse or Netbeans, there might be some dependencies provided to application from the IDE. So, when you are using maven, it is required to add dependency in pom.xml of every jar file required for the application.First, check your pom file.

Another cause could be missing of web.xml. Add the file if not present and include the servlet with URL pattern.

For example, if you are using jersy, place the web.xml with

<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Restful Web Application</display-name>

<servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>
                 com.sun.jersey.spi.container.servlet.ServletContainer
     </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>jersey-serlvet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

If the web applcation has only web services (or) if there is no other servlet mapping required, <url-pattern/> can be like <url-pattern>/*</url-pattern>

相关阅读:
Top