Skip to content

Commit dd61495

Browse files
author
Yann Diorcet
committed
Support constant command line arguments and arguments in JNI mode
1 parent 35c4053 commit dd61495

File tree

8 files changed

+28
-22
lines changed

8 files changed

+28
-22
lines changed

head_src/consolehead/consolehead.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int main(int argc, char* argv[])
5555
cmdLine = "";
5656
}
5757

58-
int result = prepare(cmdLine);
58+
int result = prepare(cmdLine, FALSE);
5959

6060
if (result == ERROR_ALREADY_EXISTS)
6161
{

head_src/guihead/guihead.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,
4949
LPSTR lpCmdLine,
5050
int nCmdShow)
5151
{
52-
int result = prepare(lpCmdLine);
52+
int result = prepare(lpCmdLine, FALSE);
5353

5454
if (result == ERROR_ALREADY_EXISTS)
5555
{

head_src/head.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ void setEnvironmentVariables(const char *exePath, const int pathLen)
11111111
}
11121112
}
11131113

1114-
void setMainClassAndClassPath(const char *exePath, const int pathLen)
1114+
void setMainClassAndClassPath(const char *exePath, const int pathLen, BOOL jni)
11151115
{
11161116
char classPath[MAX_ARGS] = {0};
11171117
char expandedClassPath[MAX_ARGS] = {0};
@@ -1179,7 +1179,9 @@ void setMainClassAndClassPath(const char *exePath, const int pathLen)
11791179

11801180
*(launcher.args + strlen(launcher.args) - 1) = 0;
11811181
strcat(launcher.args, "\" ");
1182-
strcat(launcher.args, launcher.mainClass);
1182+
if (!jni) {
1183+
strcat(launcher.args, launcher.mainClass);
1184+
}
11831185
}
11841186
else if (wrapper)
11851187
{
@@ -1194,17 +1196,18 @@ void setMainClassAndClassPath(const char *exePath, const int pathLen)
11941196
appendPath(launcher.args, jar);
11951197
strcat(launcher.args, "\"");
11961198
}
1199+
11971200
}
11981201

1199-
void setCommandLineArgs(const char *lpCmdLine)
1202+
void setCommandLineArgs(const char *lpCmdLine, BOOL jni)
12001203
{
1204+
const char *target = jni? launcher.mainClass: launcher.args;
12011205
char tmp[MAX_ARGS] = {0};
1202-
12031206
// Constant command line arguments
12041207
if (loadString(CMD_LINE, tmp))
12051208
{
1206-
strcat(launcher.args, " ");
1207-
strcat(launcher.args, tmp);
1209+
strcat(target, " ");
1210+
strcat(target, tmp);
12081211
}
12091212

12101213
// Command line arguments
@@ -1226,13 +1229,13 @@ void setCommandLineArgs(const char *lpCmdLine)
12261229
}
12271230
if (*tmp)
12281231
{
1229-
strcat(launcher.args, " ");
1230-
strcat(launcher.args, tmp);
1232+
strcat(target, " ");
1233+
strcat(target, tmp);
12311234
}
12321235
}
12331236
}
12341237

1235-
int prepare(const char *lpCmdLine)
1238+
int prepare(const char *lpCmdLine, BOOL jni)
12361239
{
12371240
if (!initGlobals())
12381241
{
@@ -1272,7 +1275,6 @@ int prepare(const char *lpCmdLine)
12721275
}
12731276

12741277
setWorkingDirectory(exePath, pathLen);
1275-
12761278
if (!jreSearch(exePath, pathLen))
12771279
{
12781280
return FALSE;
@@ -1282,7 +1284,6 @@ int prepare(const char *lpCmdLine)
12821284
{
12831285
return FALSE;
12841286
}
1285-
12861287
setEnvironmentVariables(exePath, pathLen);
12871288
processPriority = loadInt(PRIORITY_CLASS);
12881289
appendLauncher(launcher.cmd);
@@ -1291,8 +1292,8 @@ int prepare(const char *lpCmdLine)
12911292
char jvmOptions[MAX_ARGS] = {0};
12921293
setJvmOptions(jvmOptions, exePath);
12931294
expandVars(launcher.args, jvmOptions, exePath, pathLen);
1294-
setMainClassAndClassPath(exePath, pathLen);
1295-
setCommandLineArgs(lpCmdLine);
1295+
setMainClassAndClassPath(exePath, pathLen, jni);
1296+
setCommandLineArgs(lpCmdLine, jni);
12961297

12971298
debug("Launcher:\t%s\n", launcher.cmd);
12981299
debug("Launcher args:\t%s\n", launcher.args);

head_src/head.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ BOOL jreSearch(const char *exePath, const int pathLen);
134134
BOOL appendToPathVar(const char* path);
135135
BOOL appendJreBinToPathVar();
136136
void setEnvironmentVariables(const char *exePath, const int pathLen);
137-
void setMainClassAndClassPath(const char *exePath, const int pathLen);
138-
void setCommandLineArgs(const char *lpCmdLine);
139-
int prepare(const char *lpCmdLine);
137+
void setMainClassAndClassPath(const char *exePath, const int pathLen, BOOL jni);
138+
void setCommandLineArgs(const char *lpCmdLine, BOOL jni);
139+
int prepare(const char *lpCmdLine, BOOL jni);
140140
void closeProcessHandles();
141141
BOOL execute(const BOOL wait, DWORD *dwExitCode);
142142
const char* getJavaHome();

head_src/jniconsolehead_BETA/jniconsolehead.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int main(int argc, char* argv[])
5656
cmdLine = "";
5757
}
5858

59-
int result = prepare(cmdLine);
59+
int result = prepare(cmdLine, TRUE);
6060

6161
if (result == ERROR_ALREADY_EXISTS)
6262
{

head_src/jniguihead_BETA/jniguihead.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,
5050
LPSTR lpCmdLine,
5151
int nCmdShow)
5252
{
53-
int result = prepare(lpCmdLine);
53+
int result = prepare(lpCmdLine, TRUE);
5454

5555
if (result == ERROR_ALREADY_EXISTS)
5656
{

head_src/jnihead.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ void saveJvmOptions(const char *jrePath, const char *mainClass, const char *pcOp
6161
strcpy(g_rgcCurrJrePth, jrePath);
6262
strcpy(g_rgcMnCls, mainClass);
6363

64+
/* Extract main class from arguments */
65+
char *delim = strpbrk(g_rgcMnCls, g_pcSep);
66+
if (delim != NULL) {
67+
*delim = '\0';
68+
strcpy(g_rgcMnClsArgs, delim + 1);
69+
}
70+
6471
char rgcOptCpy[MAX_ARGS] = {0};
6572
int iArgCnt = 0, iCurrArg = 0, iSkipArgCnt = 0;
6673
char *pcCurrOpt;

src/net/sf/launch4j/config/Config.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ private void checkJniInvariants() {
160160
if (isJniApplication()) {
161161
Validator.checkTrue(".".equals(chdir), "chdir",
162162
"Only '.' is allowed in change directory.");
163-
Validator.checkTrue(Validator.isEmpty(cmdLine), "cmdLine",
164-
"Constant command line arguments not supported.");
165163
Validator.checkFalse(stayAlive, "stayAlive",
166164
"Stay alive option is not used in JNI, this is the default behavior.");
167165
Validator.checkFalse(restartOnCrash, "restartOnCrash",

0 commit comments

Comments
 (0)