• 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

Compiling java file

 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a pretty silly problem.
I am trying to complile the Person.java file which creates the Dog variable ( Dog class is compiled)
From what i know , the memebers from with in the same package automatically gets imported , however here, i have tried everything by importng and setttng the classpath but still get the same error where "class Dog" symbol cannot be found.- the variable Dog, and the methods getDog() and setDog() cannot be found






 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to a more appropriate forum, since the question has nothing to do with the SCWCD exam (which this forum is about).
 
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
Without knowing how you're trying to compile it, the directory layout, etc. it'll be tough to help.
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here it is..

My class files are stored in classes/foo directory
and my source (java) files are stored in src/foo directory

This is the file structure:

C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/Testing/web-inf/classes/foo/Dog.class

C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/Testing/web-inf/src/foo/Dog.java
C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/Testing/web-inf/src/foo/Person.java

And at the command prompt its :
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\Testing\WEB-INF> javac -classpath "C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/Testing/web-inf/classes" -d classes src/foo/Person.java
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you putting your work into a Program Files directory? Leave that for installed code, or code Tomcat creates for itself.

This is what I suggest.

Create your own java_work or similar directory.
  • Open command prompt. This will default to "My Documents"
  • Create a folder with "mkdir java_work" You now have this directory in "My Documents"
  • Navigate there with "cd java_work"
  • mkdir foo
  • Move your Dog.java and Person.java files into the new foo directory
  • Compile with "javac foo/Dog/java" then "javac foo/Person.java"
  • There are many other ways to do it.

    By the way: the import statement in Person is unnecessary. Also you can probably say Dog rather than foo.Dog.
     
    Nabila Mohammad
    Ranch Hand
    Posts: 664
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks.
    I got it!
     
    Campbell Ritchie
    Marshal
    Posts: 79151
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well done
     
    Popeye has his spinach. I have this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic