wood burning stoves 2.0*
The moose likes Spring and the fly likes Can't import Spring classes in SpringSource Tool Suite Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Can Watch "Can New topic
Author

Can't import Spring classes in SpringSource Tool Suite

Debojit Sinha
Ranch Hand

Joined: Mar 13, 2010
Posts: 66

Hi,
I just tried to run a "Spring Project" named Hello World on STS 2.9.1 =, but I'm unable to import ApplicationContext(or any other Spring class) into my project. The libraries just aren't there in my project build path. However, when I start with a "Spring Template Project", the libraries come along just fine, but as Maven dependencies. I tried to configure Maven for the Hello World project I started out with, but couldn't proceed on account of utter ignorance of Maven.

Could anybody please tell me what I'm missing?

Thanks,
Debojit
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1646
    
    7

Well nowadays maven is really an essential thing to have under your belt so I would suggest with starting with their getting started documentation. Really everything you need to know is freely available on their website. They even have a free copy of the Maven 2 Oreilly book available for viewing last I knew.
I would start here for familiarizing yourself with maven.
http://maven.apache.org/users/index.html


Now as for setting up your hello world project when you use the template project it puts all your dependencies and such in the POM file for you. If you are unfamiliar with POM files please see the above link.

In STS go to File -> new -> other -> maven -> maven project and click next

When you get the the archetype selection if you are doing a web app then choose maven-archetype-webapp otherwise for a stand alone application the default quickstart that is highlighted is fine.

STS will create the project structure for you. Next I would suggest (after reading the documentation provided in the above link) comparing the POM file generated when you create a spring template project to that of the empty one generated when you created a new maven project. You can mostly just focus on the items contained in the <dependencies> tags. These are the libraries that will be pulled into your classpath that are needed on your projecct build path. For a hello world application you will probably not need all of them start with the basic ones and add what you need if a class is not found.

This blog post is a little dated but is applicable.
http://blog.springsource.org/2009/12/02/obtaining-spring-3-artifacts-with-maven/


[How To Ask Questions][Read before you PM me]
Debojit Sinha
Ranch Hand

Joined: Mar 13, 2010
Posts: 66

Hi,

Thanks for your reply Bill, it gives me something to start out with in my learning. Just asking, , is there no way to get a Spring Project up-and-running without using any of the templates? Or Maven, for that matter.

Thanks,
Debojit
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1646
    
    7

Well the way I explained above is done without using the template. You can create a maven project without using STS or even the archetypes if you want as well it is just a time saver and makes life easier.

As for not using maven that is possible as well but there is no longer an uber "spring.jar" so you would have to download all the libs and their transitive dependencies and include them on your projects classpath. There are a lot of those but its possible. If you do go this route (I recommend taking the time to learn maven instead) then downloading the jars from a maven repository (they are actually probably already on your computer in your .m2 directory if you ran a template project) is probably the easiest way to get the jars you need.

Thanks,
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can't import Spring classes in SpringSource Tool Suite
 
Similar Threads
Maven Tomcat plugin precompile JSPs problem
How to create first minimal Maven Project?
Wanted: Spring tutorials with Maven (or Ant)
Maven: What's the big deal?
maven SCM project