• 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

Iterating all classes in package - of different Java project

 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
In Eclipse I have two projects [mainDev] and [Junit], the projects are related through the Java Build path -> Projects tab.
I would like to iterate all classes of package x in project "[mainDev]", Using junit test in [Junit] project.
I found piece if code here: http://forums.sun.com/thread.jspa?threadID=341935 that iterate on all classes (compleate code below)
But getContextClassLoader().getResource("/com/mycomp"); always returns null.
What am I doing wrong?



 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remove the leading "/".

And refactor; this is kind of hard to read... I ended up with something like this:
 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you David , Indeed the '/' at the end made getResource work, But running this code won’t return classes from [mainDev] project
I was able to read classes in [JUnit] project under the same package name 'com.mycomp' but I was unable to get to classes in [mainDev] project



I wrote this method to walk the package tree:
>
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are they on the classpath? I'm able to dump everything on the classpath without issue.
 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Are they on the classpath? I'm able to dump everything on the classpath without issue.


Ok I set the class path in the "Debug configuration" -> "Classpath" tab, added [MainDev] project
Now its working great!!
Thank you very much!!
:thumbup:
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to hear you got it working :)
 
reply
    Bookmark Topic Watch Topic
  • New Topic