开发者

Running java code on VMWare with references to external jar files

开发者 https://www.devze.com 2023-03-05 02:21 出处:网络
I am trying to run simple java code on VMWare Workstation. I have the following simple test Main file:

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 fi开发者_JS百科ne on windows with eclipse, but nothing seems to work on the virtual machine. Any ideas?


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

Did you configured CLASS_PATH correctly?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消