5

I know this is a common issue, but i've tried many things to make this work.

Main Class name: Test

I've included a MANIFEST.MF with Main-Class attribute, as follows:

  1. Main-Class: src.client.Test
  2. Main-Class: classes.client.Test
  3. Main-Class: client.Test
  4. Main-Class: Test

None of the above worked.(the jar is located in the deploy dir )

This is the contents of my project: enter image description here

On my deployment profile i have included:

  1. MANIFEST.MF
  2. lib directory
  3. All the merged content of the file's group contributor (Test.class , an external jar that i'm using )

Note: I'm using JDeveloper 12c IDE


Related posts i've tried but i couldn't make it work:

Could not find or load main class with a Jar File

Cannot run jar file: Could not find or load main class Hello

Phill Alexakis
  • 1,449
  • 1
  • 12
  • 31
  • Can you please post the exact exception you get? May be its an unresolved dependency that causing main to fail loading? Will need full stack trace – Anand Vaidya Oct 29 '19 at 16:57

2 Answers2

1

You jar should have the following structure:

  yourjar.jar
  |-client
  | |-Test.class
  |-com
  | |-external
  |   |-package
  |     |-SomeClass.class
  |     |-SomeOtherClass.class
  | ....
  |-META-INF
    |-MANIFEST.MF

And your MANIFEST.MF file should contain

Main-Class: client.test

StephaneM
  • 4,779
  • 1
  • 16
  • 33
  • Should i pack it by using `java` command? I'm trying to do it with an automated way through the IDE – Phill Alexakis Oct 23 '19 at 16:36
  • still, it doesn't recognise the `Main-Class` , i have the exact structure you mentioned (except the `com/external/package` etc) – Phill Alexakis Oct 23 '19 at 16:42
  • This is really odd, if i extract the `jar` in the same `dir` and do `java -jar myjar.jar` it runs! It works if only the `external.jar` and `myjar.jar` are in the same `dir` . How is this possible? (even if i delete `Test.class` from my `dir` it stills runs my `myjar.jar`( `myjar.jar` contains `external.jar` , `client` , `META-INF`) – Phill Alexakis Oct 23 '19 at 17:31
1

I mentioned correctly the Main-Class attribute, although the Class-Path was wrong.


The structure of the .jar file is the following:

myjar/client/Test.class

myjar/META-INF/MANIFEST.MF

myjar/myexternal.jar


I Had to mention myexternal.jar in my MANIFEST.MF as follows:

Correct: Class-Path: ../myexternal.jar

Wrong : Class-Path: myexternal.jar

I don't know if that is making any sense, i shouldn't get an exception loading the main class because of the wrong way of mentioning myexternal.jar

Nevertheless this fixed it!

Phill Alexakis
  • 1,449
  • 1
  • 12
  • 31
  • From what I understand both are wrong. It's simply not possible to specify a jar contained in other jar that way for plain java. Maybe there is a working ..\myexternal.jar existing relative to the code base from which the containing application was loaded? – EOhm Oct 31 '19 at 12:24