C ++:从.jar文件创建.exe文件或创建.jar启动器 - .exe文件

时间:2014-03-20 19:49:01

标签: java c++ jar exe

它想知道如何创建 - 我的意思是C ++示例 - .exe文件中的.exe文件? 不想使用Launch4j或类似的。只是想从头开始。

2 个答案:

答案 0 :(得分:1)

所以答案是here。它看起来像:

#include <iostream>

#include <fstream>

#include <windows.h>


using namespace std;

string getAppName() {

    // Creates char array with maximum needed length
    char result[MAX_PATH];
    // Uses <windows.h> method to retrieve app name. Only Windows OS
    std::string(result, GetModuleFileName(NULL, result, MAX_PATH));

    char* token;
    string name, next = "";

    //Iterates until end of tokens of Name string, divided by char -> '\' and '.'
    //The only '.' in Filename must be that for ".exe" , error otherwise.
    token = strtok(result, "\\.");
    while (next != "exe") {
        name = next;
        token = strtok(NULL, "\\.");
        next.assign(token);
    }
    return name;
}

int main(int argc, char** argv) {

    ifstream file; // file stream
    string value = "";
    string jar_name = "";
    string image_name = "splash.gif";
    file.open("run.ini");
    if (!file) { // file does not exist, so use standard name
        jar_name = getAppName();
        jar_name += ".jar";
    } else {
        do {
            file >> jar_name;
            file >> image_name;
        } while (!file.eof());
        file.close();
    }

    //Launch JAVAW command on "jar_name" file with "image_name" splash image
    string exec_command = "start javaw -splash:" + image_name + " -jar " + jar_name;
    system(exec_command.c_str());

    return 0;
}

答案 1 :(得分:0)

的#include void main(void) { system(&#34; Java&lt; Filename&gt;&#34;);

另存为呼叫中心 properties:compile-&gt; make as .exe 从tc / bin

获取exe文件