This may be an incredibly stupid question, but I have a web application that relies heavily on jQuery for many various widgets and aesthetic utilities that I'm trying to migrate into using Vaadin. For starters, I'm attempting to just create your run-of-the-mill "Hello World" application -- built with Maven and deployed to Tomcat -- with Vaadin, and I'm having a problem deploying it. I've been following the turtorial posted here ( https://vaadin.com/book/-/page/intro.walkthrough.html ). Here's my file structure thus far:
HelloWorld
src
main
java
com
business
helloworld
HelloWorld.java
resources
webapp
WEB-INF
web.xml
test
target
pom.xml
I'm guessing that my problem lies somewhere in my web.xml that follows:
web.xml
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>HelloWorld</display-name>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>HelloWorld</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
I've tried my best to follow the examples I've seen, but I have a feeling I'm making a stupid mistake. When I run the project as a Maven Build (tomcat:redeploy), it doesn't appear in my Tomcat Manager. Any ideas? If you need any more information (like what's in my pom.xml), just let me know...
EDIT: Is it better to create a Vaadin Project and convert it to Maven, or vis versa?
MyApplicationClass in application param-value should be the whole qualified class name, like
com.business.helloworld.HelloWorld
(I'm on a mobile phone so I didn't check the syntax, but that should be it.)
Edit: To the second question, there's an Maven archetype that creates an Maven Vaadin project. By using that you won't have to convert either way.
Related
I'm a complete beginner in java development, coming from rails.
I'm following this Heroku tutorial I've git cloned this example project to try deployment on heroku.
Now I have different app, a small back-end for an android app which runs on Tomcat. It's really simple but I dont understand how/where to put the files from my back-end to the embedded-tomcat app (it's Heroku's example) and push it to Heroku.
My back-end (named hatalink) has this form (and it's inside webapps folder in Tomcat)
.
hatalink
└─── WEB-INF
|
└─── lib
| └─── mysql-connector-java-5.1.27-bin.jar
|
└─── classes
└─── hatalink
| └─── All my classes in *.class
|
└─── All my classes in *.java form
└─── web.xml
And the content of my web.xml is all like:
<web-app>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>hatalink.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping>
.... (The same for all classes...)
</web-app>
This works fine on my localhost with tomcat, but how do I add the files that are already working from my back-end project to the example project?
Then again am I going right about this? Is there a simpler way/place to deploy this app? Its really simple, I just want it online.
There is a simpler way since servlets 3.0.
Instead using Deployment Descriptor (web.xml) like you did
<web-app>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>hatalink.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping>
.... (The same for all classes...)
</web-app>
You can use annotations.
#WebServlet(name = "myServlet", urlPatterns = { "/path/to/my/servlet" })
public class YourServletName extends HttpServlet {
Your web.xml file always has to go into WEB-INF/web.xml regardless of what kind of server/service you are using. This would have to be the case for your local Tomcat, too.
Your ASCII art picture shows you hev it in WEB-INF/classes/web.xml, so you'll need to move it.
You never need to package .java files with a web application. I would recommend that you don't include them for a number of reasons.
I am quite new to Java EE and as my first project I created a webservices project in Intellij according to the method described here. When I run the project and deployed it using glassfish and viewed the application in http://localhost:4848/ I can't see view endpoint link in the grid Modules and Components when I had clicked on the app I deployed. Any idea what might be wrong with my methods?
Dose your web-service in the default package ?
I have came across with same issue, and as i passed the web service to custom package and redeployed it ,the view endpoint appeared..
I had the same problem today but I use Eclipse Oxygen and Glassfish 5.0 with JDK1.8.0_151 : It miss last line in the array at the bottom of this screenshot :
After a lot of search and tests, I found a blog ( http://meveekay.blogspot.fr/2016/09/view-endpoint-is-not-available-on.html ) that propose the content of the following file :
WEB-INF/web.xml
In fact, you have just to replace the older content by a more recent.
Explaination :
Situation 1 : When I open a new Maven project from Eclipse Oxygen based on archetype "webapp"; the project contains an older web.xml. The content use again DTD for declaration.
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
Situation 2 : When I open a new JavaEE project from Eclipse Oxygen, the web.xml content use XML schema for declaration.
Finally the good web.xml content for today is this one :
<?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>Archetype Created Web Application</display-name>
</web-app>
After "mvn clean install" to regenerate war file, redeploy it and constat the line with "View Endpoint" link appear ... Enjoy !!!
I have deployed application into GAE. When i try the url as http://aabbbaaacccc.appspot.com/_ah/remote_api. I am getting 404 Error page. I have added in web.xml file. I have given correct app id. It deploys. After deployment successful, An dialog box appears and displays file not found along with notepad.
<servlet>
<display-name>Remote API Servlet</display-name>
<servlet-name>RemoteApiServlet</servlet-name>
<servlet-class>com.google.apphosting.utils.remoteapi.RemoteApiServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RemoteApiServlet</servlet-name>
<url-pattern>/remote_api</url-pattern>
</servlet-mapping>
I need to deploy my app into server and start a Remote api with an other application and share the entites from an other app.
I am struggling with this issue for past 2 days. Please help me.
U can look at the error dialog box in the following link.
http://i40.tinypic.com/bfgzki.png
Thanks.
Appengine should works fine.. i've listed the all details for basic project setup. please look and find what you missed.
The Servlet Class
App Engine Java applications use the Java Servlet API to interact with the web server.
In the directory src/guestbook/, make a file named GuestbookServlet.java with the following contents:
package guestbook;
import java.io.IOException;
import javax.servlet.http.*;
public class GuestbookServlet extends HttpServlet {
#Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
}
}
The web.xml File
When the web server receives a request, it determines which servlet class to call using a configuration file known as the "web application deployment descriptor." This file is named web.xml, and resides in the war/WEB-INF/ directory in the WAR. WEB-INF/ and web.xml are part of the servlet specification.
In the directory war/WEB-INF/, a file named web.xml has the following contents:
<?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>guestbook.GuestbookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>guestbook</servlet-name>
<url-pattern>/guestbook</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
This web.xml file declares a servlet named guestbook, and maps it to the URL path /guestbook.
The appengine-web.xml File
App Engine needs one additional configuration file to figure out how to deploy and run the application. This file is named appengine-web.xml, and resides in WEB-INF/ alongside web.xml.
In the directory war/WEB-INF/, a file named appengine-web.xml has the following contents:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application></application>
<version>1</version>
<threadsafe>true</threadsafe>
</appengine-web-app>
appengine-web.xml is specific to App Engine, and is not part of the servlet standard. You can find XML schema files describing the format of this file in the SDK, in the appengine-java-sdk/docs/ directory. See Configuring an App for more information about this file.
Running the Project
The App Engine SDK includes a web server application you can use to test your application.
select Debug As > Web Application.
Testing the Application
Start the server, then visit the server's URL in your browser. If you're using Eclipse and the Google Eclipse plugin, the server runs using port 8888 by default:
http://localhost:8888/guestbook
If you're using the dev_appserver command to start the server, the default port is 8080:
For details please see following tutorials:
Tutorial 1:
Tutorial 2:
Tutorial 3:
I'm trying to deploy an existing vaadin project to GAE.
But I'm constantly getting an error: ClassNotFoundException: com.vaadin.server.GAEApplicationServlet
This is what I've done:
commented out the #WebServlet annotation in my extends UI class
projec properties, checked: use Google App Engine. Thereby some libraries were added to
my WEB-INF/lib folder: gwt-servlet, jsr107, some appendine-*.
created the appengine-web.xml
created the web.xml:
<servlet>
<servlet-name>MyProject</servlet-name>
<servlet-class>com.vaadin.server.GAEApplicationServlet</servlet-class>
<init-param>
<param-name>UI</param-name>
<param-value>de.mypath.ApplicationUI</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyProject</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I can run my project fine if I use com.vaadin.server.VaadinServlet and run on a local tomcat.
But running on a jetty GAE (or also deploying in the cloud) I get the ClassNotFountException mentioned above.
What is wrong here?
It's been a while since I've used GAE, but when I was it seemed like I had to add some jars to WEB-INF/lib myself, despite everything working fine locally. Later I would get warnings about those same jars, but if I removed them I'ld get NoClassDefFoundException again.
Copying vaadin-server-7.5.10.jar to WEB-INF/lib and using com.vaadin.server.GAEVaadinServlet instead of com.vaadin.server.GAEApplicationServlet has resolved the issue.
I am following this tutorial to create a REst Service using Jersey.
Sometimes i fail to understand fully what the author of the tutorial means but these are the steps that i have followed so far :
1) Created a dynamic web project and named it : de.vogella.jersey.first
2) Installed Maven dependencies on eclipse
3) Converted my project to a Maven project (that means created a pom.xml file)
4) Added the necessary dependencies in pom.xml so that i can use jersey without having to manually add the jar files. I added the following xml :
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.17.1</version>
</dependency>
</dependencies>
5) The author suggests to create a java class and gives some code. I can only assume that he wants us to create a new package in the src folder , name it de.vogella.jersey.first and then create a java class and name it Hello and place the code there. Thats what i did.
6) Then he suggests to open the web.xml file. Theres not such a file in the project though. So i go ahead and create such a file in the WebContent/WEB-INF/lib path. I place the code that he suggest.
7) Next is the step that i fail to understand most. He talks about the web.xml that we just added and more specifically he states:
"The parameter "com.sun.jersey.config.property.package" defines in which package jersey will look for the web service classes. This property must point to your resources classes. "
8) Last step is open the URL http://localhost:8080/de.vogella.jersey.first/rest/hello in my browser. However i get HTTP Status 404 - /de.vogella.jersey.first/rest/hello
With what shall i replace exactly the com.sun.jersey.config.property.package ?
Are the steps that i have followed till now correct , or i misinterpreted something?
For information if you are using Jersey 2 this class has been replaced with jersey.config.server.provider.packages so your resource configuration would be like:
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>de.vogella.jersey.todo.resources</param-value>
</init-param>
The property com.sun.jersey.config.property.package just needs to be set as the package that contains the web service classes. In the tutorial it is de.vogella.jersey.first, and you can see that the Hello class is declared under that package.
In other words, when you deploy the application, Jersey will look for web service classes in the package de.vogella.jersey.first, and in this case it will find the class Hello being declared with the javax.ws.rs.Path annotation, and create a web service endpoint listening on the URL that has been declared with #Path.
However, I have never set such a thing for my Jersey projects. I just put my web service classes in the src folder, and Jersey recognizes them no matter which package I put them inside. This is the minimum configuration that I have with Jersey projects in web.xml:
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</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.your.webservice.classes</param-value>
</init-param>
-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Also if you do not fancy Maven projects, just create a simple Dynamic Web Project and copy the Jersey JARs to WebContent/WEB-INF/lib.
Also, as Qwerky suggested, web.xml has to be in WebContent/WEB-INF/ and .jar files should be copied to WebContent/WEB-INF/lib.
Other than that, the described procedure looks fine!