Monday 7 January 2013

How to build jar with Maven containing nothing but dependencies

Today I came across a problem where I had to split my project into two jars: one containing my project's classes and the other one with dependencies. The former got changed every time I made some changes in the source files. The latter was basically constant throughout the development. This facilitates me the deployment of my application. Previously after each improvement I had to transfer a big-fat-and-ugly *-jar-with-dependencies.jar and that took ten good minutes as the file weights 189MB. It turned out that dependencies weight.. 189MB and my compiled classes 45KB. Below the xml that I placed in src/main/resources/assemblies/only-deps.xml

  
  only-deps
  
    jar
  
  false
  
    
      /
      false
      true
      runtime
    
  

and a profile that I added to the main pom.xml:
        
            only-deps
            
                
                    
                        org.apache.maven.plugins
                        maven-assembly-plugin
                        
                            
                                src/main/resources/assemblies/only-deps.xml
                            
                        
                        
                            
                                package
                                create-my-bundle
                                
                                    single
                                
                            
                        
                    
                
            
        
Run the whole thing with mvn install -P only-deps.

1 comment:

  1. There is a lot of information in your article. This information is up-to-date. You keep giving us good information. Recently, I published a post about Introduction Of CPS Or Kohi Click Speed Test. If you want to increase your click speed through the click speed test, read the article given. Are you interested to know about Clicking Speed, Clicking Type, then see the given article? See my latest CPS Test - Check Clicks per Second article. Feel free to comment.

    ReplyDelete