-2

I have a very small program with just one java file with the main method inside. I tested the program in my Ubuntu terminal by javac Program.java and the java Program.java and all was good. Then I used rsync to send the project directory to FreeBSD that is running in a VM. There I did javac Program.java but when I run java Program.java then it is not finding the main. This is some CLASSPATH stuff - do I need to configure that in the JDK on the VM machine?

hk222su@freebsd-vm-group25:/home/hk222su % ls
groupAssignment1    Program.class       Program.java        Received
hk222su@freebsd-vm-group25:/home/hk222su % rm Program.class Program.java 
hk222su@freebsd-vm-group25:/home/hk222su % ls
groupAssignment1    Received
hk222su@freebsd-vm-group25:/home/hk222su % cd groupAssignment1 
hk222su@freebsd-vm-group25:/home/hk222su/groupAssignment1 % ls
1dv512_group25_assignment1.iml  out             screenshots         some_notes          src
hk222su@freebsd-vm-group25:/home/hk222su/groupAssignment1 % cd src
hk222su@freebsd-vm-group25:/home/hk222su/groupAssignment1/src % ls
Program.class   Program.java
hk222su@freebsd-vm-group25:/home/hk222su/groupAssignment1/src % javac Program.java 
hk222su@freebsd-vm-group25:/home/hk222su/groupAssignment1/src % java Program.java
Error: Could not find or load main class Program.java
hk222su@freebsd-vm-group25:/home/hk222su/groupAssignment1/src % java Program.java
Error: Could not find or load main class Program.java
hk222su@freebsd-vm-group25:/home/hk222su/groupAssignment1/src % javac Program.java
hk222su@freebsd-vm-group25:/home/hk222su/groupAssignment1/src % java Program.java 
Error: Could not find or load main class Program.java
hk222su@freebsd-vm-group25:/home/hk222su/groupAssignment1/src % 


Delpux
  • 137
  • 4
  • "java Program.java" should not have worked in your Ubuntu terminal. There is more to the story that you are not telling us. – swpalmer Nov 11 '20 at 21:33
  • @swpalmer Since Java 11 (I think) you can actually execute simple programs using `java Program.java`, but it looks like the OP is using Java 8. – Mark Rotteveel Nov 25 '20 at 10:53
  • @MarkRotteveel Yes, you are correct that was in Java 11 with https://openjdk.java.net/jeps/330 – swpalmer Nov 25 '20 at 14:20

1 Answers1

4

When you run the compiled program, use

java Program

instead of

java Program.java