make a standalone independent application out of a dynamic web project in eclipse - eclipse

So, I've made a dynamic web project in Eclipse.It uses Jsp and servlets. Now I am told to make a standalone independent application for the same. I tried to google as to how it can be done. Most of them pointed me to use Export->Runnable jar file. But on doing so I can't find my dynamic web project in the Launch Configuration. Now how to make the standalone independent application ?

I've done a similar thing using embedded Jetty which means the application jar provides the web service without having to rely on a web server.

Related

difficulty in deploying struts 2 application

I am a beginner with struts2 and I have few struts2 projects downloaded from a website, but they all are created as simple java projects and not as web-projects, so I am unable to deploy them on my Tomcat or JBoss AS server through Eclipse.
How can simple java projects be deployed on a Java EE server?
Your best bet is download sample applications from Struts2 official sites and deploy them on any of the server of your choice.
Those sample application comes with all required dependencies as well will give you idea about structuring of S2 application as well flow and configurations
I created a structure similar to the one shown on website and manually added all the files required and it worked.

how to integrate Spring and GWT from 2 different projects

I am tying to integrate a gwt project with my already running spring project.
i am using eclispe, and i have a Spring MVC application that receives JSON requests.
i am using the built in Tomcat to run my MVC application.
now i would like to create a new GWT project and have it communicate with my spring project with JSON.
i understand that they need to run on the same ip and port so i would not have to make cross site communication.
if i try to run my GWT application as run-as->Web application (which is the normal way for the project) on the same port as the Tomcat server i get an error that the address is already in use (which makes sense)
i tried creating a new dynamic web project and make it look the same as the GWT project. even though i am able to run the application, nothing happens, and the "entry point" is not run (i am not getting any errors or anything) it just runs the default HTML welcome file and thats it. with out any GWT.
what am i doing wrong, i am surly misunderstanding something about how all this should work.
can anyone help me out please.
You need to select that you are running on an external server:
That is a question that can't just be answered with yes or no. It all depends on your overall architecture and what you are trying to achieve.
As I said, if it is both the same application I'd recommend to integrate the Spring project into the web project. (and if that's the case, the spring project does not need to be a web project)
If the spring project is its own application and maybe running on a different server, keep them separated. Extend the spring project so it offers the functionality (via ejb or webservice) the gwt-web project needs.
Nevertheless, I recommend you do some reading about how Java EE applications should be designed and what the different tiers (client, server/service, business, etc) are for. Oracle/Sun offers some good articles. For example: http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/ or http://docs.oracle.com/javaee/5/tutorial/doc/bnaay.html#bnabb.

Can we check if the web project is working without deployment in Eclipse?

I just started web development, here is a simple example: i write a form submit jsp file and deployment descriptor web.xml to map the logical name used for request and servlet class , and controller servlet handle the http request and use printwriter to print the information in the request.(Don't have the model in this example.)
I know the simple way is to use ant to build a war and put into the web container(Like tomcat), but do i need to do it every time to see if the project is running? Or have a quick way to debug and see the result in eclipse?
A servlet container is the runtime environment for a Java web application. There are several open-source servlet containers available. Tomcat & Jetty are two popular ones. Both have plugins available that will allow you to do all your development and deployment from within Eclipse:
Tomcat & Eclipse
Jetty & Eclipse

GWT/Grails Project Structure

Does somebody already have some experience embedding gwt in other
client pages except the standard html file?
I want to use gwt as front end and grails as backend. Communication
should be handled over rest json interface so that is loosely coupled.
How do i structure my project at best? Should I create 2 independend
projects or should I stick them together?
At the beginning I had some problems with debugging my gwt application
as it was part of the grails project. Now I copied the compiled js
script to my webapp folder and included it in a grails page. Debugging
gwt in noserver mode worked ok. The problem is , how do I solve my
deployment later at best as I dont want to copy my js everytime by
hand? Already tried the grails gwt plugin but its difficult to debug the gwt application and I even do not want to use the service stuff provided with the plugin.
I thought its a good idea to have 2 maven modules on for grails and one for gwt. Later 2 war files(one grails, one gwt) will deployed on Tomcat, so I also can change gwt client stuff without deploying grails again. How do i manage the brige from grails to gwt best? Just call the standard html in a div from grails page?
I am using maven for building my project.
Thanks for all your help
I have written 2 posts about this topic. In the first one I show Grails+GWT in the same application, using the Grails Gwt Plugin. It appears you already tried that approach. In the second post, I show how to do it with 2 seperate applications, talking JSON between each other using RequestBuilder to request the grails app (that serves JSON responses).
For The deployment in production, you should have Maven doing this job for you.

how to run the servlet in eclipse?

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