spring MVC sample web app - java

I'm looking for an example Spring MVC 2.5 web app that I can easily:
Setup as a project in Eclipse
Deploy to a local app server (using Ant/Maven)
There are a couple of example applications included with the Spring distribution ('petclinic' and 'jpetstore'), but they don't provide any Eclipse project files (or a way to generate them). They also seem a bit complicated for my needs, e.g. require a local database to be setup.

The easiest way to get up and running with a Spring MVC project is to use SpringSource Tool Suite, which is another free IDE based on Eclipse.
The integration between the IDE and Spring/Maven is tight, and it comes with an application server already setup for you to deploy your web app.
Follow these steps to get a working Spring MVC web app.
To setup a new project in STS: Click File -> New -> Spring Template Project -> Spring MVC Project
To pull in dependencies and compile your project: Right click your new project -> Run As -> Maven install
To run your project inside an application server: Right click your new project -> Run As -> Run on Server -> SpringSource tc Server
If it works, you'll see a web page saying "Congratulations! You're running Spring!"

While not specifically an app you can download, Developing a Spring Framework MVC application step-by-step covers creating a spring application in Eclipse with an ant build script, complete with unit tests.
This meets the following requirements:
Spring MVC 2.5
Project in Eclipse
Deploy to a local app server using Ant
Uses HSQL (no need to install a local DB)

There's a Maven archetype (template project structure) for Spring MVC here:
http://docs.codehaus.org/display/MAVENUSER/Archetypes+List
That's a good starting place for this kind of investigation. To create an archetype using Maven, first install Maven:
http://maven.apache.org/plugins/maven-install-plugin/
and then create a project using the archetype:
http://maven.apache.org/guides/introduction/introduction-to-archetypes.html
You can also use the m2eclipse plugin for Eclipse to simplify this and it takes you through the stages of the project using a wizard. Just right click -> New Project -> Other, Maven and select the archetype. Hope that helps.

Just spotted http://blog.springsource.com/2010/07/22/spring-mvc-3-showcase/ which could be interessting for you.

