![](/uploads/1/2/5/7/125719689/836437811.jpg)
I am new to Java (as of today!) and am trying to run a very simple program in terminal. Normally, when I run a python (still pretty new) program in Terminal I would simple type in 'python name.py' in to terminal and it would run. When I type 'Java name.java' it does absolutely nothing.
I opened TextWrangler and selected 'Run in Terminal' and it returned this error:
'This file doesn't appear to contain a valid 'shebang' line (application error code: 13304)'
Jan 20, 2006 - If you use TextWrangler to edit java source code, // this AppleScript will compile the front window. Tell application 'TextWrangler' set the_file. TextWrangler is the powerful general purpose text editor, and Unix and server administrator’s tool. Specifically, TextWrangler provides syntax coloring for HTML/XHTML, XML, PHP, JavaScript, Perl, Python, Ruby, Lua, Java, ANSI C, C++ and Objective-C. TextWrangler includes a wide range of options when it comes to finding pieces of text in your.
My program is named 'hello.java' and it contains the code below.
What am I doing wrong?
user3961615
3 Answers
Open the terminal, go to the directory where the file is located and do this:
Of course, both
javac
and java
must be available in the operating system's PATH variable, but in a Mac that's already configured.Óscar LópezÓscar López
![Textwrangler Textwrangler](/uploads/1/2/5/7/125719689/900503274.png)
Type
The first line calls the compiler and compiles it in the current directory then the next line runs it
jcjunctionjcjunction
'Run in terminal' attempts to run the software as an interpreted script. On UNIX-like systems (meaning almost everything except Windows), a shebang line is used to indicate, what interpreter is to be used. It consists of the characters
#!
followed by the command to invoke the interpreter (e.g. #!/usr/bin/python
or #!/usr/bin/ruby
). However, Java is not (only) interpreted.java
only runs compiled Java bytecode, so it does not work on source filesInstead, head over to the terminal yourself, compile the code with
javac
and run the resulting bytecode (the .class
files) with java
:where
the_file_name.java
is the file containing main(...)
and the_class_name
is the name of the class containing main(...)
(this should usually be the same as the_file_name
)hlthlt
I just started using TextWrangler in place of Eclipse for writing Java programs. I found a script for testing Java programs in Terminal, but I’d like to handle everything right through TextWrangler. What’s the Java shebang for OS X? Or is there a Java shebang which is specifically for TextWrangler?
JblagdenJblagden
3 Answers
Here is a simple wrapper script that effectively can work as a Java shebang on OS X and Linux:
However, as pointed out in the comments this is technically not a 'shebang', but it comes pretty close in terms of functionality.
d99krisd99kris
The --source argument is required. If the source argument is omitted the following error message will be produced.
Here is a complete example
Mark HamlinMark Hamlin
The java executable is /usr/bin/java
So shebang is
However a java program is usually in more than one java file and so you need a build system e.g. ant, gradle, maven, sbt .......
If you are just learning and not doing a full release to other users I would stick to Eclipse (or another IDE e.g. Intellij) which can also package for other users
MarkMark
You must log in to answer this question.
Not the answer you're looking for? Browse other questions tagged javadevelopmenttextwrangler .
![](/uploads/1/2/5/7/125719689/836437811.jpg)