I have 4 Classes for my project, they are (titleScreen, credits, storyScreen, and camapaign) respectively, since they are connected to each other, I don't know how to get it compiled. One more thing is that when I used the commands (DOS / CMD) javac, it still did not work, saying the compiler can not find the other classes, but they are present as a class. How can I compile it and get it to work? By the way it is in console or without the GUI, so Clean and Build in Netbeans does not work.
A single Java program can contain more than one class and there are no restrictions on the number of classes that can be present in one Java program. But each Java program should have one class declared as public to make it accessible for classes in a different package.
Open a command prompt window and go to the directory where you saved the java program. Assume it's C:\. Type 'javac MyFirstJavaProgram. java' and press enter to compile your code.
Just do
javac *.java
Or if you have separate source and binary folders:
mkdir bin
javac -d bin src/*.java
Or if you have multiple source folders:
mkdir bin
shopt -s globstar # requires bash 4
javac -d bin src/**/*.java
As others have said, some variation on javac *.java
will do the trick. However, my suggestion is that you learn how to use a Java build tool:
The Apache Ant tool is the "moral equivalent" of the classic Make tool. You create an "build.xml" file containing the targets that you want to build in an OS independent fashion and the sequences of operations to be performed.
The Apache Maven tool is based on a different philosophy. Instead of saying how to build your code, you describe the code, its dependencies and the things that you want built. Maven takes care of the "how" of building ... plus lots more. This is more complicated in the short term, but (in my experience) it has lots of benefits in the long term.
Put your java files into a common folder, e.g. "directory", and then call javac directory/*.java
from the command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With