Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Compiling java file  RSS feed

 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • 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: 42975
76
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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: 60065
188
  • Mark post as helpful
  • send pies
  • 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
    • Quote
    • Report post to moderator
    Thanks.
    I got it!
     
    Campbell Ritchie
    Marshal
    Posts: 60065
    188
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well done
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!