Page 2 of 2 FirstFirst 12
Results 21 to 33 of 33
Like Tree1Likes

Thread: for gimbal2: How to compile from command line and what about the classpath

  1. #21
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,757
    Rep Power
    19

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    Every class the code you are compiling uses is a dependency.
    Some are part of the JDK, so you don't have to worry about them.
    For the rest, you need to tell Java where to find them.
    That is what you list in the classpath.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  2. #22
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,038
    Rep Power
    8

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    Thanks for all your help and patience. I saved the classpath in the file ".bash_profile"
    and after opening a new terminal window this works:
    echo $CLASSPATH
    .:/Users/willem/javastuff:/Users/willem/javastuff/src:/Users/willem/javastuff/pcg

    But the strange part is that I can run a classfile from all the spots by just saying:
    java classfile and it works (great)
    but when I do:
    javac PrivatChat.java
    I can only compile that file at the current directory and none of the other spots work, getting:
    javac: file not found: PrivatChat.java
    (and of course I put a source file at all the above spots)
    wow, I wonder why? should I install my java again?

    You see, it is important that I get this to work and I understand what happens,
    because from now on I will program from the command line and leave Netbeans for the moment!
    Last edited by willemjav; 09-12-2013 at 07:43 PM.

  3. #23
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,038
    Rep Power
    8

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    Since this might be another "death-end-street"I would be very happy when anybody would chooses one of the next three options:

    1) the classpath works equally for javac and java and when the .java .class are at the same directory and the cp points to that folder,
    javac xxxx.jav and java xxxx should both work;
    2) No (to point 1), you are still missing something
    3) various (which will send me back to start)

  4. #24
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,757
    Rep Power
    19

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    I explained exactly how the compiler treats the various parameters put into it.

    The classpath tells it where to find dependencies.
    It does not give it any pointers as to where the file you want to compile is.

    In order to compile a file you need to give it either the full path, or a path relative to where you are compiling from.

    This is why your "javac PrivatChat.java" didn't work as that file was not in your current directory.

    For running (ie the java command), the classpath points to the location of all the classes and resources you need to run your code.
    The class to execute is, in this case, not a file, but something that can be found on that classpath.

    You compile files, you execute classes.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #25
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,602
    Rep Power
    5

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    You know, trying to teach someone how compilation works who doesn't know the basics of using the filesystem is like teaching someone how to do addition who hasn't learned yet what a number is. At what point do you realize that you lack (very) basic knowledge and you take a step back and go learn that? I hope that moment isn't too far away.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #26
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,757
    Rep Power
    19

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    I know, but it's that old xkcd cartoon "Someone on the internet is wrong!"
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #27
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,602
    Rep Power
    5

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    He he, I know that one :) MUST COMMENT! http://xkcd.com/386/

    (it was not directed at you by the way, just a general reply to the thread and thus the OP)
    Last edited by gimbal2; 09-13-2013 at 12:58 PM. Reason: added link
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #28
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,038
    Rep Power
    8

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    I must say that I am very pleased that you guys did not turn silent on me! The worst punishment of a blog is when there are no answer at all…… big silence (It most have been horrible in those ancient times when kings and queens and the people where confronted by a deep silence of the Oracle).

    "I explained exactly how the compiler treats the various parameters put into it." and "The classpath tells it where to find dependencies."
    Right tolls, you did and it was like crystal-clear-water running through my hands. Since this line is key to my problem I will work hard understanding it!

    "It does not give it any pointers as to where the file you want to compile is."
    You, see that would be the most obvious thing what a "classpath" (with the stress on path) would do, right? Wrong, but a deeper understanding of this fact ties into your first remark.

    "In order to compile a file you need to give it either the full path, or a path relative to where you are compiling from."
    Right, I know how to do that one, but still what is than the classpath for? Answer: go back to start (without your 200$ bonus).

    "This is why your "javac PrivatChat.java" didn't work as that file was not in your current directory."
    That is an interesting one, to be elaborated some more, tolls. I thought that the (unseeable) dot of the classpath variable was responsible for that one (therefor I put the little dot as first option of my newly stored CLASSPATH var).
    So I did some testing here (since I do know now where, thanks to gimbal, the CP is, and thanks to myself, I do know now how to change it). So I assigned an empty string to the CP variable (so getting rid of the dot) and watched if java would still compile from the current dir…… and guess what (no guess for you tolls) it did, wow so the CP had nothing to do here!

    Now it gets really creepy and mysterious, tolls and we might need to consult the Oracle after all?
    "in this case, not a file, but something that can be found on that classpath."
    Wow, what might that "something" be, will the priest class of the Oracle raise a tip of the curtain here?

    "You compile files, you execute classes." right I got that one before!

    Yes gimbal it is fun to make fun and inspite your superiority in Java programming, please come down from the Olympus and mingle with the living souls.
    I do know the working of the file system: no question about that! But I did address an interesting issue concerning that subject. A package is a file directory and Java issue at the same time (that is why I had my A and B class within a package). That fact was also a bit confusing but I did "master" that issue (note the ironic quotes, because I try to be very humble here). Gimbal I challenge you to comment on my private chat program which I did recently and which shows you that I really mastered the beginning steps of Java programming. But there is still much to learn and that is why I am here (if you guys do not kick me out)!
    Last edited by willemjav; 09-13-2013 at 01:20 PM.

  9. #29
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,757
    Rep Power
    19

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    Quote Originally Posted by willemjav View Post
    I must say that I am very pleased that you guys did not turn silent on me! The worst punishment of a blog is when there are no answer at all…… big silence (It most have been horrible in those ancient times when kings and queens and the people where confronted by a deep silence of the Oracle).
    Um...this is not a blog.
    This is a forum.
    They are two different things.

    Quote Originally Posted by willemjav View Post
    "I explained exactly how the compiler treats the various parameters put into it." and "The classpath tells it where to find dependencies."
    Right tolls, you did and it was like crystal-clear-water running through my hands. Since this line is key to my problem I will work hard understanding it!

    "It does not give it any pointers as to where the file you want to compile is."
    You, see that would be the most obvious thing what a "classpath" (with the stress on path) would do, right? Wrong, but a deeper understanding of this fact ties into your first remark.
    No.
    Say you had a java file called Blah.java.
    And you have another java file, in a different folder, but still under the same package structure, called Blah.java.
    How do you tell the code which one you want to compile?
    You might say "give the path"...but then that's what you're doing anyway.
    So may as well keep it simple where the classpath is for dependencies.
    Quote Originally Posted by willemjav View Post
    "In order to compile a file you need to give it either the full path, or a path relative to where you are compiling from."
    Right, I know how to do that one, but still what is than the classpath for? Answer: go back to start (without your 200$ bonus).
    DEPENDENCIES!
    If you don't understand that term then I'm afraid you need to do some reading.
    Quote Originally Posted by willemjav View Post
    "This is why your "javac PrivatChat.java" didn't work as that file was not in your current directory."
    That is an interesting one, to be elaborated some more, tolls. I thought that the (unseeable) dot of the classpath variable was responsible for that one (therefor I put the little dot as first option of my newly stored CLASSPATH var).
    So I did some testing here (since I do know now where, thanks to gimbal, the CP is, and thanks to myself, I do know now how to change it). So I assigned an empty string to the CP variable (so getting rid of the dot) and watched if java would still compile from the current dir…… and guess what (no guess for you tolls) it did, wow so the CP had nothing to do here!
    I have explained this several times now.
    Quote Originally Posted by willemjav View Post
    Now it gets really creepy and mysterious, tolls and we might need to consult the Oracle after all?
    "in this case, not a file, but something that can be found on that classpath."
    Wow, what might that "something" be, will the priest class of the Oracle raise a tip of the curtain here?
    It's a class...it could be in a jar file, so is not a file, but a resource inside a jar.
    Do not think of them as files.
    For example:
    java -cp <some classpath> mypack.MyClass
    "mypack.MyClass" is not a file. You will not find a file with that name on your file syetem.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #30
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,038
    Rep Power
    8

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    It is true I do not undertand DEPENDENCIES! in this context!
    But I like to read so do not be afraid...

  11. #31
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,602
    Rep Power
    5

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    Quote Originally Posted by willemjav View Post
    It is true I do not undertand DEPENDENCIES! in this context!
    But I like to read so do not be afraid...
    I hope so, because you have plenty of reading to do still. And I'm not talking about Java only, also about how operating systems and computers work.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #32
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,038
    Rep Power
    8

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    any suggestion of good books, gimbal2

  13. #33
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,602
    Rep Power
    5

    Default Re: for gimbal2: How to compile from command line and what about the classpath

    Nope; I learned it in the proper place myself: in school. I don't think Dutch books will help you.

    Check amazon.com user reviews to figure out which books are good and which are not - that's what I do when I'm looking for something.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 4
    Last Post: 01-02-2013, 08:50 PM
  2. Replies: 4
    Last Post: 04-06-2012, 08:30 AM
  3. Replies: 16
    Last Post: 09-17-2011, 02:41 AM
  4. Replies: 3
    Last Post: 08-25-2010, 10:21 AM
  5. [SOLVED] Compile from the command line
    By GilaMonster in forum New To Java
    Replies: 8
    Last Post: 06-13-2008, 07:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •