Run eclipse project in cmd [duplicate] - java

This question already has answers here:
Eclipse open console apps in separate window
(4 answers)
Closed 7 years ago.
I have a console project in Eclipse.
I want to configure Eclipse to open a Windows Command Prompt window instead of its own console. The cmd window must run the project and do all input and output instead of the Eclipse console window.
This is very easy in C#.
How do I do this?

If this is a console-based application, then merely opening the executable JAR file should make it run in a Command Prompt. This can be done by typing
java -jar "<drive>:\path\to\JAR.jar"
into a CMD window. The program will now run as if it were in the Eclipse console, except in CMD. Using a batch file, you can alter the CMD with
COLOR 0A
as an example.
If you are looking for more of a user-friendly console-based application, you can get the name of the executable JAR and have it run in a ProcessBuilder inside the source code itself. This allows the JAR to open up itself in a CMD.
If I have not specified correctly, do let me know.

Related

How to make JAR file with Java instead of Javaw using Netbeans IDE

I have made JAR file using Netbeans IDE's clean & build option. When I'm double clicking that Jar file, programs runs with javaw which is not showing me output in console i.e in command window
I want to make Jar file with Java.exe instead of jawaw using netbeans, which will run on double click or with windows task scheduler and display me output in command prompt. Please help me for this issue.
On double click it will run with javaw by default. Better way to do so is make the Jar file and then convert it to .exe file with Launch4J with below settings,
In Basic tab - Specify Output.exe filename.
In Basic tab - Set the jar file location.
In JRE tab specify the minimum JRE version.
In Header tab - Change Header type to console instead of GUI.
And build the wrapper.
4th step will sort your problem, Which will run program in console(command prompt) on running .exe file either on double click or running from Windows Task scheduler.
The jar file built has nothing to do with java or javaw when you double click it. Your machine is set to use javaw when running a jar.
To use java just run it from a command line:
java -jar myjar.jar
To run it via command line, you could always make a batch script to launch the jar.

executable jar file doesn't run on window 10

so it was created from eclipse. Double click didn't work, a .bat file didn't work (it open cmd and close it immediately), i have updated java RE but nothing change. The only way to run it is to move it to C:\Users\user and open cmd and type java -jar xla.jar. I don't want to change any setting of the computer since i have to send it to my friend (this is a group project). Btw i'm on the new Fall Creator Window version.
try
java -cp xla.jar com.package.name.Classname
if you have main method on a specific class.. using a batch file and then run it .. if you cannot run it by double clicking just google and create a exe to run your batch file.

Load desktop application on Windows startup [duplicate]

This question already has answers here:
Run Java application at Windows startup
(8 answers)
Closed 6 years ago.
I have Java desktop application, which runs fine. I can double click on exe or run jar file and runs properly.
I want to load this application whenever system starts. How can I achieve this programmatically?
Or is there any tool available to create exe in such a manner, that once we install it creates shortcut in system startup folder.
I want it be system or code driven rather than individually placing exe in startup folder.
You can set up the exe as a windows service with these steps:
open command prompt as administrator
type this:
sc.exe create <service_name> binPath= "<path to your exe> --service" DisplayName= "<somename>" start= "auto"

Java - System.out.println() viewable from application?

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.

Error Running batch file from Windows desktop to execute a Java program in eclipse workspace

I have a Java standalone project in Eclipse with about 10 packages. I have a main method(in eclipse) that when executed from Eclipse works fine.
I have written a batch file to run it from the desktop. I just click the batch file and hope to run the program.
My code for the batch file is as follows.
RunExecuteMyProg.bat
echo Output of the Program
echo ---------------------
java C:\eclipse_workspace\eclipse\myprogram\MainProgram\ExecuteMainProgram
echo "Program Executed"
This program when run in Eclipse, usually takes between 1 -4 min depending on a number of factors. But when I click the .bat file, it opens for a fraction of a second and closes. Java is on my classpath. At command prompt when I try to compile, I get compile errors saying that some class is not found. However on eclipse it just runs fine. Log files need to get created when this program runs, but nothing happens from batch file.
PS: The class files are created in the same folder as the source files.
You will know the problem if you open a command prompt and enter that command you have there:
java C:\eclipse_workspace\eclipse\myprogram\MainProgram\ExecuteMainProgram
It could be that you don't have java in the path or your program is written so that it has to have its current working directory where the program is located, etc etc.
Or any number of things. Get the output from executing that command manually in a command prompt.

Categories

Resources