How to setup Main class in manifest file in jar produced by NetBeans project

前端 未结 10 1780
我在风中等你
我在风中等你 2020-11-29 10:25

I have the following problem. I have a Java project in my NetBeans IDE 6.8. When I compile it and it produces a .jar file containing everything possible, the META-INF is not

相关标签:
10条回答
  • 2020-11-29 10:34

    It is simple.

    • Right click on the project
    • Go to Properties
    • Go to Run in Categories tree
    • Set the Main Class in the right side panel.
    • Build the project

    Thats it. Hope this helps.

    0 讨论(0)
  • 2020-11-29 10:36

    Don't hesitate but look into your project files after you have built your project for the first time. Look for a manifest file and choose open with notepad.

    Add the line:

    Main-Class: package.myMainClassName
    

    Where package is your package and myClassName is the class with the main(String[] args) method.

    0 讨论(0)
  • 2020-11-29 10:41

    I read and read and read to figure out why I was getting a class not found error, it turns out the manifest.mf had an error in the line:

    Main-Class: com.example.MainClass
    

    I fixed the error by going to Project Properties dialog (right-click Project Files), then Run and Main Class and corrected whatever Netbeans decided to put here. Netbean inserted the project name instead of the class name. No idea why. Probably inebriated on muratina...

    0 讨论(0)
  • 2020-11-29 10:44

    I'm going to make a summary of the proposed solutions and the one that helped me!

    After reading this bug report: bug in the way NetBeans 6.8 creates the jar for a Java Library Project.

    1. Create a manifest.mf file in my project root

    2. Edit manifest.mf. Mine looked something like this:

      Manifest-Version: 1.0
      Ant-Version: Apache Ant 1.7.1
      Created-By: 16.3-b01 (Sun Microsystems Inc.)
      Main-Class: com.example.MainClass
      Class-Path: lib/lib1.jar lib/lib2.jar
      
    3. Open file /nbproject/project.properties

    4. Add line

      manifest.file=manifest.mf

    5. Clean + Build of project

    Now the .jar is successfully build.

    Thank you very much vkraemer

    0 讨论(0)
  • 2020-11-29 10:46

    This is a problem still as of 7.2.1 . Create a library cause you do not know what it will do if you make it an application & you are screwed.

    Did find how to fix this though. Edit nbproject/project.properties, change the following line to false as shown:

    mkdist.disabled=false

    After this you can change the main class in properties and it will be reflected in manifest.

    0 讨论(0)
  • 2020-11-29 10:51

    It looks like you are running into a bug in the way NetBeans 6.8 creates the jar for a Java Library Project.

    The issue implies that there is a work-around.

    I have not been able to verify that with NB 6.8 and/or NetBeans 6.9-dev...

    You may want to register with the NetBeans.org website/issue tracker and update the issue and add your 'vote'.

    0 讨论(0)
提交回复
热议问题