how to implement sample jms, springs program in my eclipse - eclipse

I'm new to jms and springs and eclipse as well. i'm trying to implement jms example using Springs in MyEclipse 7.1, and i have been referring the following url.
http://java-x.blogspot.com/2006/12/implementing-jms-with-spring-messaging.html
But Iam unable to understand how to execute the program, it contains a servlet but does not have any html or jsp page, should i create a web project for it or java application? How do i run the program.
Thanks and Best Regards.

You should create a web project to hold the servlet. A web project will have a directory for java source and a directory for web content (images, html, jsp, etc.). Make sure that you put the servlet code inside the java source directory. You will also need to register the servlet in web.xml unless it is a Java EE 5 servlet with annotations.
To run your servlet, right click on it and select Run As -> Run on Server

Related

Webservice from WSDL using Eclipse

I have a WSDL file and I would like to create a webservice from that using Java ("Contract first approach"). I used the WSImport-Tool from JAX-WS (Java version 1.6.0_07) on the command line to generate Java-code stubs. This worked fine and I received the following Java files:
Add.java
AddResponse.java
ObjectFactory.java
package-info.java
Test.java
TestPortType.java
But how do I go on from here?
I am using Eclipse. There I could set up a new "Dynamic Web Project" with Target Runtime = "Tomcat 7.0". In Configuration do I have to choose "Axis2"? (Tomcat 7 and Axis2 are already setup locally).
I am lost at this point and do not know how to keep going.
Does it make it easier to create the webservice using Axis2 or do you recommend using JAX-WS? Or is there an even better option?
How and where do I include my WSDL file so it gets deployed to Tomcat 7?

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()

Running servlet within Eclipse requires libs to be defined 3 times - am I doing something wrong?

Hullo - issue is this:
I wrote a servlet in Eclipse which requires mysql-connector-java-5.1.22-bin.jar
To compile I need to add the jar via the project's "Java Build Path"
To deploy I need to add the jar to the project's "Deployment Assembly"
To run the servlet within eclipse I need to add the jar to the servlet's Run Configuration -> Classpath
It's not the end of the world re-re-repeating myself like this, but it does seem odd.
Given that Eclipse gets a lot of other stuff correct I'm guessing / hoping that maybe I'm overlooking some feature to avoid this silliness (I cannot imagine a scenario where you'd benefit from entering this in 3 different spots ... but maybe I'm being uncreative here ...).
Insights appreciated :-)
The only thing you need to do is to drop the jar in WebContent/WEB-INF/lib.
You are developing a Java Web project, so the traditional place to put the required libs (JAR files etc) is under /WEB-INF/lib. And you do it only once.
In Eclipse, when you create Dynamic Web Project the appropriate project structure is generated for you (this is a development structure). In this case you place your JAR files in ProjectName/WebContent/WEB-INF/lib folder. And this folder is *automatically included in the project's build path.
Considering the fact that it is a Java Web project (you said you use servlets) you have to deploy your web app to some Application Server, like GlassFish, JBoss, WebLogic, WebSphere etc, or more simple Web Container like Apache Tomcat. If you do this thru Eclipse, then again your web project is automatically deployed.
NB!
There may be some additional details related to using libraries.
For instance, when it comes to using database drivers (MySql, PostgreSQL, Oracle etc) Tomcat advises the following while configuring JNDI Datasource (quote):
Before you proceed, don't forget to copy the JDBC Driver's jar into
$CATALINA_HOME/lib
In your case (MySQL) see the example here: MySQL DBCP Example
Also see my answer related to Webapp configuration file organization convention.
Hope this will help you.
P.S. Here is a step-by-step example: How do I access MySQL from a web application?

Deploy GWT to Tomcat (servlet not running)

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.

Editing a .jsp file from an App Engine project in Eclipse

I am currently creating my first project using Google App Engine in Eclipse. For my main page it seems I can create either:
a servlet (class that extends HttpServlet)
or I can create a jsp file.
Is there a way in Eclipse to make it aware of the java code in a jsp file and to use all the IDE goodies such as colored text, inline documentation, auto-complete? And is there a way to auto build and validate the code in a jsp or it can only show the errors on the first load of the web app?
It seems to be a lot easier to develop in a servlet class than in a jsp file. Or did I miss something?
Eclipse tries to validate the markup and autocomplete it in the JSP files if you have the WTP (Web Tools Platform) installed. But even that sometimes doesn't work well because it's difficult to parse HTML containing JSP tags, Javascript, etc.
Regarding the Java code : it's bad practice to have Java code in scriptlets in JSPs. You should only use JSPs for pure presentation logic, and use JSTL and custom tags for that. The Java code should be in a servlet or action invoked before the JSP. Use an MVC framework (Stripes, Struts, Spring MVC, etc.) to separate your Java code from your JSP code. I've used Stripes on app engine with success and pleasure.
To make sure your JSPs are valid, you can be helped by Eclipse, but you should also deploy your webapp (on the local server) and run tests to make sure every JSP compiles and runs correctly. You can automate these tests with HtmlUnit or Selenium.