## Problem trying to start a runnable jar from a C++ application

executable jar file not running on double clicking windows 10
no main manifest attribute
unable to access jarfile
eclipse export runnable jar not working
how to export runnable jar file in eclipse
how to open jar files
eclipse export runnable jar with resources
run jar file

I need to develop a .exe file that will launch a runnable .jar file which is stored on a subfolder called core. I built the C++ .exe application with sublime text and mingw and it's working fine but there is a small problem that I need to solve. When you execute the .exe file, during a minimum portion of time you can see a black window on screen which is disappearing in some milliseconds and after it the Java .jar application opens. This only happens if I use this .exe. If I double click in the runnable jar the black window doesn't appear.

How can I avoid that black window which dissapears in some milliseconds?

This is the code:

#include <windows.h>

int main()
{
ShellExecute(0, "open", "core.jar", NULL, "core", SW_SHOW);
return 0;
}


I tried also with this code and same result:

ShellExecute(0, "open", "cmd.exe", "/C .\\core\\core.jar", 0, SW_HIDE);


I'm aware there are other similar questions but none of them works for this problem and none of them seems to be applicable to Sublime and gcc.

The problem isn't your call to ShellExecute. Your code is for a console application. Console applications, as one might guess, run in a console (that black window; same as you'd get if you ran cmd.exe).

You can just replace main with WinMain, and simply call ShellExecute in there to launch the jar, and there should be no resulting console window (assuming the jar itself isn't creating one).

See 14 B for how to make a 'windows' app with MingW.

More Java Pitfalls: 50 New Time-Saving Solutions and Workarounds, 50 New Time-Saving Solutions and Workarounds Michael C. Daconta, Kevin T. I have seen numerous developers have problems with executable JAR files. So since these developers still haven't learned the underlying problem, they try  Hello! I am having a problem. So I need to make my program a runnable .jar file. The problem is my SQLite database path.

Use CreateProcess() or ShellExecuteEx() which will return you handle to the created process, and with that handle you can kill the process. Here is an example showing how this works including error handeling.

#include <windows.h>
#include <string>
#include <iostream>

void DisplayError(LPCTSTR errorDesc, DWORD errorCode)
{
TCHAR errorMessage[1024] = TEXT("");

DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS

FormatMessage(flags,
NULL,
errorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errorMessage,
sizeof(errorMessage) / sizeof(TCHAR),
NULL);

std::cerr << "Error : " << errorDesc << "\n";
std::cerr << "Code    = " << errorCode << "\n";
std::cerr << "Message = " << errorMessage << "\n";
}

int main()
{
STARTUPINFO info = { sizeof(info) };
PROCESS_INFORMATION processInfo;
ZeroMemory(&info, sizeof(info));
info.cb = sizeof(info);
ZeroMemory(&processInfo, sizeof(processInfo));

std::string path = "D:\\Java\\jdk1.6.0_26\\bin\\java.exe";
std::string cmdArgs = "java.exe -jar D:\\temp\\sample.jar";

// Start the child process.
if (CreateProcess(path.c_str(), const_cast<char *>(cmdArgs.c_str()), NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
{
// Wait until child process exits.
WaitForSingleObject(processInfo.hProcess, INFINITE);
// Close process and thread handles.
CloseHandle(processInfo.hProcess);
}
else
{
DWORD errorCode = GetLastError();
DisplayError(TEXT("Unable to execute."), errorCode);
}

//system("pause");
}


Export Eclipse Java Project as Runnable JAR, This tutorial explains how to create a runnable JAR file from an existing Selenium Eclipse project (Java). This will run your Selenium script: start a web browser, navigate to java -jar C:\Tests\AlertSiteSeleniumExample.jar. Most times, a JAR application is an executable JAR. An executable JAR can have a maximum of one main class defined in the manifest file . Consequently, other applications in the same executable JAR file can't be set in the manifest file, but we can still run them from the command line just like we would for a non-executable JAR.

Finally I discovered that is enough with adding -mwindows to the gcc compile command:

gcc -o launcher launcher.cpp -mwindows


Core Java Professional :: Advanced Features (Core Series) Updated , C Change directories during command execution. f First element of the file list is the update of the jar file. c:\javaprg>jar –uf Myjar.jar pack1 Creating an executable JAR Execute a jar file: c:\javaprg>java –jar Myjar.jar Theory question's: 1. java -jar Rock_Paper_Scissors.jar in the cmd it works why it does not run when i double click on the file itself. Can you post the code that you are compiling, putting in the jar and executing? Does the program use the console? That will be a problem when starting the jarfile with a double click.

Java :: Complete Reference for the Really Impatient., C Change directories during command execution. f First element of the file list is the of the jar file. c:\javaprg>jar –uf Myjar.jar pack1 Creating an executable JAR file: Execute a jar file: c:\javaprg>java –jar Myjar.jar Theory question's: 1. Remember the path to jdk\bin\jar will be similar on your computer but almost definitely not exactly the same as mine. What if you want to compile all .class files in the folder into the jar? No problem, instead of the last line up above, type: C:\> C:\Path\to\jdk\bin\jar cvfm jarDemoCompiled.jar manifest.txt *.class

How to Run .JAR Files on Windows 10, What happens for most people is that when trying to open a .jar file, Windows but this has the problem of stripping –jar from the program's execution path. ftype jarfileterm=cmd /s /k “”C:\Program Files\Java\jre7\bin\java.exe” -jar “%1″ %*” steps above you took, the java executable should either launch or launch with a  I have a java executable jar file, which I am trying to run in a terminal. I need to auto run the project so that the jar file runs whenever I start the PC like a system service.

Unable to run .jar files by double-clicking them on Windows 7 , I tried all above steps to resolve the problem but nothing worked. I had installed "C:\Program Files\Java\jdk-11.0.1\bin\javaw.exe" -jar "%1" %*. I changed it to, If you're using Win XP (and maybe some earlier versions), try this: Start -> My Computer -> Tools -> Folder Options -> File Types. There will be a list of extensions, so go to JAR. If it opens with javaw, click Change and select "Java(TM) 2 Platform Standard Edition binary", and all should be well. I had the same problem, but this fixed it.