Cannot get Javac to work on Mac OS X

I am trying to compile using javac on Snow Leopard via the command line. I have Xcode installed. I just use a simple Hello World file, it works in Eclipse, but I cannot get it to work using javac.
javac -version returns javac 1.6.0_17

HelloWorld.java

public class HelloWorld
{
   public static void main(String[] args)
   {
 String message = "Welcome to Java!";
        System.out.println(message);
   }
}

I type: javac HelloWorld.java

and get the following error.

HelloWorld.java:1: class, interface, or enum expected
public class HelloWorld 
^
1 error

and...

javac -cp. HelloWorld.java

returns the same.

echo $ CLASSPATH just returns empty.

Thanks for the help.

+3
source share
2 answers

Perhaps you are using UTF-8 with an order byte at the beginning of the file? Perhaps this confusing javac?

, , .

+8

Mac OS X 10.5.8 file.encoding MacRoman - MacRoman. Eclipse , Eclipse > Preferences > General > Workspace > Text file encoding, . NetBeans . Eclipseworkspace

+2

Source: https://habr.com/ru/post/1743846/


All Articles