Creating a jar from a maven project in intellij

后端 未结 5 569
广开言路
广开言路 2020-12-25 11:14

I created a new maven project in IntelliJ and set packaging to jar but when I build it, the target folder does not contain a jar. I\'m sure its something really dumb on my p

相关标签:
5条回答
  • 2020-12-25 11:25

    You should build you project using IDEA's Maven Projects view.

    View -> Tool Windows -> Maven Projects

    or open it from left bottom corner menu:

    menu

    And then build your project with maven goals - i.e. package: maven project

    If packaging is set to jar in pom.xml, you will get a jar in target dir.

    0 讨论(0)
  • 2020-12-25 11:26

    Assuming that the screen-shot shows the complete pom file, you are missing the entries that define the artifact. Try adding something like this following immediately after the tag:

      <modelVersion>4.0.0</modelVersion>
      <groupId>com.mycompany.example</groupId>
      <artifactId>stackoverflow-question</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    

    You should end up with stackoverflow-question-0.0.1-SNAPSHOT.jar in your /target directory. You may need to refresh the directory to see it (You certainly have to in Eclipse)

    0 讨论(0)
  • 2020-12-25 11:32

    Go to the maven project and double click clean and package.

    For just do following:

    0 讨论(0)
  • 2020-12-25 11:34

    You need to have "jar" in packaging section of your pom.xml. You can add this before dependencies section:

    <packaging>**jar**</packaging>
    

    Then go to View -> Tool Windows -> Maven and in Maven window expand everything and double click on "package" in Lifecycle section.

    0 讨论(0)
  • 2020-12-25 11:39

    You need the maven jar plugin in order to create a jar

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <classpathPrefix>lib/</classpathPrefix>
                    <mainClass>add your main class</mainClass>
                </manifest>
            </archive>
        </configuration>
    </plugin>
    

    https://maven.apache.org/plugins/maven-jar-plugin/

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