Home > Things to know about Spring Download, Installation & Configuration > Things to know about Spring Download, Installation & Configuration

Things to know about Spring Download, Installation & Configuration

 

 

Things to know about download/installation/configuration of Spring Framework:

 

The Spring Framework and container is packaged in several JAR files. Spring is a library(.jar files) of classes that will be packaged with and used by your Spring-enabled applications. Installing Spring involves adding one or more JAR files to your application’s classpath. It does not have an executable runtime. Therefore, Spring is more similar to a library like Jakarta Commons than an application server like JBoss.

How you make Spring available to your application’s classpath will vary depending on how you build and run your application. You may choose to add the Spring JAR files to your system’s classpath or to a project classpath in your favorite IDE (as we will see in the post on configuring Spring Framework with Eclipse). If you’re building your application using Ant or Maven, be certain to include Spring in your build’s dependencies so that it will be included in the project’s target deployment.

 

Downloading Spring:

There’s plenty of additional materials in Spring’s full distribution, including Spring’s API documentation, examples, and the full source code for the Spring Framework. Therefore, the first thing you’ll want to do is to download the full Spring distribution. Refer to Spring Framework Installation & Configuration post. When downloading Spring, you will have 2 main choices: you can either download a Spring distribution that comes with its own dependencies or you can download a distribution that contains only the Spring JAR files. Even though the former is a much larger download, its better to download the one that comes with dependencies so that you won’t have to hunt down other JAR files that your application needs.

 

Exploring the Spring distribution:

Once you’ve downloaded the distribution, unzip it to a directory on your local machine. The Spring distribution is organized within the directory structure described in the table below. Several of these directories contain the Spring source code. The aspectj/,mock/, src/, and tiger/ directories contain the source code that makes up the Spring Framework itself. Meanwhile, the test/ directory contains the unit tests used to test Spring Framework. Although it’s not essential to using Spring, you may want to venture around in these directories to see how Spring does its stuff.

 

 

The Spring developers are extremely talented coders and there will be probably a little something to learn by reviewing their code. The docs/ directory contains two important pieces of documentation. The reference document is an overview of the entire Spring Framework. Also, the JavaDocs for the entire Spring Framework can be found under docs/—you’ll probably want to add this as a bookmark in your web browser, because you’ll refer to it often. The samples/ directory contains a handful of sample Spring applications. Of particular note are the petclinic and jpetstore examples. Both of these applications highlight many important elements of the Spring framework.

 

Building your classpath:

The most important directory in the Spring distribution is probably the dist/ directory. That’s because this is the directory containing the JAR files that you’ll use to build Spring-based applications. Using Spring in your application involves choosing one or more JAR files from this directory and making them available in your application’s classpath. The JAR files and their purposes are described in
the table below:

 

 

spring-webmvc.jar | dist/modules/ | Spring MVC.

 

Although the list of 24 JAR files may seem a bit daunting, sorting them out isn’t all that difficult. The JAR files in the dist/modules/ directory allow you to choose which parts of Spring are needed for your application. To make things simple, however, you may want to take the lazy way out and simply add spring.jar (from the dist/ directory) to your application’s classpath. The spring.jar file is a convenient, single-JAR equivalent to all of the JARs in the dist/modules/ directory.

You should know that not all Spring-related JAR files are available in the main Spring distribution. Acegi Security and Spring-WS, for example, are subprojects of Spring and have their own distributions available from their own websites. If dist/ is the most important directory then lib/ comes in a close second. You will likely need to add other JAR files to your classpath to enable certain Spring features. For example, if you intend to use Spring’s support for AspectJ in your application, you’ll need to add aspectjrt.jar and aspectjweaver.jar to the classpath.

Likewise, Spring’s Hibernate modules depend on an appropriate version of Hibernate being available in the classpath. If you downloaded the “with dependencies” distribution of Spring, you’ll be able to find most dependencies you need in the lib/ directory. Although many of the JAR files under the lib/ directory are optional, one is required. Spring relies on Jakarta Commons Logging to log informational and error messages. Therefore, commons-logging.jar (from lib/jakarta-commons) must always be in the classpath of any Spring-enabled application.

Once you’ve decided which JAR files your application needs, the next step is to add them to your classpath. The naive way of handling this would be to add them to your CLASSPATH system variable:
set CLASSPATH=%CLASSPATH%;{SPRING_HOME}/dist/spring.jar
set CLASSPATH=%CLASSPATH%;{SPRING_HOME}/lib/jakarta-commons/commons-logging.jar

This may work for quick-and-dirty experimentation. But you’re probably going to use Spring to develop full-blown applications more often than one-off trials. You’re likely going to let a build system like Maven or Ant construct your application distribution. In the coming posts in Spring Framework Installation & Configuration category, we will see how to add Spring to your Maven and Ant builds.

 

 

Note:

  

Source: Excerpt from Manning Spring in Action, 2nd Edition.

 

 

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: