running specific class main function from jar file. import seems not working

20,430

Solution 1

The exception indicates that you need to add some other JARs into the classpath. Classes in your test.jar depend on other classes. e.g. on com.ibm.OS4690.FlexosException.

You can try searching for another JAR file (in the same place you took your test.jar) so that it will contain the FlexosException.class file. Once you find it, run your test.jar as

java -cp test.jar;<path_to_another_jar_here> ClassIWantToRun

Solution 2

You won't be able to run your program outside an OS4690 environment because you're depending on internal OS4690 libraries. You might find the jar you need if you have access to an OS4690 installation, but at the end those jars use platform dependant libraries. Try to avoid using those dependencies if you're not developing for that specific platform.

Share:
20,430
fsw
Author by

fsw

I like cake and collecting virtual internet reputation points. my avatar is probably not my real face.

Updated on November 02, 2020

Comments

  • fsw
    fsw over 3 years

    I have a jar file without its main class specified in manifest. So i followed an answer given here:

    How to run a class from Jar which is not the Main-Class in its Manifest file

    It seems to try to run main from this class. However it looks like importing some other class from this jar file is broken for some reason.

    Here is the minimized version of my problem:

    jar tf test.jar
    

    gives:

    META-INF/
    META-INF/MANIFEST.MF
    ClassIWantToRun.class
    something/
    something/something/
    something/something/something/ClassA.class
    

    Sources of ClassIWantToRun.class viewed with jd-gui seems to be:

    import something.something.something.ClassA;
    
    public class ClassIWantToRun
    {
        public static void main(String[] args)
        {
            int x = ClassA.comeMethod();
        }
    }
    

    Running this with:

    java -cp test.jar ClassIWantToRun
    

    gives me the exception:

    Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/OS4690/FlexosException
        at ClassIWantToRun.main(ClassIWantToRun.java:7)
    Caused by: java.lang.ClassNotFoundException: com.ibm.OS4690.FlexosException
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
        ... 1 more
    

    I know only basics of Java but it seems that ClassA can not be found even with the line: import something.something.something.ClassA How can i make this run?