filenames on the command line

Discussion in 'Java' started by giuseppe.on.usenet, Dec 1, 2011.

  1. The current directory has two files:

    /* A.java */
    package wrk.pkg;
    import wrk.B;
    class A { B b; }

    /* B.java */
    package wrk;
    public class B { }

    The command javac -d . A.java B.java
    compiles successfully, while javac -d . A.java
    halts because it "cannot find symbol: class B". My question is: by
    adding other options, is it possible to have the compiler seek and
    compile B.java without specifying the filename on the command line?
     
    giuseppe.on.usenet, Dec 1, 2011
    #1
    1. Advertising

  2. giuseppe.on.usenet

    Lew Guest

    giuseppe.on.usenet wrote:
    > The current directory has two files:


    That's your first mistake - using the current directory.

    > /* A.java */
    > package wrk.pkg;


    This needs to be in directory "wrk/pkg/" relative to one of the classpath roots.

    I.e., the current directory the way you're working.

    > import wrk.B;
    > class A { B b; }
    >
    > /* B.java */
    > package wrk;


    This needs to be in relative directory "wrk/".

    Notice that this is necessarily a *different* directory than the other class.

    > public class B { }
    >
    > The command javac -d . A.java B.java


    You're supposed to use directory notation with javac rather than "dot" notation.

    I was not aware that dot notation even worked here.

    In any case, it only partially "worked", not completely, at best, because you have things in the wrong directories.

    > compiles successfully, while javac -d . A.java
    > halts because it "cannot find symbol: class B". My question is: by


    Because things are in the wrong directories.

    > adding other options, is it possible to have the compiler seek and
    > compile B.java without specifying the filename on the command line?


    Why don't you read the documentation?

    You will find it astonishingly helpful.

    --
    Lew
     
    Lew, Dec 1, 2011
    #2
    1. Advertising

  3. On 1 Dic, 15:54, Lew <> wrote:
    > giuseppe.on.usenet wrote:
    > > The current directory has two files:

    >
    > That's your first mistake - using the current directory.
    >


    I am studying for an Oracle certification and I found this exercise in
    a book. There are at least five similar questions and all of them put
    the classes in the same directory, even if they belong to different
    packages. I agree with you that this is not the best practice but it
    is not my fault if the quiz is conceived that way.

    > [...]
    > Why don't you read the documentation?
    >
    > You will find it astonishingly helpful.


    Three books + the man page should be enough but if I had found the
    answer there I wouldn't have posted here.
     
    giuseppe.on.usenet, Dec 1, 2011
    #3
  4. giuseppe.on.usenet

    Lew Guest

    On Thursday, December 1, 2011 7:46:10 AM UTC-8, giuseppe.on.usenet wrote:
    > On 1 Dic, 15:54, Lew <> wrote:
    > > giuseppe.on.usenet wrote:
    > > > The current directory has two files:

    > >
    > > That's your first mistake - using the current directory.
    > >

    >
    > I am studying for an Oracle certification and I found this exercise in
    > a book. There are at least five similar questions and all of them put
    > the classes in the same directory, even if they belong to different
    > packages. I agree with you that this is not the best practice but it
    > is not my fault if the quiz is conceived that way.


    It's not "not a best practice", it's the wrong way to do it.

    It is your fault if you fail to learn the truth of what Java does.

    > > [...]
    > > Why don't you read the documentation?
    > >
    > > You will find it astonishingly helpful.

    >
    > Three books + the man page should be enough but if I had found the
    > answer there I wouldn't have posted here.


    Oracle's Java site has the best fundamental data and generally easiest to get to, plus it's authoritative. Everyone should have bookmarks to the tools documentation
    http://docs.oracle.com/javase/7/docs/
    (or use http://lmgtfy.com/?q=java tools documentation)
    specifically
    http://docs.oracle.com/javase/7/docs/technotes/tools/index.html#basic
    "You should arrange source files in a directory tree that reflects their package tree. For example, if you keep all your source files in /workspace, the source code for com.mysoft.mypack.MyClass should be in /workspace/com/mysoft/mypack/MyClass.java."

    The tutorials give the same information.

    --
    Lew
     
    Lew, Dec 1, 2011
    #4
  5. giuseppe.on.usenet

    Roedy Green Guest

    On Thu, 1 Dec 2011 06:37:50 -0800 (PST), "giuseppe.on.usenet"
    <> wrote, quoted or indirectly quoted
    someone who said :

    >he command javac -d . A.java B.java
    >compiles successfully, while javac -d . A.java
    >halts because it "cannot find symbol: class B". My question is: by
    >adding other options, is it possible to have the compiler seek and
    >compile B.java without specifying the filename on the command line?


    javac *.java

    It won't recompile if not necessary.

    If you want fast compiles you need ANT , if you have several packages
    to compile.

    see http://mindprod.com/jgloss/ant.html
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    For me, the appeal of computer programming is that
    even though I am quite a klutz,
    I can still produce something, in a sense
    perfect, because the computer gives me as many
    chances as I please to get it right.
     
    Roedy Green, Dec 2, 2011
    #5
  6. giuseppe.on.usenet

    Roedy Green Guest

    On Thu, 1 Dec 2011 06:54:48 -0800 (PST), Lew <>
    wrote, quoted or indirectly quoted someone who said :

    >> /* A.java */
    >> package wrk.pkg;

    >
    >This needs to be in directory "wrk/pkg/" relative to one of the classpath roots.


    This drives every newbie nuts. I discovered that thinking about HOW
    the compiler finds java source and how java.exe finds classes made it
    all fall into place.

    see
    http://mindprod.com/jgloss/helloworld.html
    http://mindprod.com/jgloss/classpath.html
    http://mindprod.com/jgloss/package.html
    http://mindprod.com/jgloss/javacexe.html
    http://mindprod.com/jgloss/javaexe.html

    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    For me, the appeal of computer programming is that
    even though I am quite a klutz,
    I can still produce something, in a sense
    perfect, because the computer gives me as many
    chances as I please to get it right.
     
    Roedy Green, Dec 2, 2011
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lucas Cowald
    Replies:
    4
    Views:
    1,071
    Tohid
    Oct 23, 2003
  2. B.J.
    Replies:
    4
    Views:
    744
    Toby Inkster
    Apr 23, 2005
  3. Bernd Oninger
    Replies:
    1
    Views:
    792
    Martin Honnen
    Jul 7, 2004
  4. Replies:
    4
    Views:
    1,715
    Terry Hancock
    Apr 23, 2005
  5. Lucas Cowald

    RUN/execute a Command-Line command from an ASP page

    Lucas Cowald, Oct 22, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    246
    Genich
    Oct 22, 2003
Loading...

Share This Page