4

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?

Community
  • 1
  • 1
fsw
  • 3,595
  • 3
  • 20
  • 34
  • You also need include into class path desired jar file – Andremoniy Jan 18 '13 at 13:46
  • hmm isnt "-cp test.jar" doing so? ClassA is also in test.jar – fsw Jan 18 '13 at 13:47
  • 1
    It seems, that ClassA used inside it links to some class `com/ibm/OS4690/FlexosException`, which is located in another library – Andremoniy Jan 18 '13 at 13:48
  • also i wonder why it does not fail on "import something.something.something.ClassA" but fails when it tries to call public static method from ClassA maybe this can be the clue – fsw Jan 18 '13 at 13:48
  • 1
    I don't know what is `ClassA`, also where from you got it. But in this particular case Java complains to absence of this specific class `com/ibm/OS4690/FlexosException`. – Andremoniy Jan 18 '13 at 13:51
  • Thanks a lot! this "ClassIWantToRun.java:7" misled me into thinking ClassA cant be found. Indeed ClassA.class has "import com.ibm.OS4690.FlexosException" at the very top and this is what's missing. – fsw Jan 18 '13 at 14:04
  • @fsw please help me to solve my issue http://stackoverflow.com/questions/17673917/confused-to-make-sitemap-using-php-coding – user2173803 Jul 16 '13 at 19:14

3 Answers3

6

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
maksim_khokhlov
  • 794
  • 5
  • 8
  • 1
    Thanks! Quick research showed that this jar is supposed to be running on http://en.wikipedia.org/wiki/IBM_4690_OS So i am not yet sure if i will be able to run it, but this is the correct answer to my problem. – fsw Jan 18 '13 at 14:09
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.

Daniel
  • 958
  • 5
  • 17
  • indeed. as noted in comment to accepted answer this jar (i haven't built it. just wanted to run it) was intended to run on OS4690. thanks – fsw Nov 01 '13 at 20:07
0
java -cp test.jar ClassIWantToRun

Is importing the JAR containing the class you want to run. You should as well import the JAR that includes ClassA on your classpath.

In your case, I guess it is the JAR that contains com/ibm/OS4690/FlexosException that needs to be on your classpath

cowls
  • 24,013
  • 8
  • 48
  • 78