user1433927
user1433927

Reputation: 171

Sharing a Spring MVC project

I need to do a Java web project. I'm going to be using Eclipse.

I thought of using Spring MVC. As far as I can tell - it's gonna require me to add some "extra" stuff to a "clean" Java web project. I don't mind that - the thing is - one of the project requirements is - that I'll be able to send the project to someone else - that doesn't have any extra installation and/or configuration - and he will be able to compile the project.

Is that possible with Spring MVC? Does the Spring MVC framework is just a "JAR" like addition to the project - therefore - the project can be shared without a problem?

Thanks.

Upvotes: 1

Views: 989

Answers (3)

informatik01
informatik01

Reputation: 16396

Short answer: yes, you are right.


To use Spring in your Java web project, you generally need to add two things:

  • the appropriate Spring configuration file(s) (XML)
  • the appropriate Spring JAR files (traditionally placed in /WEB-INF/lib, the same as other JARs). By the way, it is NOT a single JAR file, but several JAR files.

That is all there is to it.

Upvotes: 1

namero999
namero999

Reputation: 3012

Spring has nothing to do with "sharing the project".

To "share" the project with someone else, you put it on the SCM of your choice and your collaborators will be able to get the code and work on it.

Building the project is a different aspect. To correctly compile the project you have to make sure that all the classes and/or jars are visible in the classpath (and runtime if you want to execute the code). Spring is made of a bunch of jars that, depending on which classes of the framework you use, must be in the classpath (eg. putting them in the /WEB-INF/lib directory). You may version them as well, or just version the configuration (I'm thinking about Maven for example, that will take care of resolving the dependencies).

Another piece of the puzzle is making all of this work in your IDE. This is a matter of taste. I prefer not to version ide-specific files (in the case of Eclipse, .settings and .project files/folders). You can do that, making sure you do not use absolute path anywhere, and technically you will be able to import the project without problems from another machine.

Upvotes: 1

Hauke Ingmar Schmidt
Hauke Ingmar Schmidt

Reputation: 11607

Yes.

If the other person has nothing extra installed and configured, namely no build tool, you need to put every needed Spring and other Jar into a folder, typically called "lib" and tell him to add them into his compile process. If he just uses the JDK he will get an enormous command line. It is much better to use a build tool like Maven or Ant+Ivy for building and dependency resolution. But that would be an "extra installation" per your question.

If he has Eclipse installed like you have and you use Eclipse internal for building:

  • Put the JARs in a lib folder
  • Configure the build path
  • Make a local test build
  • Export the project as zip (File menu > Export) " The other person needs to import the project into his workspace

The exported project should not have any absolute paths as long as you didn't set some deliberately in the build path.

This works but is not exactly best practice. Installing a build tool like Maven is absolutely worth the time and should be preferred under any circumstances. It will save you a lot of time and nerves.

Upvotes: 0

Related Questions