skip to Main Content

I have made a Java Swing application and now I want to export it as an executable jar file. I have created the app in Eclipse, and it has the following structure :

enter image description here

where folder mysqlconnector contains also a jar file. So first I tried following the instructions in this link and created seo.jar, but when I try to execute it from the terminal by java -jar seo.jar I get an error :

Error: Could not find file connectionprops.properties

As the screenshot shows, I tried putting connectionprops.properties in main package, but the same problem remains.

Then I tried making a manifest file named manifest.mf with contents :

Main-Class: bin.main.MainClass   //also tried Main-Class: MainClass

as the structure of my project is :

seo --> bin --> main --> MainClass.class

I placed the manifest.mf in folder seo and I gave the following command in the terminal :

jar -cvfm seo.jar manifest.mf *

but again when executing it from the terminal by java -jar seo.jar I get an error :

Error: Could not find or load main class bin.main.MainClass

What am I doing wrong? Should I change something in my project structure? Is there a problem that I have other jar files inside my project? How can I create the executable jar and execute it successfully?

2

Answers


  1. bin.main is not a package name. You can’t add this to manifest.mf.

    You should add the package name only if you have the main class in the package. If your package is default then put only the main class.

    Main-Class: MainClass 
    
    Login or Signup to reply.
  2. The Manifest Main-Class attribute needs to receive the package path to your Main class. It doesn’t matter what the structure of the project looks like, what matters is the fully qualified package name that you have inside the src/ folder. So in this case, main.MainClass is what you should write there.

    Also, if you receive other errors when trying to read the connectionprops.properties in your program, try to open the file using

    someObject.getClass().getResourceAsStream("connectionprops.properties")
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search