简体   繁体   中英

Can't get Javac to work on Mac OS X

I am trying to compile with javac on Snow Leopard through the command line. I have Xcode installed. I am just using a simple Hello World file, it works in Eclipse but I can't 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 blank.

Thanks for the help.

Are you using UTF-8 perhaps, with a byte order mark at the start of the file? Perhaps that's confusing javac?

Have a look at the file with a hex editor to see what it looks like.

On Mac OS X 10.5.8, the default file.encoding is MacRoman . Eclipse uses this as its default, but that default may be changed in Eclipse > Preferences > General > Workspace > Text file encoding , as well as in each project's properties. In NetBeans, a similar setting is available in each project's properties. EclipseWorkspace

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM