Wrong Manifest.mf in IntelliJ IDEA created .jar

前端 未结 7 1897
-上瘾入骨i
-上瘾入骨i 2020-11-28 02:08

I\'m trying to package a project using OptaPlanner 6.0.1 libraries into a .jar through IntelliJ IDEA\'s jar artifact but instead of my manifest.mf containing the standard

相关标签:
7条回答
  • 2020-11-28 02:09

    If you want to specify Main Class, you have to add this plugin to pom.xml:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>Form</mainClass>
                </manifest>
            </archive>
        </configuration>
    </plugin>
    
    0 讨论(0)
  • 2020-11-28 02:15

    I had the same problem.

    Make sure your MANIFEST.MF is in:

    src/main/resources/META_INF/
    

    NOT

    src/main/java/META_INF/
    
    0 讨论(0)
  • 2020-11-28 02:25

    To fix:

    1. File > Project Structure
    2. Under Project Settings on the left, select "Artifacts"
    3. Find the JAR definition In the middle pane and select it
    4. In the left pane of the "Output Layout" tab find the jar file in the list and select it
    5. At the bottom, click the "Use Existing Manifest" button and select the manifest file that is in your project source.
    6. Click OK and run the build
    0 讨论(0)
  • 2020-11-28 02:26

    I had a similar problem.

    The problem was in file pom.xml.

    <archive>
      <manifestEntries>
        <Dependencies>one.jar,
                      two.rar, 
                      other.jar
        </Dependencies>
      </manifestEntries>
    </archive>
    

    I do not know for what reason this code works in eclipse, but not in IntelliJ

    This it correct.

    <archive>
      <manifestEntries>
        <Dependencies>one.jar, two.rar, other.jar</Dependencies>
      </manifestEntries>
    </archive>
    

    Manifest.mf worked!!!

    I hope this helps.

    0 讨论(0)
  • 2020-11-28 02:27

    To have no problem like Manifest, you should have a directory named "META-INF" in "src" directory. So, create it and put a file named "MANIFEST.MF" in it with the following contents:

    Manifest-Version: 1.0
    Main-Class: <packageName>.Main
    

    Not to forgot to replace the package's name containing Main class above!

    0 讨论(0)
  • 2020-11-28 02:30

    There are several ways to generate executable jars. Using IntelliJ's GUI feature is one good way. Another way is to use Maven (or similarly in gradle, buildr, etc) which is build-server friendly:

    It's more or less copy pasteable from the optaplanner examples maven build:

    1. The end-user jar (optaplanner-examples-*.jar) must include the classpath of its dependencies in its manifest.
    2. The sh and bat script must then run that jar with accordingly.
    0 讨论(0)
提交回复
热议问题