To generate Eclipse project files:
Use mvn eclipse:eclipse before importing the project into your workspace. This will create all required configuration files and hook your project up with all the required dependencies.
The mvc-basic and mvc-ajax sample projects in spring-samples (SVN URL: https://src.springframework.org/svn/spring-samples) are simple projects that do not need any local database support.

Use AppFuse

I got it working just as Drew described, but there is a trap for new users (meaning fresh install, no familiarity with Maven or m2eclipse). You'll get this error:
[ERROR] Error executing Maven.
[ERROR] The specified user settings file does not exist: /home/user/.m2/settings.xml
And the work around is to just make an almost empty settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
</settings>
(I later found this bug report.)
After that, I was in business. I was even able to export as a WAR file and deploy onto my installation of WebSphere Community Edition. Thank you, Drew!
A little less earlier, I wrote:
Hmph. Never mind. I gave up, shut down my machine, and when I came back, everything worked (except for a minor Maven issue I'm working on). Chalk it up to a bug.
Earlier, I wrote:
I was very excited to hear about STS, so I downloaded and installed it. It went perfectly. This is a new machine, so I have the latest of everything - java 1.6, eclipse 3.5.1, etc.
On step 2 of the above instructions, I get this error:
"The specified JRE installation does not exist"
I've set paths everywhere I can find, so I'm not sure which JRE it's complaining about. Help?

You could also use Spring Roo to do this. http://www.springsource.org/roo

You can use below link to download hello world spring mvc project
Spring MVC hello world example

Related

Creating a Spring MVC project using Intellij 2020

i'm trying to create a spring MVC project using intellij Ultimate 2020 but i don't have it available in my menu :
Is there a way to get the Spring option ? i already checked that the Spring plugins are all enabled .
The Spring Initializr can generate a Spring Boot project structure for you. It will give you a basic project structure and either a Maven or a Gradle build specification to build your code with.
You can use Spring Initializer to generate a spring project. It will provide you with all the dependencies required for SpringMVC project
Go to https://start.spring.io/.
Just specify the dependencies.
Download the generated project.
Open the project with IntelliJ.
Resolve the dependencies by specifying the unmet ones in pom.xml if found any.
Good to go!
I don't know are u new in spring, but if u are, here some advice to start in idea.
First of all, visit https://start.spring.io/
First 5 steps of instruction matches with numbers on this picture
https://i.stack.imgur.com/T6NW1.png
Choose dependencies u need, for example start with spring web(mvc)
Choose your language, u need java
Choose which dependency manager u will use, for example maven
Choose spring boot version, for example 2.3.3
Give a proper name to your future project, it's not necessary
Press GENERATE
Unzip downloaded file
IntelliJ Idea -> Open or Import - > select unziped folder

How to identify and build a JBoss java application from 2007?

I have a java application written in 2007-2010 that I need to build and run.
I am unable to open it in netbeans or eclipse.
Some identifying features of the source code:
It has a maven.xml and project.xml file (not pom.xml) in root
It has a jndi.properties, launch.properties and project.properties file in root
it has a .project and .jupiter file in the root directory
It is currently running in prod in a Jboss container
Are these indicators of some application framework from the late 2000s that someone can identify?
I am hoping to be able to open it in an IDE and build it.
It's a Maven 1 architecture.
[project.xml] Project Object Model (POM) definition
[maven.xml] Custom build scripts
[project.properties] general build settings
[build.properties] local build settings
Here you can see some more information and how to migrate it to Maven 2: Maven 1 to Maven 2
And here is some information on Maven's website about Maven 1: Quick start to Maven 1
Notice that it isn't supported anymore.
.project possibly indicates it's been built with Eclipse
.jupiter probably indicates that they used the code reviewer plugin Jupiter
All that said, I believe you could import it as an Eclipse project. Just pay attention on which Java version to use and which Eclipse and Maven as well.
I'd strongly recommend you to migrate to a newer version of Maven, but I also know how legacy software can be impacted by such migration, so it's up to you which way to go through.

How to create a new Java + Maven + Spring + Hibernate/JPA project from scratch with Eclipse?

I'm using Eclipse (Neon.1) and Java 8. I know my way around Java and in the past I created Java projects by File > New > Java Project (for a POJO project). Or File > New > Dynamic Web Project (for a WAR web app project).
But today I want a project that uses Maven, Spring MVC, Spring ORM, JPA/Hibernate, and probably a couple of other things.
I'm confused about how to build this project in Eclipse.
Do I do File > New > Java Project ... and tweak it and add stuff to it?
Or do I File > New > Maven Project ... and tweak it and add stuff to it?
I've also heard that Spring Boot is a good way to get started with this kind of thing.
Any pointers or suggestions would be greatly appreciated!
I suggest you use spring boot. It's very easy to develop Spring Based applications with Java. It avoids writing lots of boilerplate code, Annotations and XML Configuration.
here's the link on how to use spring boot with maven.
https://spring.io/guides/gs/spring-boot/
The easiest way is probably using the Spring Initializr; That web interface is also provided in IDEs (cannot speak to how it's implemented in Eclipse though).
What you'll get is pom.xml file that you then can use to create a new maven project by pom file. It will load all the dependencies you choose and makes configuration simple.
I usually create a Maven Project and add any Stuff like Spring MVC, Hibernate to it. And Spring boot is highly recommended, no need to look at xml files anymore. Here is a archetype that may useful:
https://github.com/superalsrk/cn.stackbox.archetypes
Let me explan one by one.
java - programming language
Maven - Build tool and dependencies manager like npm or bower
Spring - A java framework witten top of java also contains java codes
Hibernate/JPA - is another framework in java helps to handle data access and store data in database
In eclipse You need to create a maven project which will creates the project structure. it will create a pom.xml file and then you need to add spring and jpa related dependencies.
Then maven will manage those dependencies and now you can write your programming logic to manage your data and UI.
You can refer sample project in git
You can install the m2e plugins (usually come along with eclipse already). And configure it according to your local maven installation.
And then create a web application skeleton based on the maven project templates/archetypes provided by the m2e plugin like the normal new project process.
And then you can edit the pom.xml file (Project Object Model, which is the maven project file) to include the packages you need, such as Spring, etc.
I don't have my dev machine at hand. So the above descriptions may be vague without proper screenshots. So please follow the below 2 quick guides. Hope they help.
https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
https://web.liferay.com/community/wiki/-/wiki/Main/m2e-liferay+Quick+Start+Tutorial
And these:
Using Maven within the Eclipse IDE - Tutorial
Maven + Spring hello world example
Some examples related for requested technology stack:
Jersey + Spring example: https://www.mkyong.com/webservices/jax-rs/jersey-spring-integration-example/
Jersey + Hibernate + Spring example: http://www.benchresources.net/jersey-2-x-web-service-integrating-with-spring-and-hibernate-orm-framework-using-annotation/
As chaixxiv mentioned previously https://stackoverflow.com/a/40966438/5962766, to avoid boilerplate code you can use Spring Boot. More samples:
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/

tomcat-maven-plugin in GWT project. What is the difference between: org.codehaus.mojo and org.apache.tomcat.maven plugin

I am trying to set up tomcat server for gwt application. I would like to configure server to update my server side code changes immediately.
While looking for some helpful examples over the web, I found that there are to plugins for maven.
One from:
org.codehaus.mojo (which also provide plugin for gwt in maven echosystem).
And second from: org.apache.tomcat.maven.
What is the difference between them? Which one should I choose for:
GWT 2.7 Maven Project. I will develope app in Eclipse IDE. So I would like to have good integration with it to. F.e.: the Eclipse tab/view "Servers".
From https://tomcat.apache.org/maven-plugin-2.2/
This is the new home for the Tomcat Maven Plugin (previously hosted at Codehaus).
The CodeHaus Mojo (now MojoHaus) Tomcat Maven Plugin is obsolete.
I have Maven archetypes that use the Tomcat Maven Plugin to fire up a server for development, with automatic redeployment of the webapp when classes change, at https://github.com/tbroyer/gwt-maven-archetypes
Note that they use a different Maven Plugin for GWT than the one from MojoHaus (ex-CodeHaus Mojo), one that works much better with multi-module builds.
I've never used Eclipse WTP though (tried it and had too much trouble, probably because I didn't really know how to use it properly though) so I can't really comment, but I see no reason why it wouldn't work.

How to run wicket examples?

I am new to web prog. and wicket, so i went to below site to run example source codes to play with applications.
http://www.wicket-library.com/wicket-examples/index.html
Simply i create a "dynamic web project" and try to copy source codes to project.
All example's application classes are that type,
public class ...(ex.name).Application extends WicketExampleApplication
On the internet i found some of those examples with classes WebApplication, and i managed to run those examples, like that
public class ...(ex.name).Application extends WebApplication
So my question are;
1-How can i simply run those examples using dynamic web projects?
2-Copying source codes to my project after that how can i call libraries in my project using maven?
I searched many questions but couldnt find any topic who is trying to run those examples simply in a project.
Thanks.
Soso
instead of doing all the messy work just run mvn using tthis
[http://wicket.apache.org/start/quickstart.html]
now just copy the sources
if you any problem and you want to add wicket to an existing project just copy the web..xml , wicket jars and you would have wicket project (i would recomend wicket from another opm connecting you existing services and this way decouple services from the web container ...)
P. S the WebApplication thing they just inehrited it and called ExampleWebApplication
The best you can do is to use maven integration
Install Eclipse (that support Java EE)
Add all required maven related plugins
Version Control: Use Subclipse 1.8.x, see: http://subclipse.tigris.org/update_1.8.x
Maven Integration: m2e , is included in Eclipse Classic. Use
Help->Install New Software, select "--All available sites--" and
choose Collaboration -> m2e - Maven Integration for Eclipse
Subclipse/Maven Integration: Update site: http://subclipse.tigris.org/m2eclipse/1.0/
Then, just checkout the maven examples you got on the web
Go Eclipse--Window-->Show view-->Other
Type svn and select SVN repositories and open it
Then copy the check out address and add it to the svn repositories View
finaly, right click on the link you have added and check out as maven projects.
If you want to create new Maven projects
Create new maven Projects, new-->project-->Maven project
then in new Maven Project Window, in the Filer Text box, Type wicket and select org.apche.wicket as a groupID
After that, you can have your maven codes working well.
If still you got some debug errors, you can open your pom.xml file and add dependencies such as wicket-core and wicket-extensions

Categories