Results 1 to 9 of 9
- 03-17-2011, 06:32 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 49
- Rep Power
- 0
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
- 03-17-2011, 07:04 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
The javac man page is not only authoratative but has some examples near the end.
- 03-17-2011, 07:17 AM #3
Member
- Join Date
- Apr 2009
- Posts
- 49
- Rep Power
- 0
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
- 03-17-2011, 09:15 AM #4
Member
- Join Date
- Mar 2011
- Location
- Bangalore, India
- Posts
- 5
- Rep Power
- 0
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.
- 03-17-2011, 11:34 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 03-17-2011, 02:38 PM #6
Member
- Join Date
- Apr 2009
- Posts
- 49
- Rep Power
- 0
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
- 03-17-2011, 07:09 PM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.
- 03-17-2011, 11:50 PM #8
Member
- Join Date
- Apr 2009
- Posts
- 49
- Rep Power
- 0
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
- 03-18-2011, 04:37 AM #9
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Similar Threads
-
run multiple jar files by one click
By wallacetju in forum Advanced JavaReplies: 0Last Post: 02-06-2011, 06:50 AM -
[Compiling] How to compile .java files with .jar and put in another folder
By szmitek in forum New To JavaReplies: 0Last Post: 11-26-2010, 09:34 PM -
Compiling Multiple Files
By Chasingxsuns in forum New To JavaReplies: 4Last Post: 02-12-2010, 01:22 PM -
How to Compile JavaScript source into Java class files
By tosreejith in forum New To JavaReplies: 0Last Post: 04-06-2009, 03:12 PM -
Running .java-files won't work/compile does!(Code inside)
By wyldstyle in forum New To JavaReplies: 6Last Post: 02-06-2009, 08:05 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks