Results 1 to 8 of 8

Thread: javac with -sourcepath switch

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Resolved javac with -sourcepath switch

    I'm a little bit of lost with the -sourcepath switch. I'm structuring my project like this
    Code:
    classes
        + class destination
    docs
        + documentation
    src
        + java files
    make.bat
    And my make.bat is
    Code:
    javac -d classes -sourcepath src/*.java
    javadoc -d doc -sourcepath src/*.java
    But it only gets the last file. Say I have dtgen.java and Server.java, it only gets Server.java to be compiled and the class gets to classes and Server.html to doc+generated htmls.

    What should I put after -sourcepath switch? Right now, I ended up to putting make.bat to src folder having a content like
    Code:
    javac -d ../classes *.java
    javadoc -d ../doc *.java
    Thanks in advance.
    Last edited by nebulom; Jun 14th, 2005 at 04:43 AM.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: javac with -sourcepath switch

    -sourcepath src

    I also highly recommend Ant over any other build system for Java.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: javac with -sourcepath switch

    Thanks, CB. I'll be learning Ant.

    -sourcepath src BTW, doesn't do compiling. It says javac: no source files. Nevermind anyway, have to find good build system.
    Last edited by nebulom; Jun 14th, 2005 at 03:46 AM.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: javac with -sourcepath switch

    The -sourcepath switch doesn't specify which files to compile. It merely tells javac where to look for source files that the explicitely specified sources depend on.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: javac with -sourcepath switch

    javac -d classes -sourcepath src

    Does it suppose to compile all the .java in the src folder? It just displays the Usage: javac <options> <source files> after displaying javac: no source files.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: javac with -sourcepath switch

    No, it does nothing, because you specified no source files. But consider this:
    Code:
    // Class1.java
    public class Class1
    {
    }
    
    // Class2.java
    public class Class2 extends Class1
    {
    }
    Clearly, Class2.java depends on Class1.java being available. Let's assume you have this directory structure:
    Code:
    PROJECT_ROOT
    -> classes (compiled sources)
    -> docs (documentation)
    -> src (source code)
      -> Class1.java
      -> Class2.java
    From the PROJECT_ROOT, you could now type
    Code:
    javac -d classes src/Class2.java
    The compilation will fail:
    Code:
    src/Class2.java:3: cannot find symbol
    symbol: class Class1
    public class Class2 extends Class1
                                ^
    1 error
    The compiler can't find Class1.java.

    This command will succceed:
    Code:
    javac -d classes -sourcepath src src/Class2.java
    Now the compiler knows where to look for dependencies. It will compile both Class1.java and Class2.java.

    You should also add the -classpath:
    Code:
    javac -d classes -classpath classes -sourcepath src Class2.java
    This way, the compiler will find Class1.class if it exists, and not compile it again.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: javac with -sourcepath switch

    Assuming I have Class2.java, it says error: cannot read: Class2.java. I don't what did I miss but I've compiled it by javac -d classes -classpath classes -sourcepath src dtgen.java and I'm pretty sure, there is a dtgen.java in the src folder.

    error: cannot read: dtgen.java

    Thanks for being patient CB. I think I just have to learn Ant from now on. Again, thanks.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: javac with -sourcepath switch

    I edited my post after actually trying out what I wrote.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width