无法让Javac在Mac OS X上工作(Can't get Javac to work on Mac OS X)

编程入门 行业动态 更新时间:2024-10-27 12:33:14
无法让Javac在Mac OS X上工作(Can't get Javac to work on Mac OS X)

我想通过命令行在Snow Leopard上用javac编译。 我安装了Xcode。 我只是使用一个简单的Hello World文件,它在Eclipse中工作,但我无法使用javac使它工作。 javac -version返回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); } }

我输入:javac HelloWorld.java

并得到以下错误。

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

和...

javac -cp。 HelloWorld.java

返回相同。

echo $ CLASSPATH只是返回空白。

谢谢您的帮助。

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.

最满意答案

您是否正在使用UTF-8,并在文件的开始处使用字节顺序标记 ? 也许这是令人困惑的javac?

用十六进制编辑器查看文件,看看它是什么样子。

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.

更多推荐

本文发布于:2023-08-07 04:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1460060.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作   Mac   Javac   work   OS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!