Why dependencies do not accompany the made package by Maven?

前端 未结 3 1983
悲哀的现实
悲哀的现实 2021-01-27 06:40

I\'ve followed the simplest maven example and made the following pom.xml file:



        
3条回答
  •  佛祖请我去吃肉
    2021-01-27 07:40

    The problem is, you are setting the classpath to a single .jar file, thus java command can not find the dependency. (json-simple-1.1.1.jar in your case..)

    You can tell maven to include the dependencies in target folder that you compiling your class to.

    This is done by the following change in the pom.xml:

    
      
        
          maven-dependency-plugin
          
            
              install
              
                copy-dependencies
              
              
                ${project.build.directory}/lib
              
            
          
        
      
    
    

    Now try mvn package (or mvn clean install, I am not sure..) and you will see in /target/lib the dependencies are copied.

    Run your application like this:

    java -cp target/my-app-1.0-SNAPSHOT.jar:target/lib/json-simple-1.1.1.jar com.mycompany.app.App
    {"hello":"world"}
    

提交回复
热议问题