Spring Hello World setup and code in eclipse - java

I have setup Spring / WTP in eclipse as well as successfully started a Tomcat 6 server within eclipse. I'm at the point where I can create a new Spring project and add source files as necessary.
Could somebody please describe (or point me to) how I can setup of some sort of 'Hello World' test and how to run it? I have experience developing in Java SE but am trying to learn Java EE / Spring.

Start with "Spring MVC Step by Step".

I know this does not answer your question directly, but you may want to consider generating a base project using Maven and then generating an Eclipse project from that.
If you decide to go down the Maven path, the process would be:
mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-spring-archetype -DarchetypeVersion=2.1.0-M1 -DgroupId=com.mycompany -DartifactId=myproject
Details: AppFuse
Once you run the above command, it will set up a complete maven project for you with a Spring MVC project stubbed out.
The next step is to simply run: mvn eclipse:eclipse to generate the project.
Details: Maven Eclipse Plugin
Once you get the code generated and the Eclipse project set up, you can read on the AppFuse Quickstart page how to run the application locally, how to debug it, and go from there.

If you're looking at using Spring in a Web-app, then perhaps this previous answer I wrote might help?

For building Spring apps, SpringSource provides a build of Eclipse 3.5 called SpringSource Tool Suite. It includes a bunch of plugins that you can download independently, but this comes with them pre-integrated. It also includes a lot of guides, documentation, wizards, and so on, which might be good to get you started.

You may find interesting the Spring Roo project which creates a Spring MVC based project directly on the IDE or via the command line.
You might want to see the ten minute video to see how it can get you up and running in no time and it also includes other features which can be not that easy to set up like security and internationalization.

Related

Run Spring boot project from Maven or IDE

I've created Spring Boot based on Maven project as described in one of the official guides. I use IntelliJ.
Now I can run project in one of two ways:
Click on green arrow next to main method
Type mvn spring-boot:run in the command line
What's the difference between these two? Which one should I prefer and why? What does IntelliJ use internally to build the project?
The difference is that in case 1) IntelliJ starts the JVM and runs your app and in case 2) Maven does the same.
In development I would recommend to run the Spring Boot application via IntelliJ instead of Maven. If you run it with Maven, you bypass IntelliJ in a way so it will be less aware of what's going on and therefore less able to leverage it's assistance features. I'm not sure if the debugger will even work, if you start the app with mvn spring-boot:run.
IntelliJ internally uses the JDK that you configured for your project to compile your Java code and if it's a Maven project it also uses Maven to assemble the classes into an app. That last part of your question is extremely broad if one would attempt to answer it in detail. But in practice, when developing a Spring Boot app, you rarely need to worry about it anyway, to be honest.

STS, running any of the Guide projects

I install Spring Toolsuite.
I go to New -> Import Getting Started project.
I choose the 'Building a RESTful Web Service' one. Download only the 'complete' project, select maven and not to open the site.
Now what on earth to I have to do to launch it? Right-click on the project, run as, run on server, shows 'The selection cannot be run on any server'.
I have gone through loads of posts trying to find out what else I can do, done maven clean, maven install, changed the JRE Environment, nothing works.
Running a maven clean or maven install will only update the dependencies of the project (for instance, bring in Spring and its child dependencies, loggers, etc. specified in the pom.xml file).
To run the project right click on the class with the #SpringBootApplication
annotation (it will likely be the one with a main method in it, that's the one you want!). Then select 'Run as->Java Application'.
First a disclaimer. This answer applies to most of the guides. But there may be some to which it doesn't apply, because there's such a diversity of guides available.
Assuming you are trying a 'typical' guide which does something in the context of a web-app... then read on.
The reason that you can not run a guide with "Run On Server" is because of spring-boot adheres to the slogan of "Make Jar not War". The guide sample code are not things you deploy on a server (i.e war) but are standalone Java apps (i.e. jar) which contain their own embedded servlet container (if they need one). That means running them is really quite simple. Just find the 'main' method/class in the guide and use Eclipse "Run As >> Java Application".
There's also a convenient alias in STS called "Run As >> Spring Boot App" which does pretty much the same thing but gives you a few extra bells and whistles in the launch configuration editor.
Also... you don't really have to go look for the main method yourself because the "Run As >> Spring Boot App" knows how to find it in most cases. So clicking project and "Run As >> Spring Boot App" should do the trick.

GWT: eclipse debugging

I'm trying to migrate a netbeans/ant gwt project to an eclipse/maven gwt project.
For that I used the archetype gwt-maven-archetypes, to create a maven project, and after that I copied the sources.
I had succesfully been able to run codeserver and the application itself, using maven comands, as suggested by the archetype author. I even can debug on chrome dev console.
The problem, is that I want to debug from eclipse, and it seems eclipse gwt plugin, doesn't support the current structure.
Any ideas?
Thanks
I ended up, giving up this archetype, and I'm using now simple webapp maven archetype. I figured it out, but still a little tricky on my project.
So, as #ElHoss, has suggested I'm using SDBG. Besides that, I'm not using jetty, but my own tomcat installation, so I've followed this video instructions, together with the SDBG page video's instruction.
At the end, I have 3 Running Configuration items:
The one that starts Tomcat;
The one that starts codeserver;
Chrome Launcher, as instructed on SDBG page.
If you need plus information, please comment.
Thanks.

cannot create maven project in STS

I'm new to Java EE development and I heard that If I have to learn the Java EE then the Spring MVC is best choice to learn and get Command of.
After downloading STS 3.6 bundle I'm having some troubles/issues in creating Maven Project. My STEPS are
1- Create new project
2- Error Dialog
It appears that you either don't have Maven installed, or your IDE is not aware of the installation. For the former problem, have a look here. For the latter problem, view this page for IDE you are using:
Eclipse
I would also like to recommend to get started with Spring using the Spring Tool Suite by using Spring Boot and the guides at http://spring.io/guides. You can import those guides directly into STS and start from there.
I also face with this thing too, but I found a solution that just update Maven project by right click on project -> Maven-> Update Project... or (Alt+F5) then check on force to update as image below :
It works perfect for me.
NOTE** internet connection is required
I have created project using Spring Tool Suite IDE, with below navigation.
New -> Spring Starter Project
But outcome was always simple maven M2 project with error symbol.
After project build completion I have updated maven project with option "Force Update of Snapshots/Release".
It turned my project M2 project into M2S Project
Thanks

Java EE auto completion

Where can I find the jar file or the source code of JEE6? Or is there another way how you can get autocompletion for this in Netbeans/Eclipse?
And I have just installed glassfish so that i can use JAX-RS but i do not understand how it works. Why does the javacompiler find these classes but netbeans does not? I building with maven2 but have not set any paths or so.
And why am I not able to install JEE6 without glassfish? I just do not need an application server for a REST service with Jersey.
Best regards,
CQQL
Question #1:
See this example project.
The example project is built with maven, which may answer your question about auto-complete. Netbeans 6.8+ (approx) has built-in maven support. After the first build of the example project, I think you'll see that auto-complete works better for any dependencies (i.e. jersey) inside the pom.xml. In my Netbeans, auto-complete works, but the javadocs are not there, which may mean that Jersey wasn't bundled with them.
Question #2: Your maven on the command line and the one inside Netbeans are different copies. You can make Netbeans use a specific copy of maven in Tools/Options/Misc/Maven/External Maven Home. This may clear up some confusion.
Question #3: Jersey can run in Tomcat or Jetty if you find Glassfish to be too much app server for your needs.

Categories

Resources