How to run GWT in production mode - java

I am trying to run GWT project in production mode, as per the instructions at https://developers.google.com/web-toolkit/usingeclipse. So my project foo is located as a folder foo in my desktop under th workspace folder. When I right click on the foo project in the Project Explorer, click Google - GWT Compile, I see some message like permutations 1, 2.. etc in the debugging console, after which it says that compilation is complete.
However, contrary to what the Google page says, no additional HTML/Javascript files are generated in the war folder. Also, if I enter foo/war/foo.html in the URL bar, I am getting a timed-out error (even though the page contains only a simple alert call).
Can anyone tell me what is going on here?

If you are running in GWT development mode after the compile
remove the parameter gwt.codesvr=127.0.0.1:9997 in the url given by eclipse
After you compile the code the whole gwt code will convert in to javascript so you can access like an normal HTML page with proper paths .

If your GWT project is a Maven project, and you are using gwt-maven-plugin, you can run mvn jetty:run-war (for example, using that as the goal of an Eclipse Maven Run Configuration): That will GWT compile your project into a war, and run it on localhost, thus running your Prod mode.

This can test ui-only features in Production Mode. That's useful if that's all you need to do, especially if otherwise the running of a server for Production Mode occupies limited resources of your development machine that you'd like to save (whereas occupying them with a running server would be a "waste" if your testing doesn't need to make requests to that server anyways).
If your GWT project...
doesn't make any server requests for data yet (maybe your project is still in its infancy as well), and...
is a Maven project
... you can...
GWT compile your project
Maven package (those directions use gwt-Eclipse-maven-plugin) your project
open the packaged GWT host page (i.e: index.html, or < Your Module >.html, under yourProject/target/yourProject-< snapshot version >/) in a browser. Profit!
This is sufficient to test the project's ui-only features, thus in Production Mode. In fact, if your project has features that make server requests for data, but you aren't testing any of them, then this will still work to test just those ui-only features. Basically, any features requesting server data will not have those requests returned (as there is no server running to do that), but all other features will function, as they are ui-only.
If you need to test features that make server requests for data, then you'll have to run Production Mode via a server (that would respond to the requests). For example with Jetty server, see my other Answer here.

Related

Separate GWT CodeServer from Jetty

I'm working with a GWT-Spring project, normally I use the default configuration to run the project with SuperDevMode (I use IntelliJ).
I'd like to run SuperDevMode without the embedded Jetty and I know to achieve that I just need to use: -noserver
I tried to use that option and at the same time run a Tomcat server using the same artifact I have with GWT to run the backend, but it's not working.
My question is, how can I run different servers, one for the GWT compiler and other for the backend code?
I just want to avoid to recompile the GWT application each time I have to restart the backend.
Let me know if there's a way to achieve this.
Thanks
I am not sure if this is the best practice, but it works.
compile your GWT project
create a dynamic web project
copy the host page, images, css, etc from the web content folder of the GWT project (including the compiled GWT code) to the WebContent folder of the newly created web project.
make sure that the newly created web project does not have GWT Facet in the project properties (otherwise everytime you start the Tomcat server, GWT will compile your source)
add the new project to your Tomcat server Run Configuration and start it
create a GWT Run Configuration (SDM), that looks like that:
and start with Debug
Hope that helps.

How to auto reload app engine dev server?

