Skip to content

Commit 00d1402

Browse files
author
gk_brown
committed
Add support for JVMClassPath entry in Info.plist.
git-svn-id: https://svn.java.net/svn/appbundler~svn@8 07572b26-92e5-4d45-f66a-c18421440a21
1 parent 102cfae commit 00d1402

File tree

3 files changed

+50
-42
lines changed

3 files changed

+50
-42
lines changed

appbundler/native/main.m

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

3333
#define JVM_RUNTIME_KEY "JVMRuntime"
3434
#define JVM_MAIN_CLASS_NAME_KEY "JVMMainClassName"
35+
#define JVM_CLASS_PATH_KEY "JVMClassPath"
3536
#define JVM_OPTIONS_KEY "JVMOptions"
3637
#define JVM_ARGUMENTS_KEY "JVMArguments"
3738

@@ -119,25 +120,25 @@ int launch(char *commandName) {
119120
}
120121

121122
// Set the class path
122-
NSString *classPathFormat = @"-Djava.class.path=%@/Classes";
123-
NSString *javaPath = [mainBundlePath stringByAppendingString:@"/Contents/Java"];
124-
NSMutableString *classPath = [[NSString stringWithFormat:classPathFormat, javaPath] mutableCopy];
125-
126-
NSFileManager *defaultFileManager = [NSFileManager defaultManager];
127-
NSArray *javaDirectoryContents = [defaultFileManager contentsOfDirectoryAtPath:javaPath error:nil];
128-
if (javaDirectoryContents == nil) {
129-
[NSException raise:@JAVA_LAUNCH_ERROR format:@"Could not enumerate Java directory contents."];
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];
130127
}
131128

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

138+
NSLog(@"classPath = %@", classPath);
139+
138140
// Set the library path
139-
NSString *libraryPathFormat = @"-Djava.library.path=%@";
140-
NSString *libraryPath = [NSString stringWithFormat:libraryPathFormat, javaPath];
141+
NSString *libraryPath = [NSString stringWithFormat:@"-Djava.library.path=%@/Contents/MacOS", mainBundlePath];
141142

142143
// Get the VM options
143144
NSArray *options = [infoDictionary objectForKey:@JVM_OPTIONS_KEY];

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

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

141141
for (int i = 0; i < includedFiles.length; i++) {
142-
this.classPath.add(new File(parent, includedFiles[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);
143148
}
144149
}
145150

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

262-
File classesDirectory = new File(javaDirectory, "Classes");
263-
classesDirectory.mkdir();
264-
265267
File plugInsDirectory = new File(contentsDirectory, "PlugIns");
266268
plugInsDirectory.mkdir();
267269

268270
File resourcesDirectory = new File(contentsDirectory, "Resources");
269271
resourcesDirectory.mkdir();
270272

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-
281273
// Copy executable to MacOS folder
282274
File executableFile = new File(macOSDirectory, EXECUTABLE_NAME);
283275
copy(getClass().getResource(EXECUTABLE_NAME), executableFile);
@@ -291,20 +283,25 @@ public void execute() throws BuildException {
291283

292284
// Copy class path entries to Java folder
293285
for (File entry : classPath) {
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-
}
286+
// TODO Don't copy if in JRE
287+
copy(entry, new File(javaDirectory, entry.getName()));
301288
}
302289

303-
// Copy native libraries to Java folder
290+
// Copy native libraries to MacOS folder
304291
for (File nativeLibrary : nativeLibraries) {
305-
copy(nativeLibrary, new File(javaDirectory, nativeLibrary.getName()));
292+
copy(nativeLibrary, new File(macOSDirectory, nativeLibrary.getName()));
306293
}
307294

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+
308305
// Copy icon to Resources folder
309306
if (icon == null) {
310307
copy(getClass().getResource(DEFAULT_ICON_NAME), new File(resourcesDirectory,
@@ -363,6 +360,20 @@ private void writeInfoPlist(File file) throws IOException {
363360
// Write main class name
364361
writeProperty(xout, "JVMMainClassName", mainClassName);
365362

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+
366377
// Write options
367378
writeKey(xout, "JVMOptions");
368379

build.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,15 @@ questions.
8989

9090
<!-- Clean target -->
9191
<target name="clean">
92-
<delete dir="${ant.project.name}/${folder.classes}"/>
93-
<delete file="${ant.project.name}/${folder.bin}/${ant.project.name}-${version}.jar"/>
92+
<delete dir="${ant.project.name}/${folder.bin}"/>
9493
<delete dir="HelloWorld.app"/>
9594
<delete dir="SwingSet2.app"/>
9695
<delete dir="SwingSet2Plugin.app"/>
9796
</target>
9897

9998
<!-- Package target -->
10099
<target name="package" depends="compile">
101-
<property name="destfile" value="${ant.project.name}/${folder.bin}/${ant.project.name}-${version}.jar"/>
102-
103-
<delete file="${destfile}"/>
104-
<jar destfile="${destfile}" index="true">
100+
<jar destfile="${ant.project.name}/${folder.bin}/${ant.project.name}-${version}.jar" index="true">
105101
<manifest>
106102
<attribute name="Implementation-Vendor-Id" value="com.oracle"/>
107103
<attribute name="Implementation-Vendor" value="Oracle"/>

0 commit comments

Comments
 (0)