how to add external jar to maven webapp project

后端 未结 7 818
清歌不尽
清歌不尽 2020-12-31 12:26

I have a Spring roo project (basically a maven project). I want to add dropbox sdk to the project, problem is it\'s not in maven. I added the following files



        
7条回答
  •  心在旅途
    2020-12-31 13:05

    I don't recommend this approach, but you could add some POM configuration to install the 3rd-party dependency in a separate profile:

    
        
            install-dependencies
            
                
                    
                        maven-install-plugin
                        2.3.1
                        
                            
                                install-dropbox-sdk
                                validate
                                
                                    install-file
                                
                                
                                    com.dropbox
                                    dropbox-sdk
                                    1.3.1
                                    src/main/lib/dropbox-java-sdk-1.3.1.jar
                                    jar
                                
                            
                        
                    
                
            
        
    
        
            build
            
                true
            
    
            
                
                    com.dropbox
                    dropbox-sdk
                    1.3.1
                
            
        
    
    

    There are two profiles here: install-dependencies and build. The first installs the dropbox-sdk dependency into your Maven repository and needs to be run once on every machine as follows:

    mvn -Pinstall-dependencies validate
    

    The second is enabled by default, and adds the Dropbox SDK as a dependency.

    To be honest though, this isn't much better than running

    mvn install:install-file -Dfile=src/main/lib/dropbox-java-sdk-1.3.1.jar -DgroupId=com.dropbox -DartifactId=dropbox-sdk -Dversion=1.3.1 -Dpackaging=jar
    

    on every machine.

    The other downside of this approach is that you'll have to add all dependencies of the dropbox-sdk to your build as well- whereas if it is done properly by adding the JAR and a POM to a repository server, then Maven will calculate the transitive dependencies properly.

提交回复
热议问题