• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Importing packages from jar files

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 65
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic