Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's wrong with MRJAppBuilder?



On Tuesday, May 29, 2001, at 05:58 AM, Michael Hall wrote:

Are you embedding your class files in the bundle or providing paths. If providing paths are they full/absolute paths? This was my initial problem with it. Some of my jars/zips are supposed to be shared between different chunks of code or be available between Classic and OS/X versions so imbedding in the bundle doesn't seem to work that smoothly. And your choice otherwise, specifying full paths isn't exactly the smoothest either.

If not interested in something to handle the sometimes missing MRJAppBuilder PkgInfo file or a way to adjust the applications classpath allowing for jar's and zip's to _more easily_ be external to the application bundle feel free to ignore and apologies for the length.
OK, I put a class together for the above and the missing PkgInfo. It will check for the existence of a PkgInfo and create it if missing, you can optionally specifiy the creator to be used in the file. It also allows you to specify a classpath who's path will replace the path of the MRJApp.properties classpath files. Clear as mud?
Suppose all the classpath entries in the application are full path specified along the lines of...
/Mac OS 9/Java/Combined/ext/cmdline.zip
and you have downloaded it to...
/Users/mjh/Java/Combined
You can automatically change the path in the properties file to
/Users/mjh/Java/Combined/ext/cmdline.zip
Sample usage:
java -cp whereever MRJAppTweaker -creator jsig -classpath ext
or it will remove the spot if you use
java -cp whereever MRJAppTweaker -classpath .

this is not a build type tool like that indicated by Ian McFarland a bit ago but simply something for the PkgInfo file and something that could be included in a install shell script to adjust classpath for external jar's and zip's.
Ian's at...
http://www.neo.com/java/auntiemac.html

It doesn't mess with any of the .plist files.

The source...

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.StringTokenizer;

public class MRJAppTweaker {

/*
Switches: -creator Used to create or verify PkgInfo file
-classpath Used to verify correctness of paths in MRJApp.properties
application.classpath
*/
public static void main(String [] args) {
boolean info = false;
String creator = "japp", classpath = null;
if (args.length == 0) {
System.out.println("MRJAppTweaker: missing paraemters");
System.out.println("Usage: -creator [optional] Use as creator if PkgInfo file doesn't exist");
System.out.println(" -classpath [optional] Path to switch MRJApp.properties classpath entries to");
System.out.println(" -info [optional] Overrides prior. Indicates PkgInfo existence and current classpath settings");
System.out.println(" application [required] MRJAppBuilder application");
return;
}
for (int i=0;i<args.length-1;i++) {
if (args[i].equals("-info")) info = true;
if (args[i].equals("-creator"))
creator = args[++i];
else if (args[i].equals("-classpath"))
classpath = args[++i];
else {
System.out.println("MRJAppTweaker: Unknown parameter " + args[i]);
break;
}
}
String application = args[args.length-1];
File appfile = new File(application);
boolean isapp = appfile.exists();
if (!isapp) {
System.out.println("MRJAppTweaker: application " + application + " does not exist");
return;
}
File pkginfo = new File(application + "/Contents/PkgInfo");
byte [] b = new String("APPL" + creator).getBytes();
if (!pkginfo.exists()) {
if (info) {
System.out.println("MRJAppTweaker: PkgInfo does not exist");
}
else try {
FileOutputStream fos = new FileOutputStream(pkginfo);
fos.write(b);
fos.close();
}
catch (IOException ioex) {
System.out.println("MRJAppTweaker: failed to create PkgInfo\n" + ioex.toString());
}
}
else if (info) System.out.println("MRJAppTweaker: PkgInfo exists");
if (classpath != null) {
try {
boolean done = false;
RandomAccessFile props = new RandomAccessFile(new File(application + "/Contents/Resources/MRJApp.properties"),"rw");
props.readLine();
String line = props.readLine();
if (line == null) { throw new Error("MRJAppTweaker: Error processing MRJApp.properties"); }
StringBuffer lines = new StringBuffer(line);
while (!done) {
if (line.startsWith("com.apple.mrj.application.classpath")) {
if (info) {
System.out.println("MRJAppTweaker: current classpath is\n" + line);
break;
}
line = dopath(classpath,line.substring(line.indexOf("=")+1));
}
lines.append(line+"\n");
line = props.readLine();
if (line == null) {
props.seek((long)0);
byte [] bprops = lines.toString().getBytes();
props.write(bprops);
props.setLength((long)bprops.length);
done = true;
}
}
props.close();
}
catch (IOException ioex) {
throw new Error("MRJAppTweaker: failed processing classpath property\n" + ioex.toString());
}
}
}

private static String dopath(String classpath,String proppaths) {
if (classpath.equals(".")) {
classpath = new File(classpath).getAbsolutePath();
classpath = classpath.substring(0,classpath.lastIndexOf("/"));
}
StringTokenizer paths = new StringTokenizer(proppaths,":");
StringBuffer pathout = new StringBuffer("com.apple.mrj.application.classpath=");
while (paths.hasMoreTokens()) {
String path = paths.nextToken();
String file = path.substring(path.lastIndexOf("/")+1);
pathout.append(new File(classpath).getAbsolutePath() + "/" + file + ":");
}
pathout.setLength(pathout.length()-1); // Truncate last :, neatness counts
return pathout.toString();
}
}

Mike Hall <email@hidden>
<http://www.spacestar.net/users/mikehall>


References: 
 >Re: What's wrong with MRJAppBuilder? (From: Michael Hall <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.