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
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 don't like to post a question when so many suggestions pop up when I type the question title in but looking through them all and seeing no solution is somewhat distressing. I've been following a tutorial for java->postgres connections and I am constantly getting slaughtered by
"Could not find or load main class Seb"
error messages.
I've tried using
SET CLASSPATH=%CLASSPATH%:<path to work directory>;<path to jdbc jar>
compiling like so:-
javac -cp .:jdbc.jar Seb.java
and executing like so:-
java -cp .:jdbc.jar Seb
and can't see through the light -_-
The thing is, following the tutorial down to the letter (and watching the demonstration video) doesn't seem to work for me.
I'm simply using notepad and cmd.exe on Windows 8 for development as it's only a learning opportunity, not a big project - but I'm baffled as to why I can't get the thing to run!
JDBC postgres files are in the same directory as .java file.
Code is available if needed as is any other information I can provide.
Thanks in advance for any help,
-Tim!
Use a semi-colon classpath separator for Windows
java -cp .;jdbc.jar Seb
^
Read: PATH and CLASSPATH
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.
I have a java program that uses ProcessBuilder to call the unix sort command. When I run this code within my IDE (intelliJ) it only takes about a second to sort 500,000 lines. When I package it into an executable jar, and run that from the terminal it takes about 10 seconds. When I run the sort command myself from the terminal, it takes 20 seconds!
Why the vast difference in performance and any way I can get the jar to execute with the same performance? Environment is OSX 10.6.8 and java 1.6.0_26. The bottom of the sort man page says "sort 5.93 November 2004"
The command it is executing is:
sort -t' ' -k5,5f -k4,4f -k1,1n /path/to/imput/file -o /path/to/output/file
Note that when I run sort from the terminal I need to manually escape the tab delimiter and use the argument -t$'\t' instead of the actual tab (which I can pass to ProcessBuilder).
Looking as ps everything seems the same except when run from IDE the sort command has a TTY of ?? instead of ttys000--but from this question I don't think that should make a difference. Perhaps BASH is slowing me down? I am running out of ideas and want to close this 20x performance gap!
I'm going to venture two guesses:
perhaps you are invoking different versions of sort (do a which sort and use the full absolute path to recompare?)
perhaps you are using more complicated locale settings (leading to more complicated character set handling etc.)? Try
export LANG=C
sort -t' ' -k5,5f -k4,4f -k1,1n /input/file -o /output/file
to compare
Have a look at this project: http://code.google.com/p/externalsortinginjava/
Avoid the need of calling external sort entirely.