Im following the tutorial on the App Engine website for 'Google Cloud Endpoints' in Java. Everything works fine and I can run the development server using mvn appengine:devserver. The problem is that when I make any changes to a file (for example, any java file) the dev server doesnt automatically recompile. I need to ctrl-c to kill the dev server and restart it for every code change I make.
Is there a way to have maven automatically detect changes to any files in my project and have it automatically rebuild and restart the dev server?
Unfortunately no. If you want this behavior on your dev server, you need to use Python.
I run in the same issue and there is no real workaround provided by the App Engine to help you doing this.
From the "Using The Google plugin for Eclipse":
With Eclipse, you can leave the server running in the debugger while you make changes to source code, JSPs, static files and appengine-web.xml. When you save changes to source code, Eclipse compiles the class automatically, then attempts to insert it into the running web server dynamically. In most cases, you can simply reload the page in your browser to test the new version of the code. Changes to JSPs, static files and appengine-web.xml are recognized by the development server automatically, and also take effect without restarting the server. If you change web.xml or other configuration files, you must stop and start the server for the changes to take effect.
(https://developers.google.com/appengine/docs/java/tools/eclipse#Running_the_Project)
There is NOTHING comparable in Java (link from "The Java Development Server") (https://developers.google.com/appengine/docs/java/tools/devserver)
There's currently nothing in the App Engine SDK to automatically restart when files change, but that's not to say you can't do it. I ran into the same problem and wrote up a script to listen for file changes as triggers to restart App Engine. It's in JavaScript, so you'll need to install Node.js if you haven't already.
// Install watch-exec
$ npm install -g watch-exec
// Watch the current directory
$ watch-exec --command "mvn appengine:devserver" --watch .
This will immediately start App Engine, and then restart it any time a file changes. If the app crashes for some reason, the script will wait for your next edit before trying to restart.
P.S. That entire script is about 40 lines of code, and you could probably do the same thing in other scripting languages. If you haven't tried writing your own automation before, I'd definitely recommend checking out the source code to see how this works.
I've found using Gradle, GAE, and Spring MVC, the assemble command will put the correct artifacts in place, and the server will re-init the app. It's a little quicker than a server restart.
Using App Engine standard with the cloud.tools appengine-maven-plugin hot swap works fine (most of the time, can be problems when setting up the workspace).
For a multi-module maven project: no need to stop the server or browser,
just push the code changes (maven command package -pl *-server)
& refresh the browser.
Debugging with a debug client currently works perfectly for changing / adding code within methods.

How to display changes in web browser when Building a RESTful Web Service using Spring?

I am following this tutorial:
https://spring.io/guides/gs/rest-service/
After completing the tutorial I run everything in my web browser on my local host and everything seems to work.However when I make changes in the java code (I made errors on purpose) I can still run everything in the web browser. What do I need to do in order for it to change due to my code changes? I guess I should mention that I am using eclipse and have installed maven as a plugin.
You are changing the source code, but not the compiled files. Your service is using the created "gs-rest-service-0.1.0.jar" file. This is not affected by your code changes.
Jump into the tutorial again where it says:
"Build an executable JAR"
This will rebuild your jar file. Afterwards you will have to restart your service like you did in the chapter "Run the service".
Instead of using maven as a plugin a choose to install it in order to use the command prompt.

Eclipse and JBoss not refreshing or rebuilding

I'm having this problem in eclipse (EE) when I change things in my code (even something as simple as the text I'm printing using println) it doesn't get applied. I'm using JBoss and when I rerun the servlet, nothing happens.
Any idea how I can force JBoss/Eclipse to do this? I can't preview anything so it's really annoying if I want to test some new code.
Thanks!
Eclipse publishes the newer versions of your application periodically (its called the automatic publish feature). Either the interval is too large, or you're not waiting sufficiently long enough for re-deployment, or automatic publishing of the application has been disabled.
Sometimes, despite ensuring the above, Eclipse might still not publish the newer classes, in which case you might want to perform a clean build, which causes the newly built classes to be loaded into JBoss.
Sorry to ask such a basic question: Do you save your changes before testing?
Eclipse uses its own compiler to check for syntax errors while you are editing, but you have to save the file before the edits take effect in the application.
I only ask because this could be confusing if you are new to Eclipse, having changed from a different IDE. File permission settings can also prevent your files from being saved or built.
Working on EJB deployed in JBoss with Eclipse IDE.
We have ANT build file, in which first old project is deleted from JBoss,
then compiling classes, & building proper directory structure & deploy as .ear - .sar again in JBoss directory.
Stop JBoss, run build file, start JBoss.
Its a good practice to have a build file to deploy project.

How can I deploy web app on Tomcat from running app

I would like to develop updater app. Lets say I've got:
- Running Tomcat
- Running Updater App on the Tomcat
- Running old version of the app on the same Tomcat
I would like to
- Stop old app
- Undeploy old app
- Deploy new version of app (lets assume that I've got new app war file somewere in Updater app resourcess.
Is it possible to do such remote deployment on Tomcat from another app at all?
To deploy a project to your Tomcat Server from another app you need to:
Add a library into your project “catalina-ant.jar” from the folder: {TOMCAT_PATH}\lib
And in your project to deploy a war file you need to only do:
org.apache.catalina.ant.DeployTask task = new org.apache.catalina.ant.DeployTask();
task.setUrl("http://localhost:8084/manager");
task.setUsername("managerLogin");
task.setPassword("managerPassword");
task.setPath("/UrlToYourDeploadingProject");
task.setWar(new File("c:/Project.war").getAbsolutePath());
task.execute();
Thanks to this solution I'm able to develop project that can update automatically my apps.
Yes. There's a set of tools (well, a .jar) released with Tomcat that's usually used by ant but that can be used by anyone willing to call the code. There are tasks for starting and stopping applications, deploying, undeploying, listing applications and so forth; essentially it's an API that wraps the functionality of the manager servlet.
One moment while I try to dig up the name or a link for you...
Here's Apache's information on this stuff: http://tomcat.apache.org/tomcat-5.5-doc/manager-howto.html#Executing Manager Commands With Ant
... and here's a user, elsewhere, describing in detail how he uses these tasks: http://raibledesigns.com/wiki/Wiki.jsp?page=TomcatAntTasks
You may object that you're not ant. That's true, but there's nothing magic about ant, it's just calling code inside the jar. That code can be called from anywhere else that follows the API.
Here's a tutorial on writing ant tasks: http://ant.apache.org/manual/tutorial-writing-tasks.html
Not quite the same, but it should give you an idea of how the API works.
I see no reason why you shouldn't be able to call this API from within a servlet if you want to.
Alternatively, you could run the manager servlet in your Tomcat and simply access the manager application like a Web service: Use your browser or WireShark to snoop on the traffic between your browser and Tomcat when you deploy an app, and then duplicate that to remote control manager. Me, I think using the tools jar is simpler.
If you use a "project lifecycle" tool, this undeploy/deploy can be automatized in the development cycle.
Saying that, I think about Maven2 and his "maven-deploy" plugin :
mvn compile : java compilation
mvn package : creation of the war file (for a webbapp project)
mvn deploy : stop, undeploy the old application, deploy and start the new version !
After, you can couple this automatization with a continous integration server (like Hudson).

Categories

Resources