Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using classes from apache: commons-collections-3.2.1

 
Tim McMurry
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48967
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21122
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tim McMurry
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21122
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim McMurry
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic