gpt4 book ai didi

java - 运行 *.sh 脚本时发生 ClassNotFoundException

转载 作者:行者123 更新时间:2023-12-02 08:03:56 25 4
gpt4 key购买 nike

我已经下载了 CMU ARK Twitter Part-of-Speech tagger用作更大项目的一部分。为了确保它在插入之前正常工作,我从计算机上项目的根目录运行了项目自述文件中的脚本。我没有做任何改变。这是脚本:

$ ./runTagger.sh -input example_tweets.txt -output tagged_tweets.txt

我收到此错误:

java.lang.NoClassDefFoundError: edu/cmu/cs/lti/ark/tweetnlp/RunPOSTagger
Caused by: java.lang.ClassNotFoundException: edu.cmu.cs.lti.ark.tweetnlp.RunPOST agger

at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: edu.cmu.cs.lti.ark.tweetnlp.RunPOSTagger.
Program will exit. Exception in thread "main"

我认为类路径的设置方式有问题。 runTagger 脚本调用另一个脚本 classwrap.sh,该脚本应该通过访问调用脚本的根目录来设置类路径,但不知何故它不起作用。

这里是runTagger.sh

#!/bin/bash

$(dirname $0)/scripts/classwrap.sh -Xmx1g edu.cmu.cs.lti.ark.tweetnlp.RunPOSTagger "$@"

这里是classwrap.sh

#!/bin/bash

# Set up classpath and invoke 'java' with it

set -eu
root=$(dirname $0)/..

cp=""
# Eclipse and IDEA defaults
cp=$cp:$root/bin
cp=$cp:$root/out/production/ark-tweet-nlp
# our build dir
cp=$cp:$root/mybuild

cp=$cp:$(echo $root/lib/*.jar | tr ' ' :)
# Twitter Commons text library stuff
cp=$cp:$(echo $root/lib_twitter/*.jar | tr ' ' :)

exec java -cp "$cp" "$@"

我不确定问题出在哪里。显然,在这方面我是个菜鸟,这就是我来这里的原因。如有任何建议,我们将不胜感激。

::编辑::
我在 exec 命令之前回显了 cp 变量,这就是返回的内容:

:scripts/../bin:scripts/../out/production/ark-tweet-nlp:scripts/../mybuild:scripts/../lib/ark-tweet-nlp.jar:scripts/../lib/commons-codec-1.4.jar:scripts/../lib/commons-math-2.1.jar:scripts/../lib/jargs.jar:scripts/../lib/posBerkeley.jar:scripts/../lib/scala-library-2.9.0.1.jar:scripts/../lib_twitter/guava-r09.jar:scripts/../lib_twitter/lucene-core-3.0.3.jar:scripts/../lib_twitter/text-0.1.0.jar:scripts/../lib_twitter/twitter-text-1.1.8.jar

scripts/../lib/ark-tweet-nlp.jar包含代码的编译版本。所以我觉得我们的目的就是让它包含在类路径中。这还不够吗?如果是这样,我应该明确地将 lib/edu/cmu...etc 添加到 cp 吗?

::编辑2::
我给这个项目的创建者之一 Kevin Gimpel 发了电子邮件,他给我发了一个批处理文件来运行,而不是项目中包含的 shell 脚本。

java -cp lib/ark-tweet-nlp.jar;lib/commons-codec-1.4.jar;lib/commons-math-2.1.jar;lib/jargs.jar;lib/posBerkeley.jar;lib/scala-library-2.9.0.1.jar -Xmx1g edu.cmu.cs.lti.ark.tweetnlp.RunPOSTagger -input example_tweets.txt -output test.txt

如您所见,他设置了类路径,然后运行引用从 src (edu) 中包含的文件夹到该类的整个路径的类。我已要求他解释他认为问题所在,当他解释时,我会将其添加为该问题的答案。

最佳答案

这 2 个命令表明您的操作系统与脚本所针对的操作系统不匹配。 “;”是 Windows 上的类路径分隔符,而“:”是其他地方(例如 linux)的类路径分隔符。

关于java - 运行 *.sh 脚本时发生 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8462735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com