I have created a java program which has been compiled into a jar file.
Now to make it exe, I have a C++ script that launches the jar file.
It launches fine, but the black cmd screen (or C++'s default console window) stays open until the java program is closed.
Is there anyway for me to make it so the black output window doesn't open at all?
(I am using Code::Blocks IDE)
I ran into this problem once... if you are using Swing, try to run with "javaw", not "java", that worked for me.
Related
I'm building a Java tutorial where there is a button when clicked, opens a notepad application which I built. However how do I go about opening the notepad application in the ActionListener? Should I use ProcessBuilder?
If your separate program is a compiled .jar file, use the following code to launch it, but note you will not have any control over it.
Runtime.getRuntime().exec("java -jar 'path/to/file.jar'");
Note this method returns a Process object, which you can then modify to your individual needs.
I created a program that is console based, but the problem I have is when (Through eclipse) I turn it into a runnable .jar file and run it, nothing happens. I believe this is because it is printing to the console but the .jar has no idea how it's supposed to show that. So my question is is there a way to redirect the console to a new window? I have seen similar questions but none of the methods seem to work. I cannot use the console because I plan on giving this to extended family that has no idea how to use it from the command prompt, and are not computer savvy
Thanks!
Assuming you're using Windows, try running the jar from a console window thats already open:
java -jar myJar.jar
This will display the output in your existing console window.
You're not seeing anything when running the jar from the explorer because it finishes too fast and closes it's window upon completion before you can properly see it.
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
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.
I need to run an external JAR file (which is minecraft) within the window (form) of a VB.NET application, so like having the program in the center and additional text I like around it.
Is this possible, and if so, how?
With shell() command and java.exe -jar yourJarPath/file.jar It should works, if my memory of VB is good.