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

前端 未结 10 1781
我在风中等你
我在风中等你 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:51

    In 7.3 just enable Properties/Build/Package/Copy Dependent Libraries and main class will be added to manifest when building depending on selected target.

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

    Adding manifest.file=manifest.mf into project.properties and creating manifest.mf file in the project directory works fine in NB 6.9 and should work also in NB 6.8.

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

    The real problem is how Netbeans JARs its projects. The "Class-Path:" in the Manifest file is unnecessary when actually publishing your program for others to use. If you have an external Library added in Netbeans it acts as a package. I suggest you use a program like WINRAR to view the files within the jar and add your libraries as packages directly into the jar file.

    How the inside of the jar file should look:

    MyProject.jar
    
        Manifest.MF
             Main-Class: mainClassFolder.Mainclass
    
        mainClassFolder
             Mainclass.class
    
        packageFolder
             IamUselessWithoutMain.class
    
    0 讨论(0)
  • 2020-11-29 11:00

    Brother you don't need to set class path just follow these simple steps (I use Apache NetBeans)

    Steps:

    1. extract the jar file which you want to add in your project.

    2. only copy those packages (folder) which you need in the project. (do not copy manifest file)

    3. open the main project jar file(dist/file.jar) with WinRAR.

    4. paste that folder or package in the main project jar file.

    5. Those packages work 100% in your project.

    warning: Do not make any changes in the manifest file.

    Another method:

    • In my case lib folder present outside the dist(main jar file) folder.
    • we need to move lib folder in dist folder.then we set class path from manifest.mf file of main jar file.

      Edit the manifest.mf And ADD this type of line

    • Class-Path: lib\foldername\jarfilename.jar lib\foldername\jarfilename.jar

    Warning: lib folder must be inside the dist folder otherwise jar file do not access your lib folder jar files

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