1

简短的介绍

我必须在 AIX 上运行 Ghostscript。它在命令行中工作

XXXXXXXX:i2zate:/home/i2zate>/usr/bin/gs -dFIXEDMEDIA -dPDFFitPage -dFirstPage=1 -dLastPage=1 -dBATCH -dNOPAUSE -dNOPROMPT -dSAFER -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 -dDEVICEWIDTH=90 -dDEVICEHEIGHT=120 -dORIENT1=true -sDEVICE=jpeg  -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=1.jpg porsche.pdf               
GPL Ghostscript 8.70 (2009-07-31)
Copyright (C) 2009 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1

如果我从 Java 运行相同的程序,它会显示一个错误

ERROR: exec(): 0509-036 Cannot load program /usr/bin/gs because of the following errors:
ERROR:  0509-022 Cannot load module /usr/lib/libcairo.a(libcairo.so.2).
ERROR:  0509-150   Dependent module /usr/lib/libXrender.a(libXrender.so.1) could not be loaded.
ERROR:  0509-152   Member libXrender.so.1 is not found in archive
ERROR:  0509-022 Cannot load module gs.
ERROR:  0509-150   Dependent module /usr/lib/libcairo.a(libcairo.so.2) could not be loaded.
ERROR:  0509-022 Cannot load module .

我不明白,为什么会这样。你有什么主意吗?您可以在下面找到一些环境信息。如果你需要别的东西,请告诉我。

更深入的信息

我使用的java代码

