Java Maven清理并建立依赖关系

问题描述:

即时通讯仍然是新的Java Maven和依赖关系。请问? 我使用Java Maven创建了一些关于QR码生成器的项目。 当我运行我的项目到Netbeans时,使用qrgen-1.2.jar,core-2.0.jar和javase-2.0.jar。它可以生成任何我想要的QR码。Java Maven清理并建立依赖关系

https://i.stack.imgur.com/U4YCW.png

但是,当我尝试建立与清洁,它不能产生在我的文档/的NetBeansProjects/QRCODE /目标我QR码/ QR码-1.0-SNAPSHOT.JR

这里我的pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.mycompany</groupId> 
<artifactId>QRcode</artifactId> 
<version>1.0-SNAPSHOT</version> 
<packaging>jar</packaging> 
<build> 
    <plugins> 
     <plugin>      
     <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.4</version> 


      <configuration> 
       <archive> 
        <manifest> 
         <addClasspath>true</addClasspath> 
         <mainClass>com.mycompany.qrcode.QRcode</mainClass> 
        </manifest> 
       </archive> 
      </configuration>  
     </plugin> 
    </plugins> 
</build> 
<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <maven.compiler.source>1.8</maven.compiler.source> 
    <maven.compiler.target>1.8</maven.compiler.target> 

</properties> 

<dependencies> 
     <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
     </dependency> 

     <dependency> 
     <groupId>net.glxn</groupId> 
     <artifactId>qrgen</artifactId> 
     <version>1.2</version> 
     </dependency>      

</dependencies> 

根据您的POM,你是不是打包依赖于可执行的JAR文件的产生。这会导致程序在IDE外部运行时失败。

下面是如何使用Maven的大会插件创建一个可执行的JAR,包括你的依赖的例子:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>single</goal> 
      </goals> 
      <configuration> 
       <archive> 
        <manifest> 
         <mainClass>com.mycompany.qrcode.QRcode</mainClass> 
        </manifest> 
       </archive> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

mvn package现在将包括target/QRcode-1.0-SNAPSHOT-jar-with-dependencies.jar,你可以看到输出包括由指定的类你的构建依赖关系。这个插件的link to the documentation

+0

非常感谢您的先生,我的问题解决了。我很感激。 –