maven设置打jar包并引入依赖包

--------------------------------------------------------方法一:将jar包和项目打在一起---------------------------------

1.修改pom根节点下packaging属性为jar

2.修改pom根节点下build为:

复制代码

    
        
            
                maven-assembly-plugin
                
                    
                        jar-with-dependencies
                    
                    
                        
                            com.hbase2Redis.Hbase2Redis
                        
                    
                
                
                    
                        make-assembly
                        package
                        
                            single
                        
                    
                
            
        
    

复制代码

3.使用maven install 打包,将在target下生成项目jar包xxx-with-dependencies.jar复制出来,执行java -jar xxx-with-dependencies.jar即可运行。

 

 

--------------------------------------------------------方法二:将jar包和项目分离---------------------------------------

1.修改pom根节点下packaging属性为jar

2.修改pom根节点下build为:

 

复制代码

    
        Hbase2Redis
        
            
                
                    org.eclipse.m2e
                    lifecycle-mapping
                    1.0.0
                    
                        
                            
                                
                                    
                                        org.apache.maven.plugins
                                        maven-dependency-plugin
                                        [2.0,)
                                        
                                            copy-dependencies
                                        
                                    
                                    
                                        
                                    
                                
                            
                        
                    
                
            
        
        
            
                org.apache.maven.plugins
                maven-jar-plugin
                2.4
                
                    
                        
                            true
                            lib/
                            
                            com.hbase2Redis.Hbase2Redis
                        
                    
                
            
            
            
                org.apache.maven.plugins
                maven-dependency-plugin
                
                    
                        copy
                        package
                        
                            copy-dependencies
                        
                        
                            
                                ${project.build.directory}/lib
                            
                        
                    
                
            
        
    

复制代码

3.使用maven install 打包,将在target下生成项目jar包xxx.jar及lib文件夹,将这两者放在同一目录下,执行java -jar xxx.jar即可运行。

转载地址:https://www.cnblogs.com/sheeva/p/5032706.html

你可能感兴趣的:(maven设置打jar包并引入依赖包)