189 8069 5689

使用maven怎么生成可执行的jar包

使用maven怎么生成可执行的jar包,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

创新互联是一家专业提供揭西企业网站建设,专注与成都网站建设、成都网站设计、H5响应式网站、小程序制作等业务。10年已为揭西众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。

从pom的xsi中可以打开描述pom的schema:

使用maven怎么生成可执行的jar包

可以看到pom中,project的结构:

使用maven怎么生成可执行的jar包

默认的mvn install生成的jar是不带主类入口的,需要在maven-compile-plugin中设置主类,

使用maven怎么生成可执行的jar包


  4.0.0

  com.cetc.di
  hellocetc
  0.0.1-SNAPSHOT
  jar

  hellocetc
  http://maven.apache.org



  
    UTF-8
  

  
    
      junit
      junit
      3.8.1
      test
    
  
  
  




    org.apache.maven.plugins
    maven-jar-plugin
    
        1.8
        1.8
        
            
                com.cetc.di.hellocetc.App
                true
            lib/
            

        
        
        
    

    


  

执行mvn install:

使用maven怎么生成可执行的jar包

在target目录中,发现jar包已经生成:

使用maven怎么生成可执行的jar包

用java decompiler,可以看到manifest中已经加入了MainClass:

使用maven怎么生成可执行的jar包

使用mvn help:effective-pom可以看到pom.xml的完整结构(包括继承而来的属性):

使用maven怎么生成可执行的jar包

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hellocetc 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-help-plugin:2.2:effective-pom (default-cli) @ hellocetc ---
[INFO] 
Effective POMs, after inheritance, interpolation, and profiles are applied:















  4.0.0
  com.cetc.di
  hellocetc
  0.0.1-SNAPSHOT
  hellocetc
  http://maven.apache.org
  
    UTF-8
  
  
    
      junit
      junit
      3.8.1
      test
    
  
  
    
      
        false
      
      central
      Central Repository
      https://repo.maven.apache.org/maven2
    
  
  
    
      
        never
      
      
        false
      
      central
      Central Repository
      https://repo.maven.apache.org/maven2
    
  
  
    D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\main\java
    D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\main\scripts
    D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\test\java
    D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\classes
    D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\test-classes
    
      
        D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\main\resources
      
    
    
      
        D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\test\resources
      
    
    D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target
    hellocetc-0.0.1-SNAPSHOT
    
      
        
          maven-antrun-plugin
          1.3
        
        
          maven-assembly-plugin
          2.2-beta-5
        
        
          maven-dependency-plugin
          2.8
        
        
          maven-release-plugin
          2.3.2
        
        
          maven-jar-plugin
          2.4
          
            1.8
            1.8
            
              
                com.cetc.di.hellocetc.App
                true
                lib/
              
            
            
          
        
      
    
    
      
        maven-clean-plugin
        2.5
        
          
            default-clean
            clean
            
              clean
            
          
        
      
      
        maven-resources-plugin
        2.6
        
          
            default-testResources
            process-test-resources
            
              testResources
            
          
          
            default-resources
            process-resources
            
              resources
            
          
        
      
      
        maven-jar-plugin
        2.4
        
          
            default-jar
            package
            
              jar
            
            
              1.8
              1.8
              
                
                  com.cetc.di.hellocetc.App
                  true
                  lib/
                
              
              
            
          
        
        
          1.8
          1.8
          
            
              com.cetc.di.hellocetc.App
              true
              lib/
            
          
          
        
      
      
        maven-compiler-plugin
        3.1
        
          
            default-compile
            compile
            
              compile
            
          
          
            default-testCompile
            test-compile
            
              testCompile
            
          
        
      
      
        maven-surefire-plugin
        2.12.4
        
          
            default-test
            test
            
              test
            
          
        
      
      
        maven-install-plugin
        2.4
        
          
            default-install
            install
            
              install
            
          
        
      
      
        maven-deploy-plugin
        2.7
        
          
            default-deploy
            deploy
            
              deploy
            
          
        
      
      
        maven-site-plugin
        3.3
        
          
            default-site
            site
            
              site
            
            
              D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site
              
                
                  org.apache.maven.plugins
                  maven-project-info-reports-plugin
                
              
            
          
          
            default-deploy
            site-deploy
            
              deploy
            
            
              D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site
              
                
                  org.apache.maven.plugins
                  maven-project-info-reports-plugin
                
              
            
          
        
        
          D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site
          
            
              org.apache.maven.plugins
              maven-project-info-reports-plugin
            
          
        
      
    
  
  
    D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site
  

看完上述内容,你们掌握使用maven怎么生成可执行的jar包的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


当前标题:使用maven怎么生成可执行的jar包
当前链接:http://cdxtjz.cn/article/goesgp.html

其他资讯