Java and the Mac OS X Terminal
$ java -version
$ javac HelloWorld.java
$ java HelloWorld
if your program gets stuck in an infinite loop, type Ctrl-c to break out.
If you are entering input from the keyboard, you can signify to your program that there is no more data by typing Ctrl-d for EOF (end of file). You should type this character on its own line.
When I try to run java I get: Error: Could not find or load main class Hello.class.
First, be sure that HelloWorld.class is in the current directory. Be sure to type java HelloWorld without a trailing .class
or .java
. If this was not your problem, it's possible that your CLASSPATH
was set by some other program so that it no longer includes the current working directory. Try running your program with the command line
$ java -cp ./ HelloWorld
If this works, your classpath is set incorrectly.
I get the error class file has wrong version 50.0, should be 49.0
when I compile from the Terminal. What does this mean? It's probably because DrJava is configured to use Java 6.0 and and your Terminal is configured to use Java 5.0. To change the default version of Java in your Terminal, launch Java Preferencest. Drag the Java SE 6 - 64-bit entry to appear first.
How do I get the menu to display at the top of the screen instead of at the top of the frame? Execute with java -Dapple.laf.useScreenMenuBar=true
Where can I learn more about the command line? Here is a short tutorial on the command-line.
Reference
http://introcs.cs.princeton.edu/java/15inout/mac-cmd.html
http://introcs.cs.princeton.edu/java/15inout/classpath.html
http://introcs.cs.princeton.edu/java/15inout/unix.html
上一篇: Java集合源码全面分析
推荐阅读
-
Mac OS X 系统修改Terminal终端配色
-
Mac OS X Terminal教程
-
Java and the Mac OS X Terminal
-
Mac OS X 下 IntelliJ IDEA、jEdit 等 Java 程序中文标点输入无效的完美解决方法
-
Mac OS X 下 IntelliJ IDEA、jEdit 等 Java 程序中文标点输入无效的完美解决方法
-
在Mac OS上安装Java以及配置环境变量的基本方法
-
在Mac OS上安装Java以及配置环境变量的基本方法
-
在MAC OS X上安装MYSQL
-
mac系统OS X10.10版本安装最新5.7.9mysql的方法
-
Mac OS 安装java 开发环境