user3837546
user3837546

Reputation: 93

Creating a java makefile for several .java files (ubuntu)

My java makefile currently looks like this:

main: javac userCreatedClass.java userCreatedClass2.java mainClass.java

After running 'make' in the terminal, I end up with a .class file for each of the .java files. My question is how do I now run my java program from the terminal? If there was only one .java file to begin with, at this point, in the terminal, I could enter

java Prog

and it would run my program. How would I be able to do this since I have multiple classes?

Upvotes: 0

Views: 481

Answers (2)

You only need to specify the class with the

public static void main(String[] args) {...

method. After that the JVM handles loading the classes you need for you. You may, however want to put the files in a subfolder named e.g. "somethng" and then use "package something" in each of the java files (but still compile from the top folder). This will save you from some subtle issues later.

Upvotes: 1

Henry
Henry

Reputation: 43778

You specify the class contining the static main method. So in your case most likely

java mainClass

Upvotes: 0

Related Questions