Is there a standard easy way to launch Jetty from eclipse for the production mode?
I followed the instructions at http://code.google.com/webtoolkit/usingeclipse.html to setup a new project using gwt and eclipse.
The hosted (debug) mode seems to be already configured to work properly and involves one click in eclipse using "Debug as".
I would like to configure "Run as" to run the production mode in jetty. Is there a good tutorial on the standard way to set this up?
You have to compile your GWT-project before you can "Run As". It's the button with a red box and "G" on it.
Since GWT compiles to java script you don't need jetty if you don't have server-side logic... anyway, in a normal scenario you'll have some server interaction, BUT you're not sticked to jetty; tomcat or other server side technology could be used.
You can deploy the compiled JS to a web server and the server side logic to tomcat, jboss, jetty... even you could interact with php at the server.
Deployment to Google AppEngine is another option, a natural option if you use the eclipse plugin since it's tightly integrated with it.
In eclipse, Jetty is no more than a java process started like any normal java main.
Go to [Run]->[Run Configurations]->[Web Application]->[Your GWT Project] and you'll see a normal java main exec config.
Look at the [Main Class] option -> this is the embeded jetty ..or at
the [VM arguments] for the JVM
The ?gwt.codesvr= param in the URL only instruct the browser plugin to interact with the eclipse plugin embeded jetty in a way that only the modified code is re-compiled to JS and sent to the browser.
If you do not use the ?gwt.codesvr= probabilly you'll have to recompile all the project every time you change a single line of code.
I recommend you to clearly separate the compiled-to-js code and the server side code in different eclipse projects.
I also run the embeded jetty only for the client-side code; the server side code is run in tomcat.
That way I have a clear separation of layers at the time I can debug client-side GWT code and server-side java code.
Related
I'm setting up a project to use MySQL as the datasource and I'm running into a couple problems.
It appears the MySQL drivers for the Java side are incompatible with the built in GWT Jetty instance. Really?
I can configure a TomCat instance and get MySQL Driver working, but I can't debug inline (Client & server together) like I normally would be able to do using the Jetty instance in dev mode, according to Google Docs.
I spent quite a while deciding between a PHP or Java backend, and one of the main advantages besides the GWT RPC mechanism was the fact that GWT provides a nice Development environment if you use Java.
Has anyone encountered the need to use a data source other than appEngine? How did you setup dev environment?
I do believe the MySQL JDBC driver is "compatible" with the embedded Jetty; but maybe you were in an AppEngine project, in which case the embedded Jetty server forbids the use of classes that are not compatible with AppEngine (so you have at dev time a behavior as similar as possible with the production environment on Google's servers).
To debug your server code running in Tomcat, you either need to launch it (the server code) using Eclipse WTP (or equivalent if you don't use Eclipse), or launch your Tomcat instance with the appropriate debug arguments e.g. -agentlib:jdwp=transport=dt_socket,address=8788,server=y,suspend=y, and then debug it as a "Remote Java Application" (in Eclipse, I don't now how they name it in other IDEs).
You can then launch your DevMode in -noserver mode (and in debug) to debug your server and client at the same time (yes, you'll actually have 2 debug sessions).
Note that the doc you refer to (whose latest version can be found here) doesn't deal with debugging the server-side code, as it's highly dependent on the server you use, how and where it's deployed, etc. GWT code on the server side is just a standard servlet, so there's nothing specific to GWT re. how to debug the server-side code.
FYI, we do use a standalone Jetty instance (not the embedded Jetty server) for more than a year using the above setup.
You can use GWT and Tomcat and still be able to debug both client and server side. Look at the jetty startup parameters in Eclipse.
I have been in a similar position few years ago and decided to use Jetty for development and tomcat for testing.
Sounds simple, but I'm having lots of issues.
I want to run a GWT project in a tomcat on Intellij-idea 10.
Does anyone know how to set up the run config?
Regards,
Charles.
You can use '-noserver' option to start Dev Mode under Tomcat. Edit your GWT run configuration by adding '-noserver -port 8080' to 'Dev Mode parameters' field, then run the Tomcat configuration and after that run the GWT configuration.
This all implies that this is a development run, i.e. for local testing/debugging purposes. This is not deployment to production servers. I also assume you have GWT and Web facets defined for this project.
If you need GWT debugging, then you must run as GWT run configuration: here you can only choose a Default server (Jetty that comes with GWT) or an AppEngine Development server (if installed).
If you must run under Tomcat, then:
a. Add a Tomcat server under Settings - App Servers.
b. Create an Artifact - WAR exploded (under project settings). Add all items in right pane to the left pane.
b. Create a Tomcat run configuration with this Artifact.
You first run gwt compiler for compile gwt module, then compiler creates to your hosted .js and .html files. And you can run tomcat as usual but tomcat does not compiles your gwt modules.
I suggest you t use ant to compile gwt modules.
I am experiencing several issues that I can't understand from the first glances. The story is pretty simple, but I guess that the solution is behind some real configuration/deployment problem(s)/inconsistencies.
I have defined a JSP and two servlets. The JSP puts something in the session and the servlets are supposed to fetch the data and to manipulate it. The main symptom is that the servlets do not see the session data, when seeing JSPs in Chrome and Firefox. Interesting, that the JSP/servlets do share the data, when using Eclipse internal browser and also when using Internet Explorer (working on Win7).
Here is a bit long description along with some information (and subsequent symptoms) regarding the local configuration (and, as I believe, there lies the problem): I have installed Eclipse (Helios) under c:\labs\eclipse and unpacked Tomcat (7.0.12) under c:\labs\tomcat. I have also installed the Sysdeo plugin that launches Tomcat.
First, when I launch Tomcat with Sysdeo Eclipse plugin button and then try to access some application-related URL from an external browser - then the main Tomcat page is found, but not the application JSP/pages. However, when I launch Tomcat using the "play/run" Eclipse button (when some JSP page from the Eclipse web project is being selected) - then I can see the rendered JSP page both from Eclipse internal browser AND from any external browser. What is the difference between those two launch modes?
Second, when launching Tomcat via "play/run" Eclipse button only, and calling JSP and servlets either from an internal Eclipse browser or from external Internet Explorer browser, then all the data is being shared correctly by JSP and servlets. However (just for the same launch mode) if I am trying to access the JSP/servlets from external Chrome/Firefox browsers - then the JSP/servlets ARE found, but the data seems NOT to be shared via http session (printed the session id and verified that it is correct).
Third, when I launch Tomcat via "pay/run" button, then I can see the servlet log() printings in Eclipse console ONLY when using the internal Eclipse browser. When JSP/servlets are called from the external browsers - I couldn't find the log printings (but only a few access-related lines in files that reside in Tomcat logs directory).
Tried to summarize the tech issues that look odd to me - I most probably miss some valuable deployment/configuration-related info. Please advice what I am doing wrong and which is the better / correct configuration that will allow the session data to be shared when calling the application resources from all the external browsers. If you need any additional details regarding my configuration/environment - just ask.
Appreciate
Ensure that you're using Eclipse for Java EE developers, not Eclipse for Java developers. It already ships with a Tomcat server plugin builtin. The Sysdeo plugin is pretty old, you don't need it at all and I won't be surprised if that is after all the culprit some of the described problems.
As to running JSP/Servlet using the internal Eclipse browser versus a normal webbrowser, I have myself had bad experiences with the internal browser, I wouldn't recommend to use it for other than "quick testing". However, that it doesn't share the session with another browser is normal behaviour. They do not share the same browser instance anyway. Sessions are not computer-specific, they are browser-specific.
I'd just integrate Tomcat in Eclipse using the EE-provided plugin, start and stop it by the server properties (and not by rightclicking JSP/Servlet and choosing Run or something) and use a real webbrowser to access the pages. To properly getting started with developing JSP/Servlet using Eclipse and Tomcat, I warmly recommend you to use the Coreservlets.com tutorials. At the bottom of our servlets wiki page you can find several direct links.
I'm developing a web UI using GWT. While working only with the widgets I could debug from Eclipse using the Firefox extension, but now that I'm integrating the UI with other OSGi bundles I cannot use this solution.
For deploying the GWT application I create the .war and convert it to an OSGi bundle using BND. Then I launch the OSGi container with all the bundles using Pax Runner and Pax Web and the application works correctly, but when something fails in the generated javascript code I don't have any decent output error or debugging facility.
Is there any way to launch the GWT application in "debug mode" from OSGi?
Any other idea that could help in this scenario?
Update: Could it be possible to instantiate com.google.gwt.dev.DevMode or its part with the browser connector from the Activator?
I've finally managed to launch development mode using OSGi, GWT and optionally eclipse. The solution was on the -noserver flag of the GWT dev mode, it's not aware of the changes in code while the application is running, but it can be used for debugging the compiled code and to receive the exception traces.
I also managed to run the development shell without eclipse, but if you are not interested on this solution you can directly jump to the eclipse integration section.
Without Eclipse (only exceptions, no debug)
You need to know the following information:
Where do you have your source ($SRC)
Where do you have your GWT libraries ($GWT_PATH), specially gwt-user.jar and gwt-dev.jar.
(Optionally) the port from wich your HTTP OSGi server serves the application ($PORT).
The startUp url of your application ($URL)
The package containing the .gwt.xml file for your application ($PACKAGE).
Then you need to run:
java -cp $SRC:$GWT_PATH/gwt-user.jar:$GWT_PATH/gwt-dev.jar \
com.google.gwt.dev.DevMode -noserver -port $PORT \
-startupUrl $URL $PACKAGE
E.g.:
java -cp src/:lib/gwt-2.0.3/gwt-user.jar:lib/gwt-2.0.3/gwt-dev.jar \
com.google.gwt.dev.DevMode -noserver -port 8080 \
-startupUrl httplocalgui.html es.warp.samples.httplocalgui
And finally you only need to deploy your application as usual, in my example I do it with pax-runner and pax-web, using the default port 8080.
With Eclipse
Open the debug configuration for your project
Go to Server tab and uncheck "Run built-in server"
Go to Attributes tab and add "-port 8080" (if 8080 is the port used by your web container). I think that this argument without the built-in server is only used to create the url that the development mode generates to invoke the browser (or that elipse uses to generate an url you can copy and paste in your browser's address bar).
Deploy your application.
Access it from a browser with the GWT extension installed (and don't forget to add ?gwt.codesvr=127.0.0.1:9997)
I had the same problem lately and unfortunately I haven't found any good solution.
Eventually I created mock implementations of all GWT services I am using in my client side code. When I need to debug client side code I am just switching to these services instead of real services using OSGi underneath. Then in Eclipse I can run GWT application in debug mode. This is far from perfect and requires some work with mocks but it works for me (at least now).
I want to run a servlet in Eclipse. For this I have created a dynamic web project and I have deployed my servlet.java file under the WEB-INF folder. I have also added the servlet.jar file. How can I run the file as a java application?
Servlets run in a servletcontainer. Servlets are not "plain vanilla" java applications. See, they do not have a main() method! Servlets listens on HTTP requests and returns HTTP responses through the network. Running the sole servlet class as a plain vanilla Java application doesn't automagically make them to listen and react on HTTP requests.
Apache Tomcat is a popular servletcontainer. Just download and unzip it. Then in Eclipse (I assume that you already have downloaded the Eclipse Java EE version, else drop it all together and redownload the right version), go to Servers view and add the newly installed Tomcat instance. Then create a Dynamic Web Project wherein you pick the newly integrated server instance from the list. Eclipse will then automatically take the Servlet API libraries in the classpath/buildpath (thus, you do NOT need to download a random "servlet.jar file" separately yourself! this is only receipt for major trouble). Then create a Servlet class and register it in web.xml. Then deploy the project to the newly integrated server and start it. Then in your favourite webbrowser go to http://hostname:port/contextname which is usually http://localhost:8080/webprojectname.
To learn more about servlets (and Eclipse and Tomcat) I strongly recommend you to go through those tutorials. You can also search on youtube for video tutorials using the obvious keywords.
Servlets run in servlet/JSP engines, like Tomcat or Resin or Jetty. You normally don't run them outside a container.
You can certainly deploy your app to a servlet/JSP engine and start in from Eclipse. But it's the app server that you run, which then acts as the home for your servlet.
Servlets cannot be run directly as an Java app.
I recommend two approaches:
Refactor your servlet and put your "java" code (what ever generic code you want to call) in another jar that you call from both the servlet and the Java application.
Run the servlet in a container in Eclipse. See http://www.eclipse.org/jetty/
Communicate with the servlet through HttpRequest's and HttpResponse's