package biz;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class DummyCaller {
    public static void main(String[] args) throws IOException, InterruptedException {
        printSystemProperties();
        System.out.println();
        printEnvironment();
        Process process = Runtime.getRuntime().exec( args );
        new StreamReader("OUT  ", process.getInputStream() ).start();
        new StreamReader("ERROR", process.getErrorStream() ).start();
        process.waitFor();
    }

    private static void printSystemProperties() {
        System.out.println( "System.getProperties(): " );
        List<String> keys = new ArrayList<String>();
        for (Object key : System.getProperties().keySet()) {
            keys.add( (String) key );
        }
        Collections.sort(keys);
        for (Object key : keys ) {
            System.out.println( "" + key + "=" + System.getProperty((String) key) );
        }
    }

    private static void printEnvironment() {
        System.out.println( "System.getEnv(): " );
        List<String> keys = new ArrayList<String>();
        keys.addAll(System.getenv().keySet());
        Collections.sort(keys);
        for (Object key : keys ) {
            System.out.println( "" + key + "=" + System.getenv().get( key) );
        }
    }

    public static class StreamReader extends Thread {
        private BufferedReader br;
        private String streamName;

        public StreamReader(String streamName, InputStream is ) {
            super();
            this.streamName = streamName;
            br = new BufferedReader( new InputStreamReader(is));
        }

        @Override
        public void run() {
            String line = null;
            try {
                while ( (line = br.readLine() ) != null ) {
                    System.out.println( streamName + ": " + line );
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

java程序的完整输出(一些不相关的敏感信息XXXX-ed):

XXXXXXXHOST:i2zate:/home/i2zate>java -cp . biz.DummyCaller /usr/bin/gs -dFIXEDMEDIA -dPDFFitPage -dFirstPage=1 -dLastPage=1 -dBATCH -dNOPAUSE -dNOPROMPT -dSAFER -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 -dDEVICEWIDTH=90 -dDEVICEHEIGHT=120 -dORIENT1=true -sDEVICE=jpeg  -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=1.jpg porsche.pdf
System.getProperties():
com.ibm.cpu.endian=big
com.ibm.jcl.checkClassPath=
com.ibm.oti.configuration=scar
com.ibm.oti.jcl.build=20111101_1053
com.ibm.oti.shared.enabled=false
com.ibm.oti.vm.bootstrap.library.path=/usr/java6_64/jre/lib/ppc64/default:/usr/java6_64/jre/lib/ppc64
com.ibm.oti.vm.library.version=24
com.ibm.util.extralibs.properties=
com.ibm.vm.bitmode=64
file.encoding=ISO8859-1
file.separator=/
ibm.signalhandling.rs=false
ibm.signalhandling.sigchain=true
ibm.signalhandling.sigint=true
ibm.system.encoding=ISO8859-1
java.assistive=ON
java.awt.fonts=
java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment
java.awt.printerjob=sun.print.PSPrinterJob
java.class.path=.
java.class.version=50.0
java.compiler=j9jit24
java.endorsed.dirs=/usr/java6_64/jre/lib/endorsed
java.ext.dirs=/usr/java6_64/jre/lib/ext
java.fullversion=JRE 1.6.0 IBM J9 2.4 AIX ppc64-64 jvmap6460sr10-20111207_96808 (JIT enabled, AOT enabled)
J9VM - 20111207_096808
JIT  - r9_20111107_21307ifx1
GC   - 20110519_AA
java.home=/usr/java6_64/jre
java.io.tmpdir=/tmp/
java.jcl.version=20111104_02
java.library.path=/usr/java6_64/jre/lib/ppc64/default:/usr/java6_64/jre/lib/ppc64:/usr/java6_64/jre/lib/ppc64:/usr/java6_64/jre/lib/ppc64/default:/usr/java6_64/jre/lib/ppc64/j9vm:/usr/java6_64/jre/lib/ppc64:/usr/java6_64/jre/../lib/ppc64:/usr/lib:/usr/lib
java.runtime.name=Java(TM) SE Runtime Environment
java.runtime.version=pap6460sr10-20111208_01 (SR10)
java.specification.name=Java Platform API Specification
java.specification.vendor=Sun Microsystems Inc.
java.specification.version=1.6
java.util.prefs.PreferencesFactory=java.util.prefs.FileSystemPreferencesFactory
java.vendor=IBM Corporation
java.vendor.url=http://www.ibm.com/
java.version=1.6.0
java.vm.info=JRE 1.6.0 IBM J9 2.4 AIX ppc64-64 jvmap6460sr10-20111207_96808 (JIT enabled, AOT enabled)
J9VM - 20111207_096808
JIT  - r9_20111107_21307ifx1
GC   - 20110519_AA
java.vm.name=IBM J9 VM
java.vm.specification.name=Java Virtual Machine Specification
java.vm.specification.vendor=Sun Microsystems Inc.
java.vm.specification.version=1.0
java.vm.vendor=IBM Corporation
java.vm.version=2.4
jxe.current.romimage.version=15
jxe.lowest.romimage.version=15
line.separator=

os.arch=ppc64
os.encoding=ISO8859-1
os.name=AIX
os.version=6.1
path.separator=:
sun.arch.data.model=64
sun.boot.class.path=/usr/java6_64/jre/lib/ppc64/default/jclSC160/vm.jar:/usr/java6_64/jre/lib/annotation.jar:/usr/java6_64/jre/lib/beans.jar:/usr/java6_64/jre/lib/java.util.jar:/usr/java6_64/jre/lib/jndi.jar:/usr/java6_64/jre/lib/logging.jar:/usr/java6_64/jre/lib/security.jar:/usr/java6_64/jre/lib/sql.jar:/usr/java6_64/jre/lib/ibmorb.jar:/usr/java6_64/jre/lib/ibmorbapi.jar:/usr/java6_64/jre/lib/ibmcfw.jar:/usr/java6_64/jre/lib/rt.jar:/usr/java6_64/jre/lib/charsets.jar:/usr/java6_64/jre/lib/resources.jar:/usr/java6_64/jre/lib/ibmpkcs.jar:/usr/java6_64/jre/lib/ibmcertpathfw.jar:/usr/java6_64/jre/lib/ibmjgssfw.jar:/usr/java6_64/jre/lib/ibmjssefw.jar:/usr/java6_64/jre/lib/ibmsaslfw.jar:/usr/java6_64/jre/lib/ibmjcefw.jar:/usr/java6_64/jre/lib/ibmjgssprovider.jar:/usr/java6_64/jre/lib/ibmjsseprovider2.jar:/usr/java6_64/jre/lib/ibmcertpathprovider.jar:/usr/java6_64/jre/lib/ibmxmlcrypto.jar:/usr/java6_64/jre/lib/management-agent.jar:/usr/java6_64/jre/lib/xml.jar:/usr/java6_64/jre/lib/jlm.jar:/usr/java6_64/jre/lib/javascript.jar
sun.boot.library.path=/usr/java6_64/jre/lib/ppc64/default:/usr/java6_64/jre/lib/ppc64
sun.cpu.endian=big
sun.io.unicode.encoding=UnicodeBig
sun.java.command=biz.DummyCaller /usr/bin/gs -dFIXEDMEDIA -dPDFFitPage -dFirstPage=1 -dLastPage=1 -dBATCH -dNOPAUSE -dNOPROMPT -dSAFER -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 -dDEVICEWIDTH=90 -dDEVICEHEIGHT=120 -dORIENT1=true -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=1.jpg porsche.pdf
sun.java.launcher=SUN_STANDARD
sun.java2d.fontpath=
sun.jnu.encoding=ISO8859-1
user.country=US
user.dir=/home/i2zate
user.home=/home/i2zate
user.language=en
user.name=i2zate
user.timezone=
user.variant=

System.getEnv():
AIXTHREAD_SCOPE=S
AUTHSTATE=compat
AWK=/usr/bin/awk
A__z=! LOGNAME
BAR_BSALIB_PATH=/usr/tivoli/tsm/client/api/bin/xbsa.o
CORE_MMAP=yes
CSP_HOME=/opt/csp/at/test
DSMI_CONFIG=/usr/tivoli/tsm/client/api/bin/dsm.opt
DSMI_DIR=/usr/tivoli/tsm/client/api/bin
DSMI_INF_DIR=/usr/tivoli/tsm/client/informix/bin
DSMI_LOG=/var/opt/RRZ/log
DSMI_ORC_CONFIG=/usr/tivoli/tsm/client/oracle/bin/dsm.opt
DSMO_DEBUG=/var/opt/RRZ/log/orcagent.log
DSMO_NODE=XXXXXXXX_ORA
DSM_CONFIG=/usr/tivoli/tsm/client/ba/bin/dsm.opt
DSM_DIR=/usr/tivoli/tsm/client/ba/bin
DSM_LOG=/var/opt/RRZ/log
EDITOR=vi
HOME=/home/i2zate
HOST=XXXXXXXXX
IBM_JAVA_COMMAND_LINE=java -cp . biz.DummyCaller /usr/bin/gs -dFIXEDMEDIA -dPDFFitPage -dFirstPage=1 -dLastPage=1 -dBATCH -dNOPAUSE -dNOPROMPT -dSAFER -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 -dDEVICEWIDTH=90 -dDEVICEHEIGHT=120 -dORIENT1=true -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=1.jpg porsche.pdf
IBM_JVM_AIXTHREAD_SCOPE_NEW_VALUE=S
IBM_JVM_CHANGED_ENVVARS_3211296=AIXTHREAD_SCOPE,NULLPTR,CORE_MMAP
IBM_JVM_CORE_MMAP_NEW_VALUE=yes
IBM_JVM_NULLPTR_NEW_VALUE=NOSEGV
JAVA_HOME=/usr/java6_64/jre
JOBS=/opt/RRZ/AIX
LANG=en_US
LC_CTYPE=C
LC__FASTMSG=true
LIBPATH=/usr/java6_64/jre/lib/ppc64/j9vm:/usr/java6_64/jre/lib/ppc64:/usr/java6_64/jre/../lib/ppc64:/usr/lib
LOCPATH=/usr/lib/nls/loc
LOGIN=i2zate
LOGNAME=i2zate
LOGS=/var/opt/RRZ/log
MAIL=/usr/spool/mail/i2zate
MAILMSG=[YOU HAVE NEW MAIL]
NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat
NUI_NOCHECKSUM=1
NUI_NOTESDIR=/opt/lotus
NULLPTR=NOSEGV
ODMDIR=/etc/objrepos
PATH=/usr/java6_64/jre/bin:/usr/java6_64/jre/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/i2zate/bin:/usr/bin/X11:/sbin:.
PRINTER=XXXXXXXX
PROTS=/var/opt/RRZ/prots
PS1=$HOST:$USER:$PWD>
PWD=/home/i2zate
SHELL=/usr/bin/ksh
SHLVL=1
SPOC=/opt/RRZ/AIX/spoc
SPOCVER=6.1
SSH_CLIENT=XXXXXXXXXXXXXXXXXXXX
SSH_CONNECTION=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SSH_TTY=/dev/pts/0
SYS=AIX
TAPE=/dev/rmt0
TERM=xterm
TSM=/usr/tivoli/tsm/client/ba/bin/
TZ=MET-1METDST,M3.5.0/2:00,M10.5.0/3:00
USER=i2zate
_=/usr/java6_64/jre/bin/java

ERROR: exec(): 0509-036 Cannot load program /usr/bin/gs because of the following errors:
ERROR:  0509-022 Cannot load module /usr/lib/libcairo.a(libcairo.so.2).
ERROR:  0509-150   Dependent module /usr/lib/libXrender.a(libXrender.so.1) could not be loaded.
ERROR:  0509-152   Member libXrender.so.1 is not found in archive
ERROR:  0509-022 Cannot load module gs.
ERROR:  0509-150   Dependent module /usr/lib/libcairo.a(libcairo.so.2) could not be loaded.
ERROR:  0509-022 Cannot load module .

来自同一命令行会话的环境信息:

XXXXXXXX:i2zate:/home/i2zate>set
AUTHSTATE=compat
AWK=/usr/bin/awk
A__z='! LOGNAME'
BAR_BSALIB_PATH=/usr/tivoli/tsm/client/api/bin/xbsa.o
BASH=/usr/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="00" [2]="16" [3]="1" [4]="release" [5]="powerpc-ibm-aix5.1")
BASH_VERSION='3.00.16(1)-release'
COLUMNS=168
CSP_HOME=/opt/csp/at/test
DIRSTACK=()
DSMI_CONFIG=/usr/tivoli/tsm/client/api/bin/dsm.opt
DSMI_DIR=/usr/tivoli/tsm/client/api/bin
DSMI_INF_DIR=/usr/tivoli/tsm/client/informix/bin
DSMI_LOG=/var/opt/RRZ/log
DSMI_ORC_CONFIG=/usr/tivoli/tsm/client/oracle/bin/dsm.opt
DSMO_DEBUG=/var/opt/RRZ/log/orcagent.log
DSMO_NODE=XXXXXXXX_ORA
DSM_CONFIG=/usr/tivoli/tsm/client/ba/bin/dsm.opt
DSM_DIR=/usr/tivoli/tsm/client/ba/bin
DSM_LOG=/var/opt/RRZ/log
EDITOR=vi
EUID=623
GROUPS=()
HISTFILE=/home/i2zate/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/home/i2zate
HOST=XXXXXXXX
HOSTNAME=XXXXXXXX
HOSTTYPE=powerpc
IFS=$' \t\n'
JAVA_HOME=/usr/java6_64/jre
JOBS=/opt/RRZ/AIX
LANG=en_US
LC_CTYPE=C
LC__FASTMSG=true
LINES=46
LOCPATH=/usr/lib/nls/loc
LOGIN=i2zate
LOGNAME=i2zate
LOGS=/var/opt/RRZ/log
MACHTYPE=powerpc-ibm-aix5.1
MAIL=/usr/spool/mail/i2zate
MAILCHECK=60
MAILMSG='[YOU HAVE NEW MAIL]'
NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat
NUI_NOCHECKSUM=1
NUI_NOTESDIR=/opt/lotus
ODMDIR=/etc/objrepos
OPTERR=1
OPTIND=1
OSTYPE=aix5.1
PATH=/usr/java6_64/jre/bin:/usr/java6_64/jre/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/i2zate/bin:/usr/bin/X11:/sbin:.
PIPESTATUS=([0]="0")
PPID=2556030
PRINTER=prrz056
PROTS=/var/opt/RRZ/prots
PS1='$HOST:$USER:$PWD>'
PS2='> '
PS4='+ '
PWD=/home/i2zate
SHELL=/usr/bin/ksh
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=1
SPOC=/opt/RRZ/AIX/spoc
SPOCVER=6.1
SSH_CLIENT='XXXXXXXXXXXXXXXXXXXX'
SSH_CONNECTION='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
SSH_TTY=/dev/pts/0
SYS=AIX
TAPE=/dev/rmt0
TERM=xterm
TSM=/usr/tivoli/tsm/client/ba/bin/
TZ=MET-1METDST,M3.5.0/2:00,M10.5.0/3:00
UID=623
USER=i2zate
_=porsche.pdf
4

1 回答 1

1

事实证明,LIBPATH 不正确,Java 将什么传递给分叉的流程实例。

1. 步骤:获取 Ghostscript 的 LIBPATH:

经过大量的谷歌搜索,我发现了这个:

XXXXXXXX:i2zate:/home/i2zate>dump -Hv /usr/bin/gs

/usr/bin/gs:

                        ***Loader Section***
                      Loader Header Information
VERSION#         #SYMtableENT     #RELOCent        LENidSTR
0x00000001       0x00000137       0x00008118       0x000001ad

#IMPfilID        OFFidSTR         LENstrTBL        OFFstrTBL
0x0000000e       0x00062a68       0x00000e99       0x00062c15


                        ***Import File Strings***
INDEX  PATH                          BASE                MEMBER
0      /opt/freeware/lib:/opt/freeware/lib/gcc/powerpc-ibm-aix5.1.0.0/4.2.3:/opt/freeware/lib/gcc/powerpc-ibm-aix5.1.0.0/4.2.3/../../..:/usr/lib:/lib                   
1                                    libc.a              shr.o
2                                    libpthread.a        shr_comm.o
3                                    libpthread.a        shr_xpg5.o
4                                    libXt.a             shr4.o
5                                    libX11.a            shr4.o
6                                    libcairo.a          libcairo.so.2
7                                    libjpeg.a           libjpeg.so.62
8                                    libz.a              libz.so.1
9                                    libfontconfig.a     libfontconfig.so.1
10                                   libpng.a            libpng.so.3
11                                   libpaper.a          libpaper.so.1
12                                   libiconv.a          shr4.o
13                                   libdl.a             shr.o

在这里你看到索引 0(不要问我,这意味着什么,这只是一个猜测,我需要那个):/opt/freeware/lib: /opt/freeware/lib/gcc/powerpc-ibm-aix5.1.0 .0/4.2.3:/opt/freeware/lib/gcc/powerpc-ibm-aix5.1.0.0/4.2.3/../../..:/usr/lib:/lib

2.步骤:在java中传递LIBPATH

我稍微改变了我的班级。DummyCaller 使用它获得的第一个参数作为分叉进程的 LIBPATH。查看更改的方法:

public static void main(String[] args) throws IOException, InterruptedException {
    printSystemProperties();
    System.out.println();
    printEnvironment();
    String[] command = new String[ args.length - 1 ];
    System.arraycopy(args, 1, command, 0, args.length-1);
    ProcessBuilder processBuilder = new ProcessBuilder( Arrays.asList(command));
    Map<String, String> env = processBuilder.environment();
    env.put("LIBPATH", args[0] );
    Process process = processBuilder.start();
    new StreamReader("OUT  ", process.getInputStream() ).start();
    new StreamReader("ERROR", process.getErrorStream() ).start();
    process.waitFor();
}

所以第一个参数被添加到 ProcessBuilder 的环境中。

3. 步骤:使用正确的 LIBPATH 进行调用

xiud0e02:i2zate:/home/i2zate>java -cp . biz.DummyCaller /opt/freeware/lib:/opt/freeware/lib/gcc/powerpc-ibm-aix5.1.0.0/4.2.3:/opt/freeware/lib/gcc/powerpc-ibm-aix5.1.0.0/4.2.3/../../..:/usr/lib:/lib /usr/bin/gs -dFIXEDMEDIA -dPDFFitPage -dFirstPage=1 -dLastPage=1 -dBATCH -dNOPAUSE -dNOPROMPT -dSAFER -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 -dDEVICEWIDTH=90 -dDEVICEHEIGHT=120 -dORIENT1=true -sDEVICE=jpeg  -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=1.jpg porsche.pdf
System.getProperties():
com.ibm.cpu.endian=big
com.ibm.jcl.checkClassPath=
....
....
....
TSM=/usr/tivoli/tsm/client/ba/bin/
TZ=MET-1METDST,M3.5.0/2:00,M10.5.0/3:00
USER=i2zate
_=/usr/java6_64/jre/bin/java
OUT  : GPL Ghostscript 8.70 (2009-07-31)
OUT  : Copyright (C) 2009 Artifex Software, Inc.  All rights reserved.
OUT  : This software comes with NO WARRANTY: see the file PUBLIC for details.
OUT  : Processing pages 1 through 1.
OUT  : Page 1

作品。凉爽的。

于 2012-07-12T12:50:24.373 回答