Deploy GWT to Tomcat (servlet not running) - gwt

What is the correct way to deploy a GWT app to Tomcat? I have made a GWT app with server side code (servlets). It works in Hosted mode but only when I copy the WAR folder (after compiling) to Tomcat webapp directory and rename the war folder correctly.
My GWT app servlet is in URI /mygwtapp, so I renamed the folder mygwtapp. The app loads correctly with the problem that servlet do not run i.e. /mygwtapp/servlet does not run.
All the libraries needed by the server side code are in the WEB-INF/lib folder. What could be the reason for this?
Thanks.

By default, Tomcat serves an app named 'mygwtapp' from the context path '/mygwtapp'. (Whereas the GWT built-in jetty serves it from the context path '/'.)
Your servlet paths will usually be '/mygwtapp/*'. This means, that in conjunction with the context path, your servlets are now accessible from '/mygwtapp/mygwtapp/*'. (Try it: Simply enter the full URL in your browser - the Servlet will usually complain that something is missing, or that it doesn't support GET, but you'll know for sure now, where it lives.)
So you have two options:
Tell the client side to call the servlets at '/mygwtapp/mygwtapp/*' (I think, this is already taken care of automatically when using the #RemoteServiceRelativePath annotation)
Adjust the Context path of the web application in Tomcat, as explained in http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

One other option is to use GWT.getModuleBaseURL() then in your client side code append servlet name. This will make it work on jetty or Tomcat without any special config.

Related

Eclipse Jetty keeps asking for webdefault.xml

I'm deploying all necessary Jetty bundles to an OSGi-container and launch a server instance. Yet although I'm deploying jetty-webapp and the corresponding jar contains the file org\eclipse\jetty\webapp\webdefault.xml, at startup I'm presented the error
java.io.FileNotFoundException: D:\eclipse\org\eclipse\jetty\webapp\webdefault.xml
(D:\eclipse is the eclipse installation I'm launching from)
Why isn't Jetty using the file it comes with? When I copy the file from the jar to the requested location, Jetty runs fine - but that can't be a feasible solution.
I wouldn't mind having to provide the file, but then again I don't know how to pass the path to Jetty. The launch happens directly from within an eclipse launch configuration, no maven involved.
If you use jetty-osgi-boot.jar, than you have to set the following system properties:
-Djetty.home.bundle=org.eclipse.jetty.osgi.boot
-Djetty.port=8080
The value is the symbolic name of the osgi-boot bundle that contains a default configuration.
More info in the documentation of jetty: http://www.eclipse.org/jetty/documentation/current/framework-jetty-osgi.html
Alternatively you can use the org.apache.felix.http.jetty bundle. You can find information about it here: http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html
Or you can use Pax Web: https://ops4j1.jira.com/wiki/display/paxweb/Advanced+Jetty+Configuration
I used the jetty-osgi before. Nowadays I use the felix stuff as it can be configured via configadmin. Pax-web can also be used via configAdmin. I have not tried it yet but as much as I heard it has its benefits (e.g. better servlet context handling with HTTPService)

deploying spring mvc web app to tomcat: classpath issue

I am developing a small web app using Spring MVC framework. Basically, the app provides web interface, where user can upload XML file and verify it against specific XSD file. I put my XSD file within "src/main/webapp/XSDfoler". I put this folder into my Tomcat's classpath. (I am using Tomcat embedded into my Eclipse). In my code, in order to access my XSD file I simply used
ClassPathResource("myXSD.xsd");
It works fine. Now, I created a .war file from my webapp and tried to deploy it to another standalone Tomcat. When trying to run it, it give NullPointer exception since it cannot locate "myXSD.xsd" file. So as I get it, I have to somehow include this file into classpath of this standalone Tomcat instance. I looked for some nice step by step tutorial or article explaining how to deploy webapp to a standalone Tomcat server after doing the development in IDE with embedded Tomcat. Could anyone please explain/help. Thanks!
Try
ServletContext context = httServletRequest.getSession().getServletContext();
InputStream is = context.getResourceAsStream("/XSDfoler/myXSD.xsd");
alternatively use getResource() instead of getResourceAsStream()

gwt beginner- getting error when I make an RPC call on server- same code works in gwt dev mode

I have created a simple gwt application (with gwt 2.4) that makes a single RPC call.
When I run this in GWT Dev mode, it runs fine, however when I try to run this on a server-
this is the message that I get --
POST http://app.sparkcrawler.com/com.arvindikchari.auth.App/AuthenticationService 404 (Not Found)
I have copied all files from the WAR folder in my Eclipse GWT project, to the web server's folder. The web server uses Tomcat 5.5(with Cpanel control panel). I copied these files, after successfully compiling the files ("GWT Compile Project")...
What have i done wrong here? Have i missed some files? I have copied everything from war folder, including "WEB-INF" folder and its contents, to the web server.
I think, copying the Eclipse project's WAR folder is not the appropriate way to deploy a GWT application to a server.
You first have to compile for production mode (see Understanding the GWT compiler), then with the resulting JavaScript files, create a WAR including server side classes which you can deploy to a Tomcat server. (See Deploy a GWT Application)
You can use Ant or Maven to automate this process.

URL mapping of servlets and JSP files with Tomcat and Eclipse

I have a web application project in Eclipse that is configured to deploy to a local Tomcat server. Let's call the web application Blah. Here are two questions -- I must be missing something very simple, but I can't find an easy way to change these settings within Eclipse without fiddling with the Tomcat configuration files.
1.
When the application is deployed, the URL I can use to browse to some servlet/JSP is localhost:port/Blah/servlet. I would like to get rid of the Blah prefix.
2.
I would like to set up redirects for some JSP files to "hide" the .jsp extension. For example, I'd like localhost:port/login to be served by localhost:port/login.jsp, preferably without the browser seeing a 30x redirect status code.
3.
I would like to set the default URL, i.e. localhost:port/, to redirect to a particular JSP or servlet (again, preferably without issuing a redirect status code).
Any help, including links to relevant resources, would be greatly appreciated. Please note that I am looking for a way to configure these things from within Eclipse, if possible. (If not possible, I would like to do the minimal amount of changes to the scary Tomcat XML files.)
This means that you need to deploy your application as the root application. It's easily done by naming your war file ROOT.WAR (or your exploded war directory ROOT), or by defining a context for your web app with an empty string as the path attribute.
Then you don't want a redirect, but a forward. Or you simply want to map the JSP (which IS a servlet) to a given path. Define a servlet and a servlet mapping in the web.xml file, as you would for a servlet class, but use <jsp-file> instead of <servlet-class>.
This is done using the <welcome-file-list> element in the web.xml.

Configure project in eclipse so that it ends up in the tomcat "common" class loader

I have two tomcat web applications that need to share information using a singleton. I have already made it work by placing the jared classes in the tomcat common directory. Each webapp then gets the same copy of the singleton. What I would like to do is to integrate this behavior within eclipse. I would like the common classes to be a single project that gets incorporated into the tomcat common class loader every time I start the tomcat server within eclipse. Anyone knows how to configure eclipse to do this?
May be one possibility could be to extend the tomcat class loader in order for that class loader to search in other directories than WEB-INF/lib, this by:
Extending org.apache.catalina.loader.WebappClassLoader and override the findClassInternal method.
Configuring Tomcat to use the extended classloader.
This is done in the appropriate webapp configuration file under the Tomcat conf/Catalina/hostname path with the following element:
...
Then in eclipse, you could set your common project on the "Required projects on the build path", which makes it part of the classpath.
That means your extended classloader must be able to look for other classe:
either in a fixed pre-defined path
or in a pre-defined path within the classpath.
Not tested myself, but may be that can give you a lead on this issue.
A much simpler solution is proposed by noselasd in the comments, taking advantage of the GlobalNamingResources Component of Tomcat.
However, the FAQ does mentions:
When you create a new Tomcat server in Eclipse, the New Server wizard assumes it is not safe to affect the current behavior of the Tomcat installation that this new server will use.
WTP is able to avoid affecting the behavior of the installed Tomcat by using Tomcat's ability to run multiple server instances from a single installation. Thus, the default configuration for each new Tomcat sever you create will be a new server instance of the Tomcat installation associated with the Tomcat runtime selected in the wizard.
If you expect the new Tomcat server in Eclipse to run the same instance that the default batch files in your Tomcat installation run, you will likely be surprised when the Tomcat server in Eclipse doesn't behave as expected.
The Tomcat server configuration can be changed so that it does run the same instance as your Tomcat installation.
You will find here how to modify the server.xml in WTP.
I've managed to get it working. Here is what I did:
Created a common project in the eclipse workspace.
Created the two web applications, called first and second, that should share the common project.
When the web applications are created a Servers project is created with the tomcat configuration.
Change catalina.properties inside the Servers project and add the line shared.loader=/path-to-workspace/common/bin.
This works perfectly for development. Every time a new build is created everything is in sync. For deployment You need to convert the common project into a common.jar and place it in ${catalina.home}/lib.