1

I'm brand-new to Jersey/JAX-RS/RESTful Web Services/etc. and I'm having difficulty with a Jersey archetype called jersey-quickstart-webapp. I'm attempting to use it with Eclipse, Maven, and Tomcat v7 or v8 (I've tried both).

First I got a JSP error:
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path. I resolved that error with this SO question regarding the error. Apparently Maven wasn't treating my project as a Dynamic Web Application.

Then I got a warning about:
Build path specifies execution environment JavaSE-1.7. There are no JREs installed in the workspace that are strictly compatible with this environment. I resolved the second issue with another SO question on the matter. I was originally using JavaSE-1.8.

Finally, I had one last error:
Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Runtime ClassNotFoundExceptions may result.Again, I checked SO on the matter and excluded the associated raw classpath entry from the set of potential publish/export dependencies.

However, I am still given a 404 on my project and I cannot figure out why. I'm using a pom.xml file for this project. The tutorial I'm following is telling me that the correct URL to be using here is http://localhost:8080/messenger/.

Community
  • 1
  • 1
Dumpcats
  • 453
  • 5
  • 21
  • Are you using `http://localhost:port/your-project/webapi/myresource`? – Paul Samsotha May 12 '15 at 22:59
  • http://localhost:8080/messenger/ when attempting to run it from the project folder itself via Right-Click -> Run As -> Run on Server (Tomcat 7). It says that /messenger/ is the missing resource. I also attempted to do the same thing on MyResource.java which is http://localhost:8080/messenger/WEB-INF/classes/org/myName/mySite/messenger/MyResource.java, and returns a blank under missing resource. – Dumpcats May 12 '15 at 23:59
  • If your project is named `messenger`, have you tried `http://localhost:port/messenger/webapi/myresource` – Paul Samsotha May 13 '15 at 00:01
  • I tried `http://localhost:8080/messenger/webapi/myresource/` and got the same 404 result (also `http://localhost:port/messenger/webapi/myresource` verbatim) . Apologies for my noobish-ness I am new to everything mentioned except Java and Eclipse. – Dumpcats May 13 '15 at 00:11
  • Is [this](http://stackoverflow.com/a/30020830/2587435) how you created the project? – Paul Samsotha May 13 '15 at 03:54
  • Yes that is close to how I created the project. I was using `jersey-quickstart-webapp` 2.17 because 2.16 was giving me errors about referencing nonexisting libraries. – Dumpcats May 13 '15 at 04:19
  • Please see below. Try to do that. Let me know what happens. – Paul Samsotha May 13 '15 at 04:30
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77675/discussion-between-dumpcats-and-peeskillet). – Dumpcats May 13 '15 at 04:53

2 Answers2

1

This is not an answer (will be deleted)

Edit: Turned into community wiki. It's not a solution.

Try and add this jetty plugin to the app. Inside the <build><plugins> in the pom.xml file

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.2.6.v20141205</version>
</plugin>

Then Right click on project, Maven -> Build; in the dialog on the goals type jetty:run and try to run the build. This should start an embedded jetty server. Once the console says "Jetty Server started", you should be able to access http://localhost:8080/webapi/myresource. Just want to see if it is a problem with the app.

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • I was able to access my Java file! I'll have to look into why this works, but at least this multiple hour long headache has closure. – Dumpcats May 13 '15 at 04:47
  • Maybe a problem with Tomcat configuration in Eclipse. It's been a while since I ran a Maven webapp on Eclipse, so I'm not sure what the problem is. But at least you know it's not a problem with the app. – Paul Samsotha May 13 '15 at 04:54
0

Fast Temporary solution:

Change webapi to webresources in the url: http://localhost:8080/webapi/myresource

Permanent solution:

Change the file web.xml

<url-pattern>/webresources/*</url-pattern>

to

<url-pattern>/webapi/*</url-pattern>
Farokh KH
  • 23
  • 3