File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Importing packages from jar files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Importing packages from jar files" Watch "Importing packages from jar files" New topic
Author

Importing packages from jar files

Michael Boehm
Ranch Hand

Joined: Jun 02, 2010
Posts: 51
Hello I am on linux and trying to compile some code which imports packages which are available in a jar file.
Using the jar tool I have checked the the appropriate class files are actually in the jar and that the folder structure
corresponds correctly to the the structure implied by the import statement.

I have placed the jar file in /home/me/.jars and added /home/me/.jars/externalTool.jar to the class path in my .bashrc.
(Yes, I did rememeber to still have "." included in the class path)
The javac compiler can still not find the packages imported in the java file. I have tried compiling usisng the -cp option specifying
the path to jar before the .java file, but still no luck.

Feel like I am overlooking something simple.
Anton Shaykin
Ranch Hand

Joined: Dec 13, 2009
Posts: 57

I have tried compiling usisng the -cp option specifying the path to jar before the .java file, but still no luck.

Could you post the exact command that you're executing? Because with -cp switch it works almost always without problems.
Michael Boehm
Ranch Hand

Joined: Jun 02, 2010
Posts: 51
I have tool.jar in /home/me/.jars and App.java in /home/me/code

This produces a compile error from the first line having an import statement referring to a in package that is inside the tool.jar file:
Anton Shaykin
Ranch Hand

Joined: Dec 13, 2009
Posts: 57

From what you posted, everything seems correct. You can try to rename .jars to simply "jars". Maybe that's causing the trouble. Also, double-check that in your tool.jar there is a directory structure like this: /pckg/name/ClassToImport.class
Michael Boehm
Ranch Hand

Joined: Jun 02, 2010
Posts: 51
Thanks worked it out. After first checking the directory structure inside the jar, I had downloaded a newer version of the tool.jar and the structure now had an extra parent folder.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Importing packages from jar files