开发者

Can't get Javac to work on Mac OS X

开发者 https://www.devze.com 2022-12-28 19:16 出处:网络
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 jav

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.

Tha开发者_如何学Pythonnks 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.

Can't get Javac to work on Mac OS X

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号