I implemented an application that can 'works' in GUI mode or in console mode. That means if the user ( in a windows console cmd) launchs the application without parameter\>myapplication.jar
the GUI start. If the user starts the application and gives some parameters, like\>myapplication.jar -src sourcefile, the gui isn't started but the prg interprets the arguments. Now my problem, if a run the application with the prefix \>java -jar myapplication.jar -somethings I see all system.out.println() in the console, it's fine. If I start the application \>myapplication.jar -somethings , all my system.out.println(..) aren't displayed ?? in the console. Why ?
Somebody has a solution to avoid to type each time the prefix >java -jar. I don't want to use a script like 'bash file' before. Thanks in advance, Alex
(some precisions, the system is windows 7 and I don't have the admin right on this pc)
java -jar ... tells the commandline to run java with the specified arguments in the open console. somejar.jar -arg tells windows to open somejar.jar with the given argument. but this will create a completely new process that does not use the console in which you typed the command. So 'somejar.jar' is printing, but not to a visible console.
Related
I would like to see some of the System.out and accept some inputs from it for testing my application on other computers which do not have Eclipse on them.
Normally, if you run the jar by double-clicking then the console output won't be shown.
However, you can launch the command line application (Terminal/CMD depending on your OS) then use the cd command to navigate to the directory of the jar file. Then type:
java -jar [app_name.jar]
This will run the application and show output within the console.
We have a Java application based on Eclipse (main class implements IApplication) that is started from the Windows command line. Its output on System.out is not visible/printed into the command window from which it is started. Nevertheless, when piping the output to more, the output is fine. How come?
For example, consider helloworld.exe. When running C:\>helloworld.exe in a command window, the application simply returns. But when running C:\>helloworld.exe | more, the screen shows
C:>helloworld.exe | more
hello world
C:>
On linux, the output is fine. How to see the output on Windows, too?
Some reqested information:
The application is quite large. And I probably cannot cut it down. The output are simple calls to System.out.prinln("xxx");
Java version 1.8.0_60, Eclipse 3.6.2
Using >std.txt 2>err.txt shows that output is indeed on stdout.
Line endings are CR/LF
the .ini file is as follows
--launcher.suppressErrors
-vmargs
-Xms256m
-Xmx4096m
-Djava.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory
-Djava.library.path=plugins
Maybe this issue is related?
If your application is somehow started via eclipse.exe (has no console attached to it) change the call to use the eclipsec.exe (has a console attached to it, note the c in the application name).
You can launch Eclipse RCP based applications using equinox launcher as shown below:
java -jar plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar
Of course you have to find the correct version of equinox launcher you are using in your RCP Application.
This way you would see the console logs.
You can read more about it here: http://wiki.eclipse.org/index.php/Starting_Eclipse_Commandline_With_Equinox_Launcher
EDIT: The reason you don't get console logs when eclipse.exe based launcher is used is because eclipse.exe on Windows spawns a separate process which brings up another command prompt window.
You'd better use a framework to handle your logs like logback
This is much more portable and maintainable.
In your example it seems that you have created an exe from your java code. My guess is that the packager you used to create the exe made some changes to the output target because it is a wrapper for your java program.
Try creating a jar instead and try executing it by java -jar helloworld.jar.
Is the string going to stderr in place of stdout? (or the other way around depending on your expected behaviour).
https://support.microsoft.com/en-us/kb/110930
I want to execute java application without displaying popup console. It because in 64bit applicaton, the GUI (console) will created in different session ID. I even use Java Service Wrapper, but the batch file still showing an popup console. So, how can I execute java application without displaying popup console? Or there any alternative way?
Running following command in command prompt, or through a batch file should help you:
start javaw -jar -Xms1024m -Xmx1024m <Your Jar File>
Refer to this thread for more.
I have a Java application that runs great :) While uploading files, it uses the standard output to show progress : "System.out.println(...);".
When I run it in Eclipse, well it works perfectly, but when I run the JAR file, I don't see any console/terminal showing up and printing what I print through "System.out.println(...),".
How can I open a new terminal when my application is launched (it is a Swing application)?
Basically I want to be able to run the Swing application and show information on the side in a terminal / console. Why? Don't worry about why I want to do this ;)
Thanks a lot!
Regards.
Open terminal and run application as java -cp yourjar.jar YouMain or java -jar yourjar.jar if you jar is runnable.
I believe that you do not see output because you are running your application using javaw - the special windows-only variation of JVM that does not have STDOUT at all. If you want to click your application and see output map *.jar file to be opened using java instead of javaw. Alternatively write bat file that runs your application. In this case you will see console.
Use java instead of javaw to launch your application. Double-clicking on a jar executes it with javaw. Instead, open a command line window and type
java -jar thePathOfTheJarFile.jar
If you want to have something double-clickable, then write a shell script containing this command, and double-click the shell script instead of the jar.
I have this java program that I want to package within a jar.
It compiles fine and it compiles without errors into a jar. But when I double click it, it wont start. I know most jar applications uses JFrame and that works fine. But is it possible to make it command prompt/shell based? (Like Displaying System.out.println)
Example is it possible to execute this code by double clicking a jar:
public class Hello
{
public static void main( String[] args )
{
System.out.println( "Hello, World!" );
}
}
There is no problem doing like that. But where do you expect to see the output?
If you execute from the console as java -jar my jar.jar you will see your "Hello, World".
If you want to double-click you'll need to create a JFrame.
You can change the file association for jar files to have them open a console.
(This is for Windows)
Open Command Processor
Type ftype jarfile
You will get something like:
jarfile="C:\Path\To\Java\bin\javaw.exe" -jar "%1 %*"
Enter ftype jarfile "C:\Path\To\Java\bin\java.exe" -jar "%1" %* (You may need administrator privileges to do this).
I don't see anyone mentioning the obvious solution: make a .cmd (or .bat) file containing the command everyone is talking about -- java -jar YourJar.jar. You can double-click on the .cmd file and a console window will open. It will also close imediately as your program exits, so the program should wait for a keypress before exiting.
You can make a jar an executable by including a manifest file which contains the name of the class that has your main method (in your example that would be Hello). Here is a link that details what you need to do.
Sure. First try to run your program as following:
java -cp yourjar.jar Main
where Main is a fully qualified class name of your main class.
When this is working fine and if you creted exacutable jar try to run your program as following:
java -jar yourjar.jar
When this is working double click should work too unless you mapped extension jar to program other than javaw that is done by default when you are installing JRE.
If you want to display the "Hello, world!" String you have to execute your code from the command line:
jar -jar your_jar_name.jar
The output gets forwarded to the console but without eclipse, there isn't any! The only way to work around this is to launch the program in command prompt and then you will get the output from the program.