Java作为jar工作,不能用作mac app

时间:2013-07-13 22:00:42

标签: java macos

我有一个小的java应用程序,它通过一个目录并将图像组合成一个pdf文件。该应用程序在Windows上运行良好,在mac上作为jar运行,但是当我使用appbundler捆绑应用程序时它不会运行并返回错误:

  

LSOpenURLsWithRole()失败,文件错误为-10810 /Users/danielheidt/Documents/Confero/Playground/dist/Playground.app

ant构建文件是:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for Project Playground with Jar-in-Jar Loader">
    <!--this file was created by Eclipse Runnable JAR Export Wizard-->
    <!--ANT 1.7 is required                                        -->

<target name="create_run_jar">
    <jar destfile="/Users/danielhheidt/Documents/Confero/Playground/dist/Playground.jar">
        <manifest>
            <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
            <attribute name="Rsrc-Main-Class" value="Main"/>
            <attribute name="Class-Path" value="."/>
            <attribute name="Rsrc-Class-Path" value="./ pdfbox-app-1.8.2.jar appbundler-1-1.0.jar"/>
        </manifest>
        <zipfileset src="jar-in-jar-loader.zip"/>
        <fileset dir="/Users/danielhheidt/Documents/Confero/Playground/bin"/>
        <zipfileset dir="/Users/danielhheidt/Documents/Confero" includes="pdfbox-app-1.8.2.jar"/>
        <zipfileset dir="/Users/danielhheidt/Documents/Confero" includes="appbundler-1-1.0.jar"/>
    </jar>
</target>


 <taskdef name="bundleapp"
             classname="com.oracle.appbundler.AppBundlerTask"   
             classpath="lib/appbundler-1-1.0.jar" />

    <target name="bundle-Playground">
        <bundleapp outputdirectory="dist"
            name="Playground"
            displayname="Playground"
            identifier="Main"
            mainclassname="Main">
            <classpath file="dist/playground.jar" />
            <runtime dir="/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home" />
        </bundleapp>
    </target>

应用程序本身的代码是:

import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg;

public class Main {

public static void main(String[] args) {
    PDDocument acrobat = null;
    String groupPath = "C:\\Users\\Doug\\Desktop\\smaller test";
    File groupFolder = new File(groupPath);
    try{
        acrobat = new PDDocument();

        groupFolder.mkdir();
        }catch(Exception e){
        }
        for(File f:groupFolder.listFiles()){
//skip over any hidden or not image files
            if(f.isHidden() || f.getName().trim().charAt(0)=='.' || 
                    !(f.getName().toLowerCase().trim().contains(".jpg") || f.getName().toLowerCase().trim().contains(".jpeg") ||
                      f.getName().toLowerCase().trim().contains(".wbmp") || f.getName().toLowerCase().trim().contains(".gif") ||
                      f.getName().toLowerCase().trim().contains(".png") || f.getName().toLowerCase().trim().contains(".bmp")))
                continue;

            PDPageContentStream contentStream = null;

            try{
                BufferedImage bigImage = ImageIO.read(f);
                int w = bigImage.getWidth();
                int h = bigImage.getHeight();

                PDRectangle rect = new PDRectangle(w, h);
                PDPage page = new PDPage(rect);
                acrobat.addPage(page);
                PDJpeg img = new PDJpeg(acrobat, bigImage);

                contentStream = new PDPageContentStream(acrobat,page);
                contentStream.drawImage(img, 0, 0);
                contentStream.close();

            }catch(Exception e){
                e.printStackTrace();
            }
        }
        try {
                acrobat.save(groupPath+".pdf");
                acrobat.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
}

}

plist.info文件是:

<?xml version="1.0" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>JavaAppLauncher</string>
<key>CFBundleIconFile</key>
<string>GenericApp.icns</string>
<key>CFBundleIdentifier</key>
<string>Main</string>
<key>CFBundleDisplayName</key>
<string>Playground</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Playground</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string></string>
<key>JVMRuntime</key>
<string>Program Files</string>
<key>JVMMainClassName</key>
<string>/Main</string>
<key>JVMOptions</key>
<array>
</array>
 <key>JVMArguments</key>
<array>
</array>
</dict>
</plist>

你知道为什么它可以作为一个罐而不是作为一个应用程序吗?

0 个答案:

没有答案