Skip to content

Commit aa9ff0d

Browse files
author
gk_brown
committed
Rollback JVMClassPath changes.
git-svn-id: https://svn.java.net/svn/appbundler~svn@9 07572b26-92e5-4d45-f66a-c18421440a21
1 parent 00d1402 commit aa9ff0d

File tree

2 files changed

+32
-46
lines changed

2 files changed

+32
-46
lines changed

appbundler/native/main.m

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
#define JVM_RUNTIME_KEY "JVMRuntime"
3434
#define JVM_MAIN_CLASS_NAME_KEY "JVMMainClassName"
35-
#define JVM_CLASS_PATH_KEY "JVMClassPath"
3635
#define JVM_OPTIONS_KEY "JVMOptions"
3736
#define JVM_ARGUMENTS_KEY "JVMArguments"
3837

@@ -120,23 +119,21 @@ int launch(char *commandName) {
120119
}
121120

122121
// Set the class path
123-
NSMutableString *classPath = [NSMutableString stringWithString:@"-Djava.class.path="];
124-
NSArray *classPathEntries = [infoDictionary objectForKey:@JVM_CLASS_PATH_KEY];
125-
if (classPathEntries == nil || [classPathEntries count] == 0) {
126-
[NSException raise:@JAVA_LAUNCH_ERROR format:@"%@ is required.", @JVM_CLASS_PATH_KEY];
122+
NSString *javaPath = [mainBundlePath stringByAppendingString:@"/Contents/Java"];
123+
NSMutableString *classPath = [NSMutableString stringWithFormat:@"-Djava.class.path=%@/Classes", javaPath];
124+
125+
NSFileManager *defaultFileManager = [NSFileManager defaultManager];
126+
NSArray *javaDirectoryContents = [defaultFileManager contentsOfDirectoryAtPath:javaPath error:nil];
127+
if (javaDirectoryContents == nil) {
128+
[NSException raise:@JAVA_LAUNCH_ERROR format:@"Could not enumerate Java directory contents."];
127129
}
128130

129-
for (int i = 0, n = [classPathEntries count]; i < n; i++) {
130-
NSString *classPathEntry = [classPathEntries objectAtIndex:i];
131-
if (i > 0) {
132-
[classPath appendString:@":"];
131+
for (NSString *file in javaDirectoryContents) {
132+
if ([file hasSuffix:@".jar"]) {
133+
[classPath appendFormat:@":%@/%@", javaPath, file];
133134
}
134-
135-
[classPath appendFormat:@"%@/%@", mainBundlePath, classPathEntry];
136135
}
137136

138-
NSLog(@"classPath = %@", classPath);
139-
140137
// Set the library path
141138
NSString *libraryPath = [NSString stringWithFormat:@"-Djava.library.path=%@/Contents/MacOS", mainBundlePath];
142139

appbundler/src/com/oracle/appbundler/AppBundlerTask.java

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,7 @@ public void addConfiguredClassPath(FileSet classPath) {
139139
String[] includedFiles = directoryScanner.getIncludedFiles();
140140

141141
for (int i = 0; i < includedFiles.length; i++) {
142-
File entry = new File(parent, includedFiles[i]);
143-
if (entry.isDirectory()) {
144-
throw new BuildException("Class path entry cannot be a directory.");
145-
}
146-
147-
this.classPath.add(entry);
142+
this.classPath.add(new File(parent, includedFiles[i]));
148143
}
149144
}
150145

@@ -264,12 +259,25 @@ public void execute() throws BuildException {
264259
File javaDirectory = new File(contentsDirectory, "Java");
265260
javaDirectory.mkdir();
266261

262+
File classesDirectory = new File(javaDirectory, "Classes");
263+
classesDirectory.mkdir();
264+
267265
File plugInsDirectory = new File(contentsDirectory, "PlugIns");
268266
plugInsDirectory.mkdir();
269267

270268
File resourcesDirectory = new File(contentsDirectory, "Resources");
271269
resourcesDirectory.mkdir();
272270

271+
// Generate Info.plist
272+
File infoPlistFile = new File(contentsDirectory, "Info.plist");
273+
infoPlistFile.createNewFile();
274+
writeInfoPlist(infoPlistFile);
275+
276+
// Generate PkgInfo
277+
File pkgInfoFile = new File(contentsDirectory, "PkgInfo");
278+
pkgInfoFile.createNewFile();
279+
writePkgInfo(pkgInfoFile);
280+
273281
// Copy executable to MacOS folder
274282
File executableFile = new File(macOSDirectory, EXECUTABLE_NAME);
275283
copy(getClass().getResource(EXECUTABLE_NAME), executableFile);
@@ -283,25 +291,20 @@ public void execute() throws BuildException {
283291

284292
// Copy class path entries to Java folder
285293
for (File entry : classPath) {
286-
// TODO Don't copy if in JRE
287-
copy(entry, new File(javaDirectory, entry.getName()));
294+
String name = entry.getName();
295+
296+
if (entry.isDirectory() || name.endsWith(CLASS_EXTENSION)) {
297+
copy(entry, new File(classesDirectory, name));
298+
} else {
299+
copy(entry, new File(javaDirectory, name));
300+
}
288301
}
289302

290-
// Copy native libraries to MacOS folder
303+
// Copy native libraries to Java folder
291304
for (File nativeLibrary : nativeLibraries) {
292305
copy(nativeLibrary, new File(macOSDirectory, nativeLibrary.getName()));
293306
}
294307

295-
// Generate Info.plist
296-
File infoPlistFile = new File(contentsDirectory, "Info.plist");
297-
infoPlistFile.createNewFile();
298-
writeInfoPlist(infoPlistFile);
299-
300-
// Generate PkgInfo
301-
File pkgInfoFile = new File(contentsDirectory, "PkgInfo");
302-
pkgInfoFile.createNewFile();
303-
writePkgInfo(pkgInfoFile);
304-
305308
// Copy icon to Resources folder
306309
if (icon == null) {
307310
copy(getClass().getResource(DEFAULT_ICON_NAME), new File(resourcesDirectory,
@@ -360,20 +363,6 @@ private void writeInfoPlist(File file) throws IOException {
360363
// Write main class name
361364
writeProperty(xout, "JVMMainClassName", mainClassName);
362365

363-
// Write class path
364-
writeKey(xout, "JVMClassPath");
365-
366-
xout.writeStartElement(ARRAY_TAG);
367-
xout.writeCharacters("\n");
368-
369-
for (File entry : classPath) {
370-
// TODO Write appropriate path based on location
371-
writeString(xout, "Contents/Java/" + entry.getName());
372-
}
373-
374-
xout.writeEndElement();
375-
xout.writeCharacters("\n");
376-
377366
// Write options
378367
writeKey(xout, "JVMOptions");
379368

0 commit comments

Comments
 (0)