• 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

Why am I getting these weird package errors?

 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


HibernateUtil.java is in the same directory as the model folder and looks like this:



Code associated to user was commented out because that was the only way it would compile.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

javac -classpath "C:\_hiblib\*" C:\_mycode\com\examscam\model\User.java


Two things: The classpath does not accept wildcards, so you'll either need to use "C:\_hiblib" or include all subdirectories of "C:\_hiblib" explicitly. Secondly, you can make it easier on the compiler by using relative paths like "com\examscam\model\User.java" instead of "C:\_mycode\com\examscam\model\User.java". That way, it'll know how to find other source files that wre in the same directory. You can also use wildcards like "com\examscam\model\*.java".
 
Matt Kidd
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:

javac -classpath "C:\_hiblib\*" C:\_mycode\com\examscam\model\User.java


Two things: The classpath does not accept wildcards, so you'll either need to use "C:\_hiblib" or include all subdirectories of "C:\_hiblib" explicitly. Secondly, you can make it easier on the compiler by using relative paths like "com\examscam\model\User.java" instead of "C:\_mycode\com\examscam\model\User.java". That way, it'll know how to find other source files that wre in the same directory. You can also use wildcards like "com\examscam\model\*.java".



Now i"m more confused. I removed the wildcard from the original line and I get "no source files" error from javac. This happens using a relative path as well. I remove the \ and get 27 errors for not finding the hibernate jars.
 
Matt Kidd
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
searched the forum and all I had to do was put a period in to include the current diretory



turns out my CLASSPATH environment variable was not set.

but I'm still confused as to why when I'm in the same directory the packages were not finding each other.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I generally advise not to use the CLASSPATH variable at all; it's generally more hassle than it's worth.

And, again, the "C:\_hiblib\*" part does nothing because classpaths don't accept wildcards (or do you have a directory named "*" ?).

Note that "." is the default classpath, so if you had used no "-classpath" switch at all, that's what would have been used, and it should have worked if all class files are somewhere in the C:\_mycode hierarchy.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf for hepling Matt get my code snippets working.

That darn wildcard works in JDK 6! I'm not lying, it does, it does, it does!!! I'm not sure if support was added in JDK 6, or an update version, but it's supported. Or maybe it's Windows that's making it possible. The darn stuff does work though! It works somewhere? I'm pretty sure it's JDK 6 and on where you're good with this.

I'm doing a little update on the book. I'll find out where and when the wildcard doesn't work and document it in there.

Thanks again!

-Cameron McKenzie

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a new JDK 6 feature; the wildcard expands to all jar files in a directory. On UNIX platforms you have to remember to escape it, so the shell doesn't expand it for you!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic