Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: making a .bat file that compiles your java files

  1. #1
    Member
    Join Date
    Oct 2010
    Posts
    38
    Thanks
    11
    Thanked 1 Time in 1 Post

    Exclamation making a .bat file that compiles your java files

    I made a .bat file that would compile my java files for a visual basic project that im doing. This is the code for the batch file:

    @echo off
    title Java Compiler
    :start
    javac *java
    pause
    goto start
    When it gets called from my project i get this error:

    javac: invalid flag: *java
    Usage: javac <options> <source files>
    use -help for a list of possible options
    Press any key to continue . . .
    However when i run this file from the directory its placed it it works fine. Any ideas about whats wrong?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: making a .bat file that compiles your java files

    try 'javac *.java'

  3. #3
    Member
    Join Date
    Oct 2010
    Posts
    38
    Thanks
    11
    Thanked 1 Time in 1 Post

    Default Re: making a .bat file that compiles your java files

    now i get this error:

    javac: file not found: *.java
    Usage: javac <options> <source files>
    use -help for a list of possible options
    Press any key to continue . . .

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: making a .bat file that compiles your java files

    Just to step back a bit...why not use an IDE such as Eclipse to do all this work for you?

    Back to the problem at hand, the file must be in the proper location relative to where javac is being executed (aka where the .bat file is).

  5. #5
    Member
    Join Date
    Oct 2010
    Posts
    38
    Thanks
    11
    Thanked 1 Time in 1 Post

    Default Re: making a .bat file that compiles your java files

    I can't use eclipse because this is a Visual Basic Project. I'm making my own Java IDE in Visual Basic. In Visual Basic the file i mentioned gets put into the same folder as the java files and it just doesn't work when it gets called.

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: making a .bat file that compiles your java files

    Don't put *.java, you need to replace this with the actual file name.

    rem this will compile a file named test.java
    javac test.java

    There are also various parameters you will need to consider when building via command-line. I won't go into the details for each one, but these are the main ones:

    1. Multiple source files
    2. packages/multiple packages, nested packages
    3. external libraries.

    You can also pass in command-line arguments for batch files. I can't remember the exact semantic, but I believe it's something like this:
    rem this is build.bat
    rem this will compile a file named specified in the first parameter
    javac %1

    Then, to use this batch file:

    build.bat test.java

Similar Threads

  1. Making computer independent file path
    By Javabeginner in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: September 2nd, 2010, 03:56 PM
  2. Methods in java class files are not recognized.
    By Girish in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 18th, 2010, 05:44 AM
  3. Calling exe files from Java
    By linuxrockers in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 26th, 2010, 04:20 AM
  4. Need help compiling java class files
    By peahead in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 11th, 2010, 09:04 AM
  5. merging two tables from two diffrent htmls files using java
    By sukant_at in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: September 1st, 2009, 05:13 AM