*
The moose likes Beginning Java and the fly likes Using classes from apache: commons-collections-3.2.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using classes from apache: commons-collections-3.2.1" Watch "Using classes from apache: commons-collections-3.2.1" New topic
Author

Using classes from apache: commons-collections-3.2.1

Tim McMurry
Greenhorn

Joined: Oct 31, 2009
Posts: 22
Hi,

I have an application that needs the Multimap from org.apache.commons.collections package.

I went to the apache.org site and found a download with commons-collections-3.2.1

In the README it says it uses Ant as the build tool and there is no build.xml file. Does this mean I have to create the build.xml file myself ?

All i want to do is get the .class files put them in an appropriate folder-structure as usual for java packages and then add the containing folder to my classpath.

Would it be crazy to get the .java files and compile from source and create the appropriate folder structure and adding to the classpath ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
Welcome to JavaRanch

Depends how many .java files you have. If you have a manageable number try putting your org folder cataining apache containing commons containing collections inside your folder structure in the appropriate location. You can do that by putting the jar file in your folder structure and unzipping it. I can't remember exactly where you put it, so try moving the org folder with drag-and-drop in your directory explorer until it works.
Tim McMurry
Greenhorn

Joined: Oct 31, 2009
Posts: 22
Thank you for the welcome and the assistance .

Oh my, quite emberassing I had tried to "unpack" the jar-file by issuing "java -jar target.jar" which of course gave a no-menifest message :-)
Unzipping it takes care of everything as the appropriate folder-tree is already created. I think I will give myself a 2-week ban from posting questions about Java for this one !
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Tim McMurry wrote:Oh my, quite emberassing I had tried to "unpack" the jar-file by issuing "java -jar target.jar" which of course gave a no-menifest message :-)
Unzipping it takes care of everything as the appropriate folder-tree is already created. I think I will give myself a 2-week ban from posting questions about Java for this one !


You can "unpack" the jar file with the jar command -- "jar xvf target.jar".... but.... why are you doing this? what's wrong with just putting the whole jar file into the classpath. I don't believe these packages were meant to be used in pieces like this.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Tim McMurry
Greenhorn

Joined: Oct 31, 2009
Posts: 22
Hi again,

I thought that if I only include the .jar-file in my classpath and dont actually have .class-files unpacked in the appropriate structure then I wouldnt be able
use the classes through import statements in my code ?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Tim McMurry wrote:I thought that if I only include the .jar-file in my classpath and dont actually have .class-files unpacked in the appropriate structure then I wouldnt be able
use the classes through import statements in my code ?


The Java compiler can find class files located inside Jar files. If the jar file is in the classpath, the compiler will search the jar file during compilation. This is also true of the JVM during runtime.

Henry
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14117
    
  16

You normally don't need to unpack JAR files to use them. Just put the JAR file in the classpath, and Java will be able to use the classes inside the JAR. You don't need to unpack the JAR to be able to import the classes in your source code.

You also don't need to get the source code and compile it yourself if you just want to use the classes.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Tim McMurry
Greenhorn

Joined: Oct 31, 2009
Posts: 22
Thanks for the explanations. Ill go read up on the JAR file format :-)

I had tried adding the JAR file to my classpath, but the compiler complained about it not finding the package, thats why I assumed the actual class -files needed to be there. So I must have made a mistake when setting the classpath firstly trying to use the jar.

Things work now. Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using classes from apache: commons-collections-3.2.1