Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling java file

 
Nabila Mohammad
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






 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • 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).
 
David Newton
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
 
Campbell Ritchie
Sheriff
Posts: 48441
56
  • 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
    Sheriff
    Posts: 48441
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well done
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic