IntelliJ Idea, how to remove java file directory from Console? - java

When you run a file, it opens the console window and all the way on top it has the directory of where the file is. This is pretty irritating because now, to separate other lines from mixing with the directory, I have to use "\n" on before any System.out.println() commands can be initiated.
"C:\Program FIles..." I want to get rid of that.

There is presently no way to disable this.
It does show useful information which shows which jvm is being used and which parameters are used to configure it, so it does "annotate" your program log to some extent. You'll also get a line stating the exit code when your program terminates.
There is an option to be able to write the console log to a file, I'm not sure if it shows the jvm version and exit code or not, perhaps you can try it and see if it is be useful to you.

Maybe try Settings->Editor->General->Console, in the "Fold console lines that contain:", add a substring of the line you want folded e.g. "C:\Program Files

Related

Need help converting this IntelliJ run configuration to a command line one

I've got this working run configuration in IntelliJ which I want to convert tro a command line one. Been trying few things but it can't seem to locate my class file.
Can someone suggest the correct command to run please?
Many thanks
The easiest way is to run this configuration from within IDEA, open the "Run" tool window and copy the command from there.
Note that IDEA adds some specific settings and you'll have to remove them, like removing idea_rt.jar from classpath, etc.

What happens to "System.out.println()" in executable jar?

Suppose I've created an executable jar from a code where I have used
System.out.println()
When we run the executable jar, there is no console. So, what happens to this line? How does java handle this situation?
EDIT 01:
NOTE: The situation is when I don't use a console to run the jar nor associate any console with it anyhow.
EDIT 02: Making things clearer:
I know that nothing will be printed anywhere as there is no console..! I want to know how java handle this line in this case? Is this line omitted when generating the bytecode for a executable jar? Or is this line just overlooked when there is no console? Or anything...
There's nothing special about running code in an executable jar file. If you run it from a console, e.g. with java -jar foo.jar the output will still go to the console.
If you run the code in some way that doesn't attach a console - such as javaw on Windows, which is the default program associated with executable jar files - then the output won't go anywhere. It won't cause any errors - the text will just be lost.
Note that in that case, if you use System.console() instead, that will return null. So:
System.out.printf("Foo%n"); // No problem. Goes nowhere.
System.console().printf("Foo%n"); // Would throw a NullPointerException.
The output is omitted, as long as you do not run your application from a console window (java -jar executable.jar). Furthermore, you can configure your Java installation such, that a console windows is launched as soon as you start a Java application. Output will be written to the JVM's console window then. You can find an article How do I enable and view the Java Console? on the official Java web site.
I you open it from the console (java -jar YourJar.jar) the text gets printed in your console window.
If you open it in the explorer (or similar), you won't see the text
To clarify your second Edit:
The bytecode is not omitted, because the compiler cannot know in what context the jar will be executed. The jar can always be called from console, in that case the println has to stay there.
In fact, many jar Files would be completely useless otherwise. There are plenty of Java programs that interact with the user by console in- and output.
It is not neccessary for a java-Program to have a GUI (or to run completely in the background).

Launch4J executable not executing as expected

Tools: Win 7, Launch4J 3.5, Simple Hello world Java console app (bundled in a JAR file)
Hello all,
I have a basic JAVA console application that doesn't request any inputs, just a simple application that opens a console window and displays Hello World text.
I built it so simple so I can experiment with Launch4J 3.5 and build an executable file from the jar file.
Everything looks fine, the exe builds successfully but when I launch it nothing happens, I get the hour glass for a few seconds then nothing. I check the Task Manager and there's no process stuck in there.
See my settings in Launch4J, I only filled in the basics, I tried with and without an entry in the Wrapper manifest field:
Output file: C:\Development\SFDC\ProjectX\out\exe\ProjectX.exe
Jar: C:\Development\SFDC\ProjectX\out\artifacts\ProjectX_jar\ProjectX.jar
Wrapper manifest: C:\Launch4j\manifest\uac.exe.manifest (also tried with leaving this blank)
The rest is all left as default.
If by launching you mean double clicking it, no - nothing you can see will happen; you have to 'tell' Java to run your application with an associated console. To do this, you may create a new .bat file: Simply open a text editor and insert the following line:
java -jar NAME.jar
where "NAME" is the name of your application. Save the text file in .bat format, not in .txt, and place it in the same directory as your application. You can launch your application by double-clicking that file.
The reason it does not pop up in your task manager is because probably (I cannot know) your application only prints out a simple message and does nothing more. In non-console mode, it will just call your print (println or any other console) method without having any visual effect as there is no console to print the message to. In both cases however, if you only print something and do not perform other operations that 'last', such as listening for input, your programm will terminate as it has reached the end of the main method.
Yes. You do need to use the console mode.
You also do need to have some method of keeping the console window open, because it closes the console the moment the program terminates. Use scan.nextLine(); or Thread.sleep(i) if you really need to.
Possibly you need to use launch4j in console mode, see this answer: lauch4j hello world program

My JAR file only executes on a double-click by opening a black window with one line but disappears before it is readable

When I created the program using JCreator on computer A, I can execute the program by double-clicking on the jar file, however when I brought the exact folder holding the jar file to a different computer without JCreator but with Java installed, a black screen that looked like command prompt appeared with one line of text instead of the opening JFrame. However, before I can read the line the command prompt looking screen disappears and ends the program. Can someone explain what is happening and how to fix this?
The jar is throwing an Exception before it can show any windows or take any action. To see the Exception it's throwing, run the jar via the command prompt instead of double-clicking it.
More info here: http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html
Most likely you have a problem with the classpath of the jar looking for a resource that was being provided by JCreator but it can't find it, now that the directory has been moved. Use java -jar {jarfileName} to execute your jar file at the cmd prompt. You should then be able to see what is missing.
Hope this helps.

Java Console In Eclipse, But What If Using As Jar?

So,
I have made a little game in eclipse, it generates a rondom number from 1 - 1000 , when playing out of Eclipse, it plays in the eclipse console, but what if i want to play it without eclipse?
There is no console showing up?
Anyone a idea on how to fix this?
EDIT : I would like a new GUI instead of CMD.
Grts
PS: Tell me if you need a specific part of the source code
1) You should probably export your program as a .jar file.
This isn't absolutely necessary - but it's better. And it sounds like you've already done it :)
2) Be sure to specify the main class in Eclipse before you export the .jar
3) Once you have the .jar, you can:
a) execute "java -jar myjar.jar" from a command prompt (for a console-mode program)
b) execute "javaw2 -jar myjar.jar" from a command prompt (for a Swing/GUI program)
4) You can also set a "file association" with javaw in Windows so that you can just double-click on the .jar to execute it:
Running JAR file on Windows
It seems the OP wants to reroute console output to a location of his choosing, not open an actual shell.
Here is one way to reroute stdout.
You can send it to a string, stream, file, etc. and then print it yourself into a window.
If you want a GUI, you will have to develop one yourself. There is no "Java Console GUI" that I've ever heard of.

Categories