Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jar files and import statement question

 
Josefina Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my code I use a line like the following where I import a class file:

[code]
import com.mypackage.test.api.abc.MyClassName;
[/code]


this was in a jar file included in my build at compile time.

first.jar - com - mypackage - test - api - abc - MyClassName


this jar file has changed and the now I have to import my class from a jar file within this jar file.

first.jar - com - mypackage - test - api - abc -
- second.jar - com - mypackage - test - api - abc - MyClassName


how would one write the import statement in this case?


 
Joe Harry
Ranch Hand
Posts: 10079
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did it give you an error when you tried to use the same import statement?
 
Josefina Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it only gave the typical unable to resolve class error.

I was think that I must be forgetting how to load a class in this case.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josefina Smith wrote:how would one write the import statement in this case?

The import statement won't change. It's your classpath that needs to change - you need to include second.jar in it.
 
Paul Clapham
Sheriff
Pie
Posts: 20715
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josefina Smith wrote:this jar file has changed and the now I have to import my class from a jar file within this jar file.


Jar files within jar files can't be used as part of the classpath. At least, not without a lot of work -- I vaguely recall reading about a product which allowed you to use a specialized classloader to do that, but I really wouldn't recommend going down that road unless you're being forced to use a jar within a jar by some inflexible manager out of a Dilbert comic. It's better to just not do that.
 
Josefina Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips guys! What I ended up doing is pulling my inner jar out next to my outer jar and then my compiler could easily read it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic