Eclipse we-app Error using google cloud - eclipse

Eclipse is returning a couple of quite frustrating errors.
attribute xmlns must be declared for element type web-app
attribute version must be declared for element type web-app
This is the source code for web.xml
I got it from following the instructions from this site.
https://cloud.google.com/appengine/docs/java/gettingstarted/ui_and_code
Here is also the code...
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC
"-//Oracle Corporation//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>guestbook</servlet-name>
<servlet-class>com.example.guestbook.GuestbookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>guestbook</servlet-name>
<url-pattern>/guestbook</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>guestbook.jsp</welcome-file>
</welcome-file-list>
</web-app>
The errors occur on line 5. I'm not sure s to how to fix this problem. Any input would be greatly appreciated.

You can replace the first 5 lines with this:
<?xml version="1.0" ?>
<web-app 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"
version="2.4">
But your app will probably run properly anyway, so you can also disable that Eclipse warning.

Related

404 servlet not found error in eclipse IDE

I'm working on a dynamic web project on eclipse IDE. My web.xml looks like
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>TestTest</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>NewServlet</servlet-name>
<servlet-class>NewServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>NewServlet</servlet-name>
<url-pattern>/NewServlet</url-pattern>
</servlet-mapping>
</web-app>
And here is my javascript code..
Example.js:
$.ajax('/NewServlet',params,function(result) {
var json = JSON.parse(result);
alert(json.data);
});
When I created the NewServlet.java, it didn't get automatically mapped in web.xml. I just manually entered it. Still I'm getting this error 404 not found
NewServlet.java file path is Java Resources->src->(DefaultPackage)->NewServlet.java
Example.js file path WebContent->Js->Example.js
There is problem in AJAX call.
It should be something like this :
$.ajax('NewServlet',params,function(result) {
var json = JSON.parse(result);
alert(json.data);
});
Without "/" check out here for example of AJAX call to Servlet.
Hope this helps.

HTTP Status 404 The requested resource is not available jersey tomcat

I am having trouble to launch my testing app on the tomcat8 server. When i enter the http://localhost:8080/loginService/rest/auth, the error message is "HTTP Status 404 -
type Status report. message: description The requested resource is not available."
And the starting page http://localhost:8080/ works fine.
I put all the jar files(jersey-client, jersey-common, jersey-container-servlet,jersey-container-servlet-core, jersey-server, javax.ws.rs-api-2.0 ....) under the WEB-INF/lib. And loginService is deployed by the server.
the web.xml file under WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
<display-name>loginService</display-name>
<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>loginTest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
my testing app:
package loginTest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/auth")
public class Authenticate {
// This method is called if TEXT_PLAIN is request
#GET
#Produces(MediaType.TEXT_PLAIN)
public String test() {
return "succes";
}
}
Here are the part of the console msg which seems like a problem:
七月 10, 2014 3:06:20 下午 org.apache.catalina.core.StandardContext reload
严重: Exception starting Context with name [/loginService]
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/loginService]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3780)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:293)
at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5539)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1365)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1369)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1369)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1345)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: jersey/repackaged/com/google/common/base/Function
at org.glassfish.jersey.internal.ServiceFinder.<clinit>(ServiceFinder.java:165)
at org.glassfish.jersey.servlet.internal.ServletContainerProviderFactory.getAllServletContainerProviders(ServletContainerProviderFactory.java:66)
at org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer.onStartup(JerseyServletContainerInitializer.java:132)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 8 more
Caused by: java.lang.ClassNotFoundException: jersey.repackaged.com.google.common.base.Function
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1324)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1177)
... 13 more
七月 10, 2014 3:06:20 下午 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/loginService] is completed
And I am using tomcat8 and jersey2.10.1.
I just changed my web.xml file to :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
<display-name>loginService</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>loginTest</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
It seems like your application is missing some of the required libraries or (Since you already have the jercy-common.jar) there is an incompatibility in the libraries already in the classpath.
Therefore I would like to point out a perfectly working(Tested with Tomcat 8) sample in the below link.
Jersey-HelloWorld-Example
Hope this helps.
I had this problem. I just solved it by deleting all web.xml files (inside "target" folder and "main" folder). Then right click on the project in Project Explorer and java EE tools -> Generate Deployment Descriptor Stub. After that just right click again on the project -> run as -> Maven build... Then in "Goals" field write: "clean install" (whithout quotes). Click on Apply, click on Run. Then go to your Tomcat manager, undeploy the old .war file and deploy it again. Then just run it! It worked for me.
According to this link https://www3.ntu.edu.sg/home/ehchua/programming/howto/Tomcat_HowTo.html#TomcatDebug , there are many reasons for this kind of problem to occur. In addition, I had been through this problem before. I solved it through the following way. Take a look at the web.xml heading in tomcat/webapps/ROOT/WEB-INF/web.xml. And make sure your your web.xml looks like that. Specially try to compare the versions. For instance:
Mine was:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
........
..........
</web-app>
The tomcat version that you install can be like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="4.0"
metadata-complete="true"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_4_0.xsd">
........
..........
</web-app>
If you look at both they have version difference and metadata attribute difference. So header of both your web.xml and tomcat/webapps/ROOT/WEB-INF/web.xml must be identical. By changing version number within the header of my web.xml into 4 solved my problem. Whatever version you have, make sure it is identical with the ROOT's web.xml version. Hope it helps

