Whenever a compilation results in an error output longer then one screen, I have to scroll back to see the first error (possibly a cause of the later ones) and fix it. This is especially a pain in Screen, where I first have to press ctrl+a Esc to scroll.
Is there a command line switch in javac that lets the error messages be displayed in reverse order, or is there some generic command line magic I can achieve the same effect with?
Update: Just to clarify, I always use the command line for compilation, an IDE is not an option.
If you want to stop on the first compilation error, then you should probably use -Xmaxerrs 1. You can fix that error and compile again.
Edit
If you are under *nix environment, redirecting stderr to stdout will make most of the tools like head, more, less work. Compilation errors are printed to stderr.
javac File.java 2>&1 | less
Edit2
You could also send it to a file using -Xstdout filename
Pipe the output to more on command-line or better use an IDE like Eclipse.
javac file.java | more
Now press space bar to let the output scroll (or enter for line by line) if it's more than one screen page.
Related
I'm calling vim/gvim from within a Java program to convert a source code containing file into html, as follows: "gvim -c \"set syntax=java\" -c \"TOhtml\" -c \"wq\" -c \"q\" -c \"q\" " + Konst.FPATH + "tmp.txt"
However, for some reason gvim thinks "syntax=java" is a name of a file, and ends up spitting out tons of messages ".syntax=java.swp" found, and more importantly does not apply syntax highlight after all. How to fix this?
EDIT: For some reason, "set syntax=java" is misinterpreted, and gvim opens a file syntax=java" -- exactly this, with a double-quote at the end.
Executing an external program from Java is generally not a good idea, especially if this code run on a web server. It might lead to serious security issues.
What are you trying to do? If your goal is to highlight some Java code, just use a code highlighting library.
I don't know any Java highlighting library, but you can find some good Javascript libs (highlightjs, prismjs, code-prettify, etc.).
I solved this with "gvim -s script.vim" command, where in script.vim I put (!) ":set syntax=java" etc -- yes, starting with ":".
I have a program which throws StackOverflowException. So the error output is very big and I can't read beginning of output from terminal. How can I watch all program output?
I know that there is something like pagination in terminal. I've googled about it and found advice to use more or less commands.
So I've tried...
java Program | less
But it doesn't work. What am I doing wrong?
Assuming you are using bash4 you can use the |& to concat std error.
java Program |& less
You can redirect the output to a file
java myProgram &>file.log
Then you can tail , head or grep that file.
Use a good IDE (Integrated Development Environment) such as Eclipse. Any decent IDE will have a debugger mode.
Java is a both compiled and interpreted language, which gives it speed and is also easy to debug.
IDE debuggers will walk you through the program execution step by step, which can help you to find errors in your program that you might not otherwise see.
I am a student of computer science. I am learning java on linux platform ubuntu. While I am compiling a program always I get some compilation error in terminal. I tried to read the error message from terminal. I think reading these error message gives me better understanding about the program/java language itself. So when I recover the error sometimes I would try to read the earlier error message, but the message sometimes removed from the terminal.
So my question is - is there any way to redirecting the error message from terminal to directly to a file.
I am using the fllowing command in ubuntu to compile -
$javac MyClass.java > file_name
But it prints all the line from the terminal to the 'file_name'. Is there any way to redirect only the error message?
Thanks.
You need
$javac MyClass.java 2> file_name
which will redirect stderr. You can (instead) redirect stderr to to stdout and then to a file thus:
$javac MyClass.java 2>&1 > file_name
The above assumes you're using a Bourne-shell type shell (sh/bash/ksh/zsh), as opposed to a C-shell variant.
Having said all that, I would (if at all practical) avoid using the command line for general development in favour of an IDE, which (amongst many other advantages) will tell you a lot more info re. your compilation issues.
Is it possible to execute a Java program in the background so the user can execute other commands in front of it?
For instance, here is how the console might look for said program:
$ myProgram (executes program)
Program Started! (output from myProgram)
$ (the user can enter another UNIX command while myProgram is still running)
Thanks in advance!
Background execution is part of the shell. You can add & at the end of the command line to run it in the background.
The background output does not go to the current shell. If that happened, it would be confusing to the user, having to type input while the terminal is still producing output.
EDIT: I just tried "ls &" on cygwin, and the ls output appears in the console. Seems there is a lot of conflicting information on the net! :)
Best way is to use screen if you dont have it type
sudo apt-get install screen
type
screen
run the command like
java MyClass
press ctrl + (a + d)
to view this window again, type screen -x
I beleive it's possible to start the program and allow access to the shell... but the user would not see the output.
I do not think its possible to achieve the example scenario you have given.
Noob question, apologies. I'm compiling Java in Windows Vista's command-line and have so many syntax errors that some are being pushed off the top (a lot of 'class, interface or enum expected' errors which leads me to believe it's an obvious syntax mistake early on in the code that I can't spot). Does anyone know how I could get it to display those first errors?
Thanks in advance for the help.
You have several options:
route stdout and stderr to a file:
javac [whatever] > file.out 2>&1
use an IDE
increase the 'height' of your command console's buffer in "Properties/Layout/Screen Buffer Size" - I routinely set this setting to 6000 so I can scroll back a long ways...
Try increasing the buffer size for your command-prompt. Read more here:
http://www.cs.princeton.edu/introcs/15inout/windows-cmd.html
you can
1 - as Matt says Use an IDE, will make your life much easier. there are plenty of good ones.
2 - as Ben said you can increase the buffer but even if you do so you still run the chance of loosing some messages.
3 - you can pipe the output through more ex :
javac SomeClass.java | more
However this will make your compiling much longer as it will wait for you to scroll pages
4 - redirect the messages to a file ex :
javac SomeClass.java > compileLog.txt 2>&1
More on redirection for CMD here. This way you can view the messages without worrying that you missed any or without being constrained to the command line window. Search through them etc.
Use an IDE so you 1) don't have to scroll for pages to find errors 2) can jump straight to the line with the error.
Redirect your ouput for the command's errors to a text file and open it on notepad
ex: suppoing Test.java is your program
> javac Test.java 2>errs.txt
> notepad errs.txt