在 VMWare 上运行 java 代码并引用外部 jar 文件

发布于 2024-11-06 03:41:21 字数 1247 浏览 2 评论 0原文

我正在尝试在 VMWare Workstation 上运行简单的 java 代码。我有以下简单的测试主文件:

import cern.jet.random.engine.RandomSeedGenerator;;

public class TestDataService {

    //private static Logger logger = Logger.getLogger(TestDataService.class);
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.out.println("Hello World DAI!");

        // Input some data.
        RandomSeedGenerator re = new RandomSeedGenerator();
        return;
}
}

RandomSeedGenerator 是 colt.jar 库中的一个类,我的 lib 文件夹下有 jar 文件。

我正在使用 ant 构建项目,并且有以下清单文件,我在其中设置类路径:

Manifest-Version: 1.0
Main-Class: edu.umass.TestDataService
Name: edu/umass/TestDataService/Version.class
Class-Path: lib/colt.jar

当我从运行 Red Hat Linux 的 VMWare shell 运行代码时,我收到此异常:

[root@localhost] java -jar app.jar

Hello World DAI!
Exception in thread "main" java.lang.NoClassDefFoundError: cern/jet/random/engine/RandomSeedGenerator
at edu.umass.TestDataService.main (Unknown Source)
Caused by: java.long.ClassNotFoundException: cern.jet.random.engine.RandomSeedGenerator

正如最后一点,一切似乎都使用 eclipse 在 Windows 上工作正常,但在虚拟机上似乎没有任何工作。有什么想法吗?

I am trying to run simple java code on VMWare Workstation. I have the following simple test Main file:

import cern.jet.random.engine.RandomSeedGenerator;;

public class TestDataService {

    //private static Logger logger = Logger.getLogger(TestDataService.class);
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.out.println("Hello World DAI!");

        // Input some data.
        RandomSeedGenerator re = new RandomSeedGenerator();
        return;
}
}

RandomSeedGenerator is a class in colt.jar library, and I have the jar file under my lib folder.

I am building the project with ant, and I have the following manifest file where I set the classpath:

Manifest-Version: 1.0
Main-Class: edu.umass.TestDataService
Name: edu/umass/TestDataService/Version.class
Class-Path: lib/colt.jar

When I run the code from the VMWare shell which runs Red Hat Linux, I get this Exception:

[root@localhost] java -jar app.jar

Hello World DAI!
Exception in thread "main" java.lang.NoClassDefFoundError: cern/jet/random/engine/RandomSeedGenerator
at edu.umass.TestDataService.main (Unknown Source)
Caused by: java.long.ClassNotFoundException: cern.jet.random.engine.RandomSeedGenerator

Just as a final note, everything seems to work fine on windows with eclipse, but nothing seems to work on the virtual machine. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妳是的陽光 2024-11-13 03:41:21

您是否在虚拟机上安装了应用程序所需的 jar 文件?

您是否正确配置了 CLASS_PATH?

Did you install the jar files required by your application on the VMs?

Did you configured CLASS_PATH correctly?

奶气 2024-11-13 03:41:21

我怀疑jvm或vm有问题。问题在于你如何管理班级。具体来说你如何设置类路径。试试这个:

导航到放置 colt.jar 的位置。通过输入 pwd 获取当前工作目录。使用它来使用 colt.jar 的绝对路径构建运行命令。

所以最终你应该运行(从包含你的jar的目录)这样的东西:

java -cp /the/full/path/to/lib/colt.jar -jar app.jar

一旦你完成了这项工作,你就可以尝试找出正确的相对路径是什么。然后你就可以做

java -cp a/relativel/path/to/lib/colt.jar -jar app.jar

I doubt there is an issue with the jvm or the vm. The problem is going to be in how you run the class. Specifically how your setting the classpath. Try this:

Navigate to where you've placed colt.jar. Get the present working directory by typing in pwd. Use this to construct the run command using the absolute path to colt.jar.

So eventually you should be running (from the directory containing your jar) something like this:

java -cp /the/full/path/to/lib/colt.jar -jar app.jar

Once you've got that work you can then try and figure out what the correct relative path is. and then you'll be able to do

java -cp a/relativel/path/to/lib/colt.jar -jar app.jar
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文