Unable to compile servlet in jetty

I have a google app engine connected project (in eclipse juno) and it contains a simple servlet file but for some reason when I run the project ,the corresponding class file is not getting created inside WEB-INF/classes folder, in fact there is no classes folder inside WEB-INF. and hence I am unable to run the servlet.I will appreciate if someone could suggest some solution.
Below is my web.xml file->
<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.queryname.DeviceInfoEndpoint,com.queryname.MessageEndpoint</param-value>
</init-param>
<servlet-name>QueryServiceServlet</servlet-name>
<servlet-class>com.queryname.QueryTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>QueryServiceServlet</servlet-name>
<url-pattern>/Query/*</url-pattern>
</servlet-mapping>
</web-app>
I get the following exception-->
WARNING: Failed startup of context com.google.appengine.tools.development.DevAppEngineWebAppContext#684528a3{/,C:\Users\User8\workspace\QueryName-AppEngine\war}
java.lang.IllegalStateException: No such servlet: QueryServiceServlet
Regards,
Laura.
Move your <servlet-name> and <servlet-class> into their own <servlet> and see if this solves the problem. currently they are under the <servlet> element of the SystemServiceServlet.

tomcat homepage is opening but 404 on any project that i have made (in eclipse helios)

I have started a project in JSP, I am using eclipse Helios 3.6 and tomcat 6.0 integration with it, the problem is that , when i start the tomcat server from eclipse , it starts normally (Means the hompage is displaying on "localhost:8085"), but when i make a "new dynamic web project" (even very simple project that just display index.html in "web-content" folder) I got a 404 not found error. The directory structure is as follows
I am accessing the project through "localhost:8085/testing", but it shows 404 error like this........
My code for web.xml is also ver simple :-
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>testing</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
Include following lines before <display-name> tag in "web.xml" file, then it'll may help you...
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Requested Resource (servlet name) not found Tomcat Eclipse IDE

I am trying to deploy a servlet on Tomcat from Eclipse using WTP plugin. Eclipse is working fine and Tomcat is also up. As when I open http://localhost:8080 I get the home page of Tomcat. I am following this exact tutorial http://www.vogella.com/articles/EclipseWTP/article.html but when I try to deploy it on tomcat by right clicking on servlet class and run as run on server I get following error. The requested resource (/test/FileCounter) is not available. I searched but could not find anything which could help me. I am using Eclipse Java EE IDE and Tomcat 6. Following is my web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>test</display-name>
<servlet>
<description></description>
<display-name>FileCounter</display-name>
<servlet-name>FileCounter</servlet-name>
<servlet-class>com.servlets.FileCounter</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FileCounter</servlet-name>
<url-pattern>/FileCounter</url-pattern>
</servlet-mapping>
</web-app>
I faced this same problem and just solved it !
In the Project Explorer , expand the Deployment descriptor ( just above the Java resource ) . Then expand "servlet" in that deployment descriptor , their should be your created Servlet. Right click on it and Run as --> Run on server .
But one thing isn't clear to me in Eclipse that web.xml is not defined properly but the servlet is running without it !
I just had this same problem. It appears from some reason when I created the servlet through the servlet wizard, eclipse did not create a web.xml file in the WebContent WEB-INF folder. I don't know why it didn't create it.
I added the web.xml file into the WebContent/WEB-INF folder and when I did that, I had a servlet under deployment descriptor that I could right click on and run as -> run on server
Here is the web.xml file you need:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>test</display-name>
<servlet>
<description></description>
<display-name>FileCounter</display-name>
<servlet-name>FileCounter</servlet-name>
<servlet-class>your.servlet.path.filecounter.servlets.FileCounter</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FileCounter</servlet-name>
<url-pattern>/FileCounter</url-pattern>
</servlet-mapping>
</web-app>
Of course you will want to update your servlet class to the package name you created