I'm really new to java. I don't like Eclipse because I want to work with bare stuff like just compiling with command prompt, so... Would I just type something like javac class1.java class2.java. And would it link them together?
Five answers:
Light Cloud
2011-05-29 22:44:48 UTC
You can create .jar files that contain a bunch of compiled classes, although I'm not too familiar with how to do that.
However, in the really simple case in which you just have a bunch of .java files lying around in a folder, "javac *.java" would compile all of them. (In your case, javac *.java would create a class1.class file and class2.class file, and assuming class1 has the main method, "java class1" would then execute the program.)
anonymous
2016-10-16 05:32:46 UTC
Compile Multiple Java Files
CricSync
2011-05-30 02:02:43 UTC
If you are using an IDE, you done need to worry about compiling your code since Java IDE will do that for you.
ANT and maven can also be used to compile your projects.
You you want to keep it simple, the following will do the job assuming all hava files are in the root folder:
javac *.java
To compile 2 classes that are in package test:
javac test\Class1.java test\Class2.java
Jane
2016-02-28 02:57:15 UTC
Strange. For me it works fine under Windows. As long as each class is defined in a source file of the same name, javac will find it. You could also do "javac packagename/*.java" assuming all your java files are in a folder called "packagename".
?
2011-05-30 01:30:49 UTC
you can put them all in one package, for example you have "test1.java" and "test2.java" and you want them to be compile together so you put them in same package called "test"......so you should open "test1.java" and write this line in the very beginning (the first line only) : package test;
do the same for "test2.java"
so when you are compiling the main file (the file that has main method in it) it will compile others and will run them together
for example if main method is in "test1.java" , javac test1.java will compile every class that is in test package
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.