views:

154

answers:

6

This is in a way a follow-up of a previously unanswered question of mine (link) which excalated over the past weeks, and now it has come to a point where I cant really develop anymore...

So here's the deal; I have more of a mathematics/engineering background than pure CS, so I dont have a lot of experience with proper/large-scale software development, but rather scripting and algorithms. Now that I am working on a large project, on my own, I am confused with some of the aspects of development. One of them being handling libraries/dependencies

I have initially created a folder called lib under my project folder (in Eclipse workspace) and copied my external libraries in there and then added them to the build path. However later on I needed some other stuff like JCommons, JFreeChart, Apache Commons Math etc.. According to instructions these libraries can/should be included as user libraries, allowing the developer to see the documentation and source code from within IDE (such as Eclipse). I have gotten it right so far, I hope...

So where is the problem? Well first off it appeared as the user libraries mentioned above are not included on the SVN copy of the project, meaning that my colleagues who wanted to test-drive my project couldn't do so, by just simply acquiring the project from SVN. Now the second phase of the problem unsurfaced when I changed my workstation at work, I wanted to import my project into Eclipse from my backup, but then everything except those user libraries are there. To make things more complicated, when this software is done, it will be implemented on a server so it would be absolutely best if everything could be packed into one single library or a even better a runnable jar file.

I have been previously advised to take a look at Maven, or Ivy, but my initial understanding after checking them both is that they are used from the beginning and mostly for more complicated projects. Honestly I am completely puzzled as to how I am supposed to manage my dependencies. Any ideas?

(Sorry for keeping it long, but I figured better complete and long then inadequate information)

EDIT: I have managed to sort out the problem; the problem has apparently originated from the simple fact that eclipse doesn't copy all resources to one place, and the installation instructions for some libraries doesn't really warn you about how to manage the libraries in the best way.

Thanks to everyone, who took their time to try and help me. I will in time look more into projects like Maven and Ivy, it's definitely interesting stuff. However for now I just need to get back to the software into running state, been wrestling with new stuff for too long.. :)

+3  A: 

Invest some time to learn how to create a project using Maven. It just does so many things for you that it's amazing.

This cheat sheet may help you in the beginning.

Boris Pavlović
Thanks for the tip but I cant say that the link helps a lot. I am still not sure about what Maven is really about. I mean I already have a project, one that I have invested a lot of time on. I am not sure if I want to start over...
posdef
Don't worry. Redoing a thing doesn't make it harder. Actually it's quite opposite and the second time you're going to do it much, much better. There's nothing to loose, just create a project using maven create artifactory plugin and copy the existing code in the places that maven expects to find.
Boris Pavlović
A: 

You don't have to have a complicated project or a greenfield project to benefit from Maven so I would take the advice you've already been given to try and give it a go.

If you really don't want to, then you should really be checking your libraries into SVN along with your code. If a version of your code relies on a specific library at a certain point in time then there is a contract there and by not including the libraries in SVN you're breaking that contract- something you've already found as you can't recreate your application from scratch elsewhere.

As for packing up in a single JAR- this is possible with Ant, but why would you need to?

MrWiggles
I thought I did check my libraries, as mentioned above most of them are there. I got confused when I realised that some of them were missing. I find it very tedious/unreasonable that eclipse won't copy the external resources into a one folder but instead links them somehow.
posdef
oh and as for the reason for packing up everything to a single JAR; well we are mostly going to make it available for public use and for that reason I would like to keep things simple and clean. The user finds the only java file they want to get, which holds everything, they download and use the software without having the need to set up anything.
posdef
+2  A: 

Okay I think this can be solved..

In Eclipse in the java build path screen there is also an import jar libraries choice that allows you to choose the project lib folder..in fact there is a choice labeled folder I think..

The other thing since it will be deployed to a server you will have to have every jar in the lib folder.

There is an ant technique where you check for a class and a property in the jar to verify its the correct jar to import from the lib folder before proceeding with that sequence of the build.. do a Google search and you will find the posts about it..

Fred Grott
A: 

At our company we have a separate SVN Repository for third party libraries, and we have a company rule that on every development workstation this repository is checked out to C:\dev. So every one, has the libraries in the right place and the projects works fine.

huo73
so you are suggesting that I should have a separate SVN rep to store the libraries, and somehow link the project to the lib rep?
posdef
Basically, yes.
huo73
+1  A: 

The three options are:

  • Maven (refcard) - a very powerful tool, but at the same time very easy to use. I use it in all my projects, no matter how small they are. It is dependency management + build tool in one
  • Ivy - much like maven, but it is only a dependency management tool. You'd have to do your builds with ant
  • committing jars & eclipse project files - this is not portable between IDEs, but actually isn't that horrible and is used in many projects

Update: a few words explaining maven ideology:

  • convention over configuration - you structure your project in a predefined way. That doesn't have to do with dependency management, so just mentioning it.
  • repositories - that's where the jar files actually reside. They don't reside in your SVN, because they have a separate mechanism of versioning and because they take up unnecessary space.
  • IDEs integrate with maven. For example m2eclipse gets the maven dependencies and appends them to your eclipse build path, thus making the usage transparent
  • dependency resolution - in pom.xml you define multiple <dependency> tags, with name and version, and maven fetches all the required jars from the remote repositories. It also fetches jars on which your dependencies depend (transitive dependencies). Thus you don't end up having NoClassDefFoundException.

To me this is extremely straightforward: you define what you need, and maven decides how to fetch it, and how to add it to your classpath.

Bozho
Maven being "very easy to use" is debatable. You need the right mindset.
Thorbjørn Ravn Andersen
well, yes, you have to 'think the maven way', but it is not far from 'best practices', so .. :)
Bozho
I am gonna have to agree with Torbjörn, what is easy to use is highly subjective with regards to one's background, experience and competencies. I have been trying to make sense out of the refcard, and the cheatsheet given above as well as the documentation on the homepage, but can't say I have done much progress, even though the language used is plain english... What I think I need is to actively and intuitively see which libraries are needed, and where they are. It would be cool to keep them in one single place automatically as well, if possible..
posdef
maven has the pom.file, where you have a list of dependencies. that's it. I don't see anything hard with that. When I started using it 2 years ago it came like a completely logical solution.
Bozho
I have been reading maven and the POM model, but I only end up more confused, do I use Maven instead of Eclipse? Why do I need repositories? Pieces of the puzzle just don't fit together, at least not in my mind; there's Eclipse (and my project), there is SVN trac, there is Maven (with it's rep.s) and the libraries I need to use... I am sorry if I sound like a scared 10 year old, but really none of this stuff is basic or intuitive..
posdef
@posdef - see updated
Bozho
+1 for a well needed and well written explanation. Thank you! I'll try to dig in a bit deeper with maven. Just one small thing though: so I need to create and define a maven project, how does that relate to my existing eclipse project?
posdef
You don't need a new project. You just add the pom.xml (at the root), install the eclipse plugin m2eclipse, and right-click the project choosing "Maven > Enable dependency management". You will just have to put your java sources in src/main/java :)
Bozho
+6  A: 

At the risk of committing an act of heresy, I'd say Maven and wot-not are overkill here. You need your dependencies in your SVN project, simple as that. You've added your lib folder to your build path in Eclipse, and that's fine. But unless you specifically add the contents of the lib folder to your project (as Fred describes), those items won't be eligible for committing to SVN -- they will simply be referenced in your set-up's classpath. That's good for you, no good for anyone looking to check out your project (as you have found).

I appreciate that we could have endless discussions about best practice, the validity of committing third party libraries to version control, and so on and so forth... but I think most people have work to do ;-)

Ben Poole
so in short, I redo ( as in re-link) the problem libraries and make sure that theyare synced to the svn rep, thats it?
posdef
Yes. You can also add the documentation and source (in jar form) to the project in SVN, if you'll find that helpful. By right-clicking on the Referenced Libraries entry for the library, you should get the opportunity to define where the javadoc and/or source libraries are located.
Bill Michell
I disagree. Maven is fit for a project of any size. You just use the simplest features - dependency management and `mvn package`. Proven by experience - takes 2 minutes to setup.
Bozho
maven seems to give me more and more challenges to tackle, such as finding and adding libraries that are not included in the search engine. I am standing behind my original statement; maven is not well documented. As for just adding the libraries to the SVN, I can't seem to use "User Libraries" if they are in my lib folder; I get resource not found error which is really odd. I followed the instructions precisely: http://sourceforge.net/projects/jfreechart/files/2.%20Documentation/1.0.13/jfreechart-1.0.13-install.pdf/download
posdef
If memory serves (don't have IDE open at the moment), I simply drag external jar files into my lib folder in Eclipse, and then configure the build path (“Add JAR” button >> then open project in resulting dialogbox) to actually pick them up.
Ben Poole