0

I had developed a standalone program which don't have any GUI, it's only use in the linux machine(without any GUI). So, i converted my java source code into jar file using the following command

jar cfm hardcoded.jar manifest.txt hardcoded.class


The jar file was successfully created but when i try to execute the jar file in the terminal,i get this error

no main manifest attribute, in hardcoded.jar


Some of the information said that the problem due to the manifest file but i can't figure out where is the root cause because i am very new to java on linux,Some people said that the package also need to include but where can i find my package name?.My manifest file is showed as the following

Manifest-Version: 1.0
Class-Path: ./ commons-logging-1.1.2.jar httpclient-4.5.2.jar htt
 pcore-4.4.1.jar java-json.jar java-rt-jar-stubs-1.5.0.jar javax-ssl-1
 _1.jar joda-time-2.2.jar
Class-Path: .
Main-Class: hardcoded  

As you can see my manifest file, i had some others external library, i know eclipse have the build in function to solve this issue, how i need to solve it in linux environment ?

attack
  • 103
  • 1
  • 11
  • Are you using all of those dependencies? If so, I would recommend maven to manage them. If not, know that is not how you add jars (or manipulate the class-path). – Elliott Frisch Jun 19 '17 at 03:43
  • @ElliottFrisch , yes, i need all those library but there's will only one class file – attack Jun 19 '17 at 03:45
  • Can you try `java -cp hardcoded.jar hardcoded` and see what happens? – Dat Huynh Jun 19 '17 at 03:47
  • The JRE may may not like the class been in the root/default pacakge – MadProgrammer Jun 19 '17 at 03:47
  • You should get a good solution in this thread. https://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute – Udara Gunathilake Jun 19 '17 at 03:47
  • @DatHuynh, it's show me this error message "Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ssl/TrustStrategy " – attack Jun 19 '17 at 03:51
  • @UdaraGunathilake, that is the solution i had refer before but can't hundred percent get what they mean, this is my first time using text editor to develop java,i used eclipse before this – attack Jun 19 '17 at 03:53
  • Does your `hardcoded` class have a package name? – Dat Huynh Jun 19 '17 at 04:18
  • @DatHuynh, no any package name – attack Jun 19 '17 at 04:24
  • In your manifest file, make sure your `Class-Path`s are right, it seems like it's messed up somehow (hence the `Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ssl/TrustStrategy`). Maybe try full paths? – Dat Huynh Jun 19 '17 at 04:47
  • @MadProgrammer, can you explain it more detail ? – attack Jun 20 '17 at 01:52
  • @DatHuynh, i added in the full path for my library file,it's still look the same, please refer to this link (http://codepad.org/lzSTcB5B) for my new updated manifest – attack Jun 20 '17 at 01:54

0 Answers0