maven install 和 maven build和install的区别

利用MAVEN打包时,如何包含更多的资源文件 -
- ITeye技术网站
首先,来看下MAVENx项目标准的目录结构:
一般情况下,我们用到的资源文件(各种xml,properites,xsd文件等)都放在src/main/resources下面,利用maven打包时,maven能把这些资源文件打包到相应的jar或者war里。
有时候,比如mybatis的mapper.xml文件,我们习惯把它和Mapper.java放一起,都在src/main/java下面,这样利用maven打包时,就需要修改pom.xml文件,来把mapper.xml文件一起打包进jar或者war里了,否则,这些文件不会被打包的。(maven认为src/main/java只是java的源代码路径)。网络上有很多方法,我大概试了下,几种方法都可以,可以任选一种即可。
方法1,其中**/*这样的写法,是为了保证各级子目录下的资源文件被打包。
&finalName&test&/finalName&
这样也可以把所有的xml文件,打包到相应位置。
&resources&
&resource&
&directory&src/main/resources&/directory&
&includes&
&include&**/*.properties&/include&
&include&**/*.xml&/include&
&include&**/*.tld&/include&
&/includes&
&filtering&false&/filtering&
&/resource&
&resource&
&directory&src/main/java&/directory&
&includes&
&include&**/*.properties&/include&
&include&**/*.xml&/include&
&include&**/*.tld&/include&
&/includes&
&filtering&false&/filtering&
&/resource&
&/resources&
方法2,利用build-helper-maven-plugin插件
&/plugins&
此plugin可以用
利用此plugin,把源代码中的xml文件,
打包到相应位置,这里主要是为了打包Mybatis的mapper.xml文件
&groupId&org.codehaus.mojo&/groupId&
&artifactId&build-helper-maven-plugin&/artifactId&
&version&1.8&/version&
&executions&
&execution&
&id&add-resource&/id&
&phase&generate-resources&/phase&
&goal&add-resource&/goal&
&configuration&
&resources&
&resource&
&directory&src/main/java&/directory&
&includes&
&include&**/*.xml&/include&
&/includes&
&/resource&
&/resources&
&/configuration&
&/execution&
&/executions&
&/plugins&
方法3,利用maven-resources-plugin插件
&/plugins&
此plugin可以用
利用此plugin,把源代码中的xml文件,打包到相应位置,
这里主要是为了打包Mybatis的mapper.xml文件
&artifactId&maven-resources-plugin&/artifactId&
&version&2.5&/version&
&executions&
&execution&
&id&copy-xmls&/id&
&phase&process-sources&/phase&
&goal&copy-resources&/goal&
&configuration&
&outputDirectory&${basedir}/target/classes&/outputDirectory&
&resources&
&resource&
&directory&${basedir}/src/main/java&/directory&
&includes&
&include&**/*.xml&/include&
&/includes&
&/resource&
&/resources&
&/configuration&
&/execution&
&/executions&
&/plugins&
浏览 37225
浏览: 162198 次
来自: 深圳
如果你maven项目分了模块,比如分了一个 projec-da ...
yangcheng33 写道赞,有个地方要纠正下 &in ...
赞,有个地方要纠正下 &includes&
非常棒,因为从来没写过日志,要几小时上手,官网将的一塌糊涂。这 ...Maven学习总结:几个常用的maven插件 - 点缀星辰 - ITeye技术网站
博客分类:
我们使用maven做一些日常的工作开发的时候,无非是想利用这个工具带来的一些便利。比如它带来的依赖管理,方便我们打包和部署运行。这里几个常见的插件就是和这些工程中常用的步骤相关。
maven-compile-plugin
这个插件就如同名字所显示的这样,用来编译源代码的。最开始碰到这个插件是在于有的时候我们下载了一些工程需要编译的时候,比如我们输入命令:mvn install ,但是系统编译的时候报错了,错误的信息如下:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project springJMS: Compilation failure: Compilation failure:
[ERROR] /home/frank/programcode/SpringJMSSample/src/main/java/huangbowen/net/jms/MessageSender.java:[6,1] error: annotations are not supported in -source 1.3
[ERROR] (use -source 5 or higher to enable annotations)
[ERROR] /home/frank/programcode/SpringJMSSample/src/main/java/net/EmbedBrokerApp.java:[5,7] error: static import declarations are not supported in -source 1.3
[ERROR] -& [Help 1]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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
从错误显示的信息我们就可以看出,这是因为编译的时候是默认用的javac 1.3版本的,太老了不支持代码里的特性。为了修改这个问题,我们需要设置编译器的版本。解决这个问题的办法也比较简单,就是直接在后面的插件部分增加如下的插件,比如如下部分,将编译器的版本设定为1.6:
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-compiler-plugin&/artifactId&
&version&2.3.2&/version&
&configuration&
&source&1.6&/source&
&target&1.6&/target&
&/configuration&
&/plugins&
exec-maven-plugin
我们写一些java console相关的程序时,比较头疼的一点就是真正要通过命令行将打包后的程序执行起来还是比较麻烦的。我们需要在命令行里敲如下的命令:java -cp ***.jar:**.jar:/**/ 。因为要将classpath目录以及引用的类库都加入进来,并指定运行的入口,这样子每次用手工的方式来处理实在是太繁琐也比较容易出错。所以一种办法就是利用这个插件,通过一些基本的配置,我们可以执行起代码来的时候很方便。一个典型的配置如下:
&groupId&org.codehaus.mojo&/groupId&
&artifactId&exec-maven-plugin&/artifactId&
&version&1.2.1&/version&
&executions&
&execution&
&goal&java&/goal&
&/execution&
&/executions&
&configuration&
&mainClass&com.yunzero.App&/mainClass&
&/configuration&
如果我们运行的时候需要提供一些输入的参数,也可以通过configuration的元素里添加。这样后续要执行这个程序时,我们只需要在命令行执行如下命令:mvn exec:java ,然后程序就可以运行起来了。
maven-dependency-plugin
  还有一个比较常用的插件就是这个。我们在IDE的环境里编译和执行代码的时候,那是直接引用一些类库。但是在我们实际部署的环境里,那边很可能就一个java执行环境,不可能有源代码和IDE。这个时候,我们需要将源代码编译打包。这个时候的一个问题就是如果我们引用的库很多的话,我们希望能够把他们统一打包到一个目录下,比如lib文件夹。这样部署执行的时候只需要将编译生成的程序jar包和依赖包文件夹拷到特定目录去执行。要实现这个效果也比较容易:
&artifactId&maven-dependency-plugin&/artifactId&
&executions&
&execution&
&phase&install&/phase&
&goal&copy-dependencies&/goal&
&configuration&
&outputDirectory&${project.build.directory}/lib&/outputDirectory&
&/configuration&
&/execution&
&/executions&
从前面的配置里我们可以看到,插件的执行被配置到install这个阶段。这样,当我们执行命令:mvn clean install 的时候,会发现对应的target目录里生成了对应的jar包和依赖包。
浏览 23995
浏览: 765306 次
来自: 北京
去重情况很给力。
king_qing 写道 our company's proj ...
enctype=&multipart/form-da ...08:10 提问
求大神!当我运行maven clean install build是出现如下错误
[INFO] Scanning for projects...
[WARNING] Some problems were encountered while building the effective model for com.bcd:test:war:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 20, column 21
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[INFO] ------------------------------------------------------------------------
[INFO] Building test Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test ---
[INFO] Downloading:
四月 14, :20 上午 org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
信息: I/O exception (org.apache.maven.wagon.providers.http.httpclient.NoHttpResponseException) caught when processing request: The target server failed to respond
四月 14, :20 上午 org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
信息: Retrying request
按时间排序
看看你maven环境变量有没有配置
maven插件版本问题吧
看看你的环境变量以及配置文件的问题
其他相似问题

我要回帖

更多关于 yum install maven 的文章

 

随机推荐