0

这是错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/alicebot/server/net/AliceServer
Caused by: java.lang.ClassNotFoundException: org.alicebot.server.net.AliceServer
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

这是 server.sh 文件:

#!/bin/sh
echo Starting Jarvis Program D.
cd "`dirname \"$0\"`"
export ALICE_HOME=.
export SERVLET_LIB=lib/servlet.jar
export ALICE_LIB=lib/aliceserver.jar
export JS_LIB=lib/js.jar

# Set SQL_LIB to the location of your database driver.
export SQL_LIB=lib/mysql_comp.jar

# These are for Jetty; you will want to change these if you are using a different http server.
export HTTP_SERVER_LIBS=lib/org.mortbay.jetty.jar

export PROGRAMD_CLASSPATH=$SERVLET_LIB:$ALICE_LIB:$JS_LIB:$SQL_LIB:$HTTP_SERVER_LIBS
exec java -classpath $PROGRAMD_CLASSPATH -Xms64m -Xmx128m org.alicebot.server.net.AliceServer $1

这是 NSTask 代码:

NSString *shstring = [NSString stringWithFormat:
                          @"%@ %@ %@", 
                          @"source", 
                          @"server.sh", 
                          @"| /usr/bin/sed '/Jarvis>/q'"
                          ];

NSTask *sh = [NSTask new];
    NSPipe *outputPipe = [NSPipe new];

    [sh setLaunchPath:@"/bin/sh"];
    [sh setArguments:[NSArray arrayWithObjects: @"-c", shstring, nil ]];
    [sh setCurrentDirectoryPath:@"/applications/jarvis/brain"];
    [sh setStandardInput:[NSPipe new]];
    [sh setStandardError:outputPipe];
    [sh setStandardOutput:outputPipe];
    [sh launch];

    NSMutableString *outputString = [NSMutableString string];
    while ([outputString rangeOfString:@"Jarvis>"].location == NSNotFound) {
        [outputString appendString:[[[NSString alloc] initWithData:[[outputPipe fileHandleForReading] readDataToEndOfFile] encoding:NSUTF8StringEncoding] autorelease]];
        NSRunAlertPanel(@"", outputString, @"", @"", @"");
    }

每当我通过 NSTask 运行此脚本并检查错误管道时,就会出现该错误并且仅打印回显。

有任何想法吗?

4

2 回答 2

0

看起来工作目录不是您期望的那样。您在 classpath 参数中定义相对路径。它们是相对于当前工作目录的。当前工作目录可能不知道lib/aliceserver.jar文件。做一个pwd来了解当前的工作目录。

于 2010-08-22T05:23:12.317 回答
0

在 server.sh 中将 relative 替换为绝对路径,然后使用完整路径运行 server.sh(如果 server.sh 具有 shebang 行,请不要在 NSTask 代码中获取 server.sh 并始终检查 cd 命令的退出代码)。

这是我的 server.sh 文件:

#!/bin/sh
# cat ~/Desktop/charliebot/server.sh

# code from: http://sourceforge.net/projects/charliebot/

# also adapt the following files if necessary:
# ~/Desktop/charliebot/console.sh
# ~/Desktop/charliebot/targeting.sh
# ~/Desktop/charliebot/tester.sh

echo Starting Alicebot Program D.
ALICE_HOME="${HOME}/Desktop/charliebot"

cd "${ALICE_HOME}" || { echo "Could not cd to: ${ALICE_HOME}"; exit 1; }

SERVLET_LIB="${ALICE_HOME}/lib/servlet.jar"
ALICE_LIB="${ALICE_HOME}/lib/aliceserver.jar"
JS_LIB="${ALICE_HOME}/lib/js.jar"

# Set SQL_LIB to the location of your database driver.
SQL_LIB="${ALICE_HOME}/lib/mysql_comp.jar"

# These are for Jetty; you will want to change these if you are using a different http server.
HTTP_SERVER_LIBS="${ALICE_HOME}/lib/org.mortbay.jetty.jar"

PROGRAMD_CLASSPATH="${SERVLET_LIB}:${ALICE_LIB}:${JS_LIB}:${SQL_LIB}:${HTTP_SERVER_LIBS}"

export ALICE_HOME SERVLET_LIB ALICE_LIB JS_LIB HTTP_SERVER_LIBS PROGRAMD_CLASSPATH

#printf "\n\n\nPROGRAMD_CLASSPATH\n%s\n\n\n"  "$PROGRAMD_CLASSPATH" | tr ':' '\n'

exec java -classpath "$PROGRAMD_CLASSPATH" -Xms64m -Xmx128m org.alicebot.server.net.AliceServer $1

这对我有用,没有丝毫打嗝。

# in Terminal.app
~/Desktop/charliebot/server.sh

我不认为 server.sh 的参数 $1 是强制性的。如果是这种情况,server.sh(即 exec java -classpath ...$1)会抱怨它。但是,是的,很高兴知道什么样的参数可以作为 $1 传递给 server.sh (...阅读 man 1 java ...)!

当然,所有这些都不会消除您的 Objective-C while 循环死锁 (NSNotFound)。您必须实现异步标准输出管道读取机制而不是 while 循环。(例如,有关这种方法的异步操作,请参见 Apple 的“仪表板编程主题”。)

于 2010-08-22T20:16:15.033 回答