-1

I have three classes, all in the same package. I just need the execption when I run, java -jar jarName.jar

Class1.java

package test;

public class Class1 {

     public static void main(String[] args) throws Exception
       {

     System.out.println("Enter Class1");
     //Class1 bs = new Class1();

     Class2 objClass2 = new Class2();
     objClass2.method1();

     System.out.println("Exit Class1");
   }
 //hello

}

Class2.java

package test;

public class Class2 {

    int exitValue=100;

    public static int doIt() throws Exception{
        System.out.println("Enter doIt");
        int exitValue=10;
        if(exitValue>0) {
            throw new TestInstallException("Got an Exception here!");
        }       

    return 0;
}

public void method1() throws Exception {
    System.out.println("Enter Class2");
    int exitValue = Class2.doIt();
    System.exit(exitValue); 
}

}

TestInstallException.java

package test;

public class TestInstallException extends java.lang.Exception {

    public TestInstallException()
    {
        super();
    }

    public TestInstallException(String s) {
        super(s);
    }

public TestInstallException(String s, Exception e) {
    super(s, e);
}

public TestInstallException(Throwable cause)
{
    super(cause);
}

}

I even modified the manifest file with the below content,

>cat dd/META-INF/MANIFEST.MF
Manifest-Version: 1.0 .
Created-By: 1.8.0_141 (Oracle Corporation) .
Main-Class: test.Class1 .

So, as we can see it has the main class defined. I bundled everthing in a jar file called new.jar. But, when I run java -jar new.jar, I get below exception.

java -jar new.jar
Error: Could not find or load main class test.Class1

jar -tvf test.jar
0 Sat Apr 14 20:17:54 IST 2018 META-INF/ .
89 Sat Apr 14 20:29:48 IST 2018 META-INF/MANIFEST.MF .
562 Sat Apr 14 20:11:02 IST 2018 Class1.class .
760 Sat Apr 14 20:11:06 IST 2018 Class2.class .
542 Sat Apr 14 20:10:50 IST 2018 TestInstallException.class .

Devendra Sahu
  • 15
  • 2
  • 7

1 Answers1

0

The problem is solved, by bundling the class inside the test folder.

test/Class*.class

Also, added this in the manifest
Class-Path: .

Devendra Sahu
  • 15
  • 2
  • 7