• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

really basic question about compiling...

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a really basic question about compiling... I have to compile someone else's code... I have (say) two .java files, both with the same package name, in the same directory... one is called XmlUtil.java and defines object XmlUtil... the other is called (say) Foo.java and references XmlUtil... when I javac Foo.java it says basically "cannot resolve XmlUtil...". XmlUtil has been compiled and is on the classpath... what am I doing wrong? I know the code works and is legal...
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is the XmlUtil.class file and what is your classpath? What is the package that they are in. (XmlUtil should be in classpath\package directories)
[This message has been edited by Cindy Glass (edited October 16, 2001).]
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also where are YOU sitting when you compiled it?
 
doug byrnes
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you!!!
Um, ok... package name for both is (say)
package com.myclient.mycompany.util;
Both files are located in
c:\wuzawoo\jinkaboo\com\myclient\mycompany\util
I am in also c:\wuzawoo\jinkaboo\com\myclient\mycompany\util
Then, to make sure current location is on classpath (I am working in Windows) I did this:
set classpath=%CLASSPATH%;.
(Hmmmmm.... anyway, isn't Foo.java looking for XmlUtil.java (not .class), so does the classpath matter?)
As to your question about where I am sitting... I am sitting by the window... the morning light is slanting in through the blinds, making dappled patterns on the desktop... imparting an aura of warmth and calm to the room... could this be causing the problem?
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Um, ok... package name for both is (say)
package com.myclient.mycompany.util;
Both files are located in
c:\wuzawoo\jinkaboo\com\myclient\mycompany\util


Your classpath needs to be set to "c:\wuzawoo\jinkaboo." The package name (substituting slashes for dots), appended to your classpath, is the location of the files.

Originally posted by doug byrnes:
(Hmmmmm.... anyway, isn't Foo.java looking for XmlUtil.java (not .class), so does the classpath matter?)


Foo.java is looking for something in the same (com.myclient.mycompany.util) package. Given your package name, the XmlUtil.java (or XmlUtil.class) file should be in directory [classpath]\com\myclient\mycompany\util. So yes, the classpath and the package name are both vital. Just be sure you set classpath to "c:\wuzawoo\jinkaboo," and you should be okay.

I am in also c:\wuzawoo\jinkaboo\com\myclient\mycompany\util
Then, to make sure current location is on classpath...


As I stated above, this is your problem. You don't want the current location on the classpath. You want the location that holds the directory corresponding to the package name.
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by doug byrnes:
As to your question about where I am sitting... I am sitting by the window... the morning light is slanting in through the blinds, making dappled patterns on the desktop... imparting an aura of warmth and calm to the room... could this be causing the problem?


LOL !
Well I am sure that the state of your aura has much to do with your programming potential - but what I meant was, if you add a dot reference to your classpath
>set classpath = .;c:\etc.
Then whatever directory that you are currently in will become part of the classpath. Well that can confuse the system if you are sitting in one of the package subdirectories of the classpath. It thinks that that is THE classpath, and looks for the package subdirectories for imports to be below THAT. Doesn't work well.
 
doug byrnes
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Bill!!!
Thank you Cindy!!!

Got it!!!
whew!
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I find dappled patterns of sunlight on my desktop very annoying and often impede my judgement when compiling files.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by doug byrnes:

(Hmmmmm.... anyway, isn't Foo.java looking for XmlUtil.java (not .class), so does the classpath matter?)


Why does Foo.java look for XmlUtil.java to compile?
Why should XmlUtil.class not be enough to satisfy Foo.java when compiling?
Thanks,
Shilpa.
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It only looks for the class file. That is the only file that must be in the classpath or the package directory under the classpath.
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Cindy!
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic