Java – run a specific class main function from a jar file Import doesn’t seem to work

I have a jar file that does not specify its main class in the manifest

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

It seems to be trying to run main. From this class However, for some reason, importing other similar files from this jar file seems to have been corrupted

This is a minimal version of my problem:

jar tf test.jar

Get:

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

Classiwanttorun. Viewed with JD GUI The source of class seems to be:

import something.something.something.ClassA;

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

Run this:

java -cp test.jar ClassIWantToRun

Gave me an 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 only know the basics of Java, but it seems that I can't find classA even if I use the following line: import something something. something. ClassA how can I run this?

Solution

This exception indicates that you need to add some other jars to the classpath test. The classes in jar depend on other classes For example, on COM ibm. OS4690. On flexosexception

You can try to search another jar file (where your test. Jar is located) so that it contains flexosexception. Jar Class file When found, run test jar

java -cp test.jar;<path_to_another_jar_here> ClassIWantToRun
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>