Results 1 to 9 of 9
  1. #1
    DavidG24 is offline Member
    Join Date
    Apr 2009
    Posts
    49
    Rep Power
    0

    Default How to compile multiple files in terminal / dos

    Hi guys,

    I started learning Java in Eclipse and whilst I love it, I'm exploring doing my work via a text editor and (I'm using Windows at work) compiling via CMD.

    Now for an individual file, say

    public class file1 {

    ....

    }

    when I compile this file using javac file1.java, it creates the class file when I can call using java file1

    I'm hoping to go to the next stage when I have multiple classes that I want to bundle together in a package, but have no idea how to do this.

    i.e. two classes in separate .java files but under the one project

    I know there would be a tonne of tuts on this on the net, but I was hoping someone would be able to point me in the direction of a fairly simple to understand doco explaining how to do this.

    Thanks in Advance,

    David

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    The javac man page is not only authoratative but has some examples near the end.

  3. #3
    DavidG24 is offline Member
    Join Date
    Apr 2009
    Posts
    49
    Rep Power
    0

    Default

    hey mate,

    thanks for the link, to be honest I'm not fully understanding it - is there a textbook / webpage that does a dummy intro guide to it that you know of?

    Cheers,

    David

  4. #4
    santoshpai1 is offline Member
    Join Date
    Mar 2011
    Location
    Bangalore, India
    Posts
    5
    Rep Power
    0

    Default

    Hi David,
    If you see the folder, where your project is located you will find the answer. The package structure is a directory strcture actually. If you want to create a file Sample.java in the package examples.new.samples , you need to create this directory structure and the put the java file there.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by DavidG24 View Post
    hey mate,

    thanks for the link, to be honest I'm not fully understanding it - is there a textbook / webpage that does a dummy intro guide to it that you know of?

    Cheers,

    David
    What you've not understand in that page posted by pbrockway2?

  6. #6
    DavidG24 is offline Member
    Join Date
    Apr 2009
    Posts
    49
    Rep Power
    0

    Default

    Hi,

    I think I'm almost there, I now see that I have to have all the package files in a directory with its name, which I've done,

    I then used -
    (project is the package name)

    javac project/*.java {the folder containing the project foldre is called JavaPlay}

    which compiles everything nicely

    the file that contains the main method (mytest in this situation) is now causing me headaches as I'm trying to run that file.

    Do I have to set the classpath before hand or can I just use

    java -classpath project/; project.mytest ??

    The above is giving me an error

    ....I'm sure its something simple - I'll keep reading the specs and hopefully will figure it out.

    Cheers,

    David

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    The command is

    Java Code:
    java project.mytest

    (The class should really be MyTest and its source file project\MyTest.java)

    The point is not about the classpath but rather that you must give the java executable the full name of the class with main() in it. The full name includes the package part - think of it as surname.firstname

    If classpath becomes an issue (because the package folder itself may be somewhere else on the disk) then you use -classpath. But notice in that case case that the classpath won't have "project" in it, rather the classpath will include the folder containing project.

  8. #8
    DavidG24 is offline Member
    Join Date
    Apr 2009
    Posts
    49
    Rep Power
    0

    Default

    Hi guys,

    got it working now, many thanks to those who helped out, and for previous post, I'm assuming that when you say it should be Mytest etc that you are referrring to the Java Coding Conventions? if so, completely agree - changes have been made.


    Thanks again, was a good learning curve for me.

    Regards,

    David

  9. #9
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    You're welcome. And, yes, I was thinking about the conventions which have pretty much standard. Good luck with your programing!

Similar Threads

  1. run multiple jar files by one click
    By wallacetju in forum Advanced Java
    Replies: 0
    Last Post: 02-06-2011, 07:50 AM
  2. Replies: 0
    Last Post: 11-26-2010, 10:34 PM
  3. Compiling Multiple Files
    By Chasingxsuns in forum New To Java
    Replies: 4
    Last Post: 02-12-2010, 02:22 PM
  4. How to Compile JavaScript source into Java class files
    By tosreejith in forum New To Java
    Replies: 0
    Last Post: 04-06-2009, 04:12 PM
  5. Replies: 6
    Last Post: 02-06-2009, 09:05 PM

Posting Permissions

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