How to build jars from IntelliJ properly?

前端 未结 20 2456
盖世英雄少女心
盖世英雄少女心 2020-11-22 01:14

I have a project that contains a single module, and some dependencies. I\'d like to create a jar, in a separate directory, that contains the compiled module. In addition, I\

相关标签:
20条回答
  • 2020-11-22 01:42

    I was trying to build a jar from a multi-module Kotlin app and was getting the notorious 'no main manifest attribute' error. Creating the manifest directory in src/main/resources didn't work either.

    Instead, it works when creating it in src directly: src/META-INF/MANIFEST.MF.

    0 讨论(0)
  • 2020-11-22 01:43

    It is probably little bit late, but I managed to solve it this way -> open with winrar and delete ECLIPSEF.RSA and ECLIPSEF.SF in META-INF folder, moreover put "Main-class: main_class_name" (without ".class") in MANIFEST.MF. Make sure that you pressed "Enter" twice after the last line, otherwise it won't work.

    0 讨论(0)
  • 2020-11-22 01:43

    If you are working on spring/mvn project you can use this command:

    mvn package -DskipTests
    

    The jar file will be saved on target directoy.

    0 讨论(0)
  • 2020-11-22 01:44

    My problem was this: I used Intellij IDEA (tried different versions) + Gradle. When I compiled the project and builded artifacf jar, as indicated in the above responses, I received an error - "no main manifest attrubute ..."

    This solution worked for me (special thanks to Thilina Ashen Gamage (see above) for tip):

    Excerpt - if you use external libraries and build a project through Project Settings - Artifacts - Add (+) - Jar - From modules with dependencies, then probably because of a program bug the META-INF folder with MANIFEST_MF file not including to jar. To avoid it create EMPTY jar file.

    Project Settings - Artifacts - Add (+) - Jar - EMPTY JAR. META-INF folder will added to resources folder. Then select your main class. You will see following jar structure: Note the presence of a folder META-INF Then you can build your project and build artifacts. This solution worked for javaFX applications too.

    0 讨论(0)
  • 2020-11-22 01:47

    For those that benefit from images as I do:

    File -> Project Structure

    0 讨论(0)
  • 2020-11-22 01:48

    With Maven you can use this plugin:

     <build>
        <plugins>
    
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>[path you class main]</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase> 
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
    0 讨论(0)
提交回复
热议问题