maven项目打包额外lib目录

maven项目依赖了几个额外的jar包一直都无法打进最终jar,不知道哪里出了问题.一直对这块不甚清楚,就大概梳理一下

默认打包方式:

  maven项目下,默认编译目录为

src/main/java和src/test/java 

  和

src/main/resouces和src/test/resources

所以按照默认条件,其他目录的东西都不会被打进去,而且这些目录底下的一些非符合条件文件也不会被打包,java目录下只会打包.java文件,具体看target/classes目录下的文件即可

除非特别指定,否则,打包时将会把target/classes目录下的东西打包成jar

那么问题来了,怎么把想要加入打包的东西弄到目录target/classes下呢

这个是由resource决定的,当需要将一些特殊文件打包时,需要额外配置resource标签:

  比如经常碰到的在src/main/java中写的xml需要打包到jar,需要配置:

    
           
            
                
                    
                src/main/java    
 
                     
                 
                      **/*.xml
                   
                     
                      
                  
                    **/*.yaml  
                  
 
                      
                      
   
                    
                true     
                          
             
  

  所以,如果要加入jar包同样需要加入resource


                lib
                BOOT-INF/lib/
                
                    **/*.jar
                
            

把lib目录下的所有jar都加入到resource中,就能看到target/class目录下有这些jar包啦

不过jar包有了,还是会报错:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project op-realname-test: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:972)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 21 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

编译失败了,并且是因为缺少类引起的,而且是maven-compiler-plugin插件报错,检查发现,由于加入了新的资源,打包插件中也需要加入相应包路径:


                maven-compiler-plugin
                
                    1.8
                    1.8
                    UTF-8
                    
                        
                        ${project.basedir}/lib
                    
                
            

done

你可能感兴趣的:(maven项目打包额外lib目录)