Separate GWT CodeServer from Jetty - java

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.

Related

vaadin4spring security sample: failed to load widgetset

I am desperately trying to build a little Vaadin project with login secured pages/views. I have found vaadin4spring and thought I could start based on the security sample. However, after importing the project and running it, I am receiving the message (without any changes at the project):
Failed to load the widgetset:
./VAADIN/widgetsets/org.vaadin.spring.samples.security.Widgetset/org.vaadin.spring.samples.security.Widgetset.nocache.js?1424243461387
I have also tried to compile the widgetset manually, which wasn’t possible at the beginning (missing WebContent folder). After converting the project to use WebFacets and adding Dynamic Web Module the compilation was possible. But the widgetset related error message was still the same.
Can anybody help me with this problem? I have the feeling that it is just a little thing I am missing.
I think you have imported the sample somehow wrong, because you are talking about WebContent folder. I bet you are using eclipse (because of WTP related WebContent folder).
Delete the old project from workspace and possible settings files eclipse created
Choose File->Import->Maven->Existing Maven Project
You probably want to make one fresh install before you start to play with the project: from the top level "parent-pom" project, choose with right click: Run as -> Maven install. Get a cup of coffee, the build will take a while.
Enjoy!
To start e.g. the Security sample you seem to have tried, just execute the main method from org.vaadin.spring.samples.security.ApplicationInitializer. In eclipse, right click on the class and choose Run as Java Application and the app will launch with embedded Tomcat at http://localhost:8080/

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.

How to run GWT in production mode

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.

file saved outside from eclipse is compiled automatically?

I have a spring mvc web project configured in eclipse. Web application is running via tomcat server built inside eclipse. I have seen as soon as I change something and save the code, the project is rebuild and new web application is available for browsing. All this build-deploy is done behind the scenes.
If I have my project running on a server through eclipse and I changed one of project files from some an external tool like notepad++ and save it from there, will my new changes be build-deploy automatically in eclipse?
If not how can I achieve this functionality?
I guess if you will refresh project in eclipse after changed some file from notepad it will automatically be deployed.
Have you tried Window / Preferences / General / Workspace then check
Refresh using native hooks or polling
Refresh on access
Refresh the Project inside which file is changed and the project would/should be built automatically and published

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