- 浏览: 300903 次
- 性别:
- 来自: 东京
-
文章分类
最新评论
-
80后的童年2:
企业级分布式搜索平台Solr视频教程网盘地址:https:// ...
企业级搜索引擎Solr使用入门指南 -
springdata_spring:
apache lucene开源框架demo使用实例教程源代码下 ...
Lucene / Solr 开发经验 -
springdata-jpa:
java web开发分页demo源代码下载:http://ww ...
简易java分页标签 -
zjf_sdnu:
兄弟,script写错了
jqGrid初学备注 -
85600367:
你好,请教一个问题。当进行分布式查询时solr无法查询到Luc ...
Lucene / Solr 开发经验
项目生命周期:process-resources -> compile -> process-classes -> process-test-resources ->
test-compile -> test -> prepare-package -> package
也可单独运行:
mvn resources:resources \
compiler:compile \
resources:testResources \
compiler:testCompile \
surefire:test \
jar:jar
Maven坐标:groupId:artifactId:packaging:version
groupId
团体,公司,小组,组织,项目,或者其它团体。团体标识的约定是,它以创建这个项目的组织名称的逆向域名(reverse domain name)开头。来自Sonatype的项目有一个以com.sonatype开头的groupId,而Apache Software的项目有以org.apache开头的groupId。
artifactId
在groupId下的表示一个单独项目的唯一标识符。
version
一个项目的特定版本。发布的项目有一个固定的版本标识来指向该项目的某一个特定的版本。而正在开发中的项目可以用一个特殊的标识,这种标识给版本加上一个“SNAPSHOT”的标记。
packaging
项目的类型,默认是jar,描述了项目打包后的输出。类型为jar的项目产生一个JAR文件,类型为war的项目产生一个web应用。
help插件:
$ mvn help:describe -Dplugin=help -Dfull
创建简单项目:
$ mvn archetype:create -DgroupId=org.clayz.simple -DartifactId=simple -DpackageName=org.clayz.simple
构建并打包:
$ mvn install
生成站点和报告:
$ mvn site
在不载入依赖情况下运行Java类:
$ mvn exec:java -Dexec.mainClass=org.clayz.simple.weather.Main
浏览项目依赖:
$ mvn dependency:resolve $ mvn dependency:tree
指定编译环境:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build>
忽略单元测试失败:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin> </plugins> </build>
跳过单元测试:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> </plugins> </build>
构建打包好的命令行应用程序:
<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build>
$ mvn assembly:assembly
创建一个web应用的pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.clay.web</groupId> <artifactId>clay-webapp</artifactId> <packaging>war</packaging> <version>1.0</version> <name>clay-webapp Maven Webapp</name> <url>http://clay.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-servlet_2.4_spec</artifactId> <version>1.1.1</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>clay-webapp</finalName> </build> </project>
为自定义JSP标签添加JSP 2.0规格说明:
<dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jsp_2.0_spec</artifactId> <version>1.1</version> <scope>provided</scope> </dependency>
多模块中父模块pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>simple-parent</artifactId> <packaging>pom</packaging> <name>Chapter 6 Simple Parent Project</name> <modules> <module>simple-weather</module> <module>simple-webapp</module> </modules> <parent> <artifactId>parent</artifactId> <groupId>org.sonatype.mavenbook.ch06</groupId> <version>1-SNAPSHOT</version> </parent> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </pluginManagement> </build> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
其中simple-webapp子模块pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.sonatype.mavenbook.ch06</groupId> <artifactId>simple-parent</artifactId> <version>1-SNAPSHOT</version> </parent> <artifactId>simple-webapp</artifactId> <packaging>war</packaging> <name>Chapter 6 Simple Web Application Project</name> <dependencies> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-servlet_2.4_spec</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.sonatype.mavenbook.ch06</groupId> <artifactId>simple-weather</artifactId> <version>${project.version}</version> </dependency> </dependencies> <build> <finalName>simple-webapp</finalName> <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> </plugin> </plugins> </build> </project>
由Maven Reactor负责解析模块依赖以编译:
$mvn clean install
多模块的依赖优化:
上移共同的依赖至dependencyManagement
如果多于一个项目依赖于一个特定的依赖,你可以在dependencyManagement中列出这个依赖。父POM包含一个版本和一组排除配置,所有的子POM需要使用groupId和artifactId引用这个依赖。如果依赖已经在dependencyManagement中列出,子项目可以忽略版本和排除配置。
为兄弟项目使用内置的项目version和groupId
使用{project.version}和${project.groupId}来引用兄弟项目。兄弟项目基本上一直共享同样的groupId,也基本上一直共享同样的发布版本。使用${project.version}可以帮你避免前面提到的兄弟版本不一致问题。
如原始父pom:
<project> ... <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.0.7</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.5</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> <version>3.3.0.ga</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>3.3.0.ga</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>3.2.5.ga</version> <exclusions> <exclusion> <groupId>javax.transaction</groupId> <artifactId>jta</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </dependencyManagement> ... </project>
原始子pom:
<project> ... <dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> </dependency> </dependencies> ... </project>
可以看出父pom与子pom在hibernate-annotations和hibernate-commons-annotations上有重复,优化后的父pom如下:
<project> <properties> <hibernate.annotations.version>3.3.0.ga</hibernate.annotations.version> </properties> ... <dependencyManagement> ... <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> <version>${hibernate.annotations.version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>${hibernate.annotations.version}</version> </dependency> ... </dependencyManagement> ... </project>
发表评论
-
Eclipse快捷键
2011-12-22 14:05 1385好久没用了,再回顾一下,免得忘了。 编辑 ... -
设计模式备忘 - 行为型
2010-03-29 23:59 1538责任链模式(Chain of Responsibility) ... -
设计模式备忘 - 结构型
2010-03-28 17:50 1305适配器模式(Adapter) 将一个类的接口转换成客户希望的 ... -
设计模式备忘 - 创建型
2010-03-28 16:04 1242工厂模式 工厂模式主 ... -
SVN同步备份
2009-05-30 22:59 2951首先建立一个空的repository,svnadmin cre ... -
Eclipse下配置Tomcat debug
2009-05-24 21:16 8218Eclipse下自带有Tomcat debug插件,不过该插件 ... -
Jboss SSL on Debian
2009-03-22 12:17 12801. Generate self-signed certifi ... -
IzPack使用备注
2009-02-11 01:05 3834install.xml <?xml version=&q ... -
How to integrate Solr and Jboss
2008-09-11 22:50 1879本文转自 http://www.mail-archive.co ... -
什么是JMX?
2008-08-28 21:31 1375转自:http://www.blogjava.net/mlh1 ... -
JNLP介绍
2008-08-02 17:44 3033原文地址:http://blog.csdn.net/yq760 ... -
Apache虚拟主机配置
2008-07-10 16:42 3324Apache虚拟主机配置 来自 Clay的日记 ... -
Apache配置.htaccess\.htpasswd
2008-07-10 16:59 2764Apache配置.htaccess\.htpasswd 来自 ... -
Apache服务器中的URL重写的配置和应用
2008-07-10 17:15 2382Apache服务器中的URL重写的配置和应用 来自 Clay的 ... -
Log4j常用配置
2008-01-31 18:25 1851常用log4j配置,一般可以采用两种方式,.propertie ... -
SVN常用目录结构
2007-12-26 22:29 5152特殊目录名说明 trunk 主干,存储最新稳定版本 tag ... -
Windows下SVN服务器的搭建
2007-12-26 22:25 85621,软件下载 下载Subvers ... -
针对ECLIPSE的SUBVERSION插件
2007-12-15 16:30 3395摘要 Subversion (SVN) ...
相关推荐
这篇教程将通过一个具体的实例来讲解如何使用Java连接MySQL数据库,适合初学者学习。首先,我们需要理解几个关键的概念: 1. **MySQL**: MySQL是一款流行的开源关系型数据库管理系统(RDBMS),广泛应用于Web应用...
一款后端基于springboot,前端基于VUE,开发的CMS,技术栈非常少,非常适合初学者开发学习使用。 web自适应界面。有了它你只需要懂一点springboot 和 VUE即可在几天的时间内快速开发出一个简单的web应用。 【后端...
`download.md` 和 `memo.md` 文件可能用于记录项目的下载方式以及一些重要的备注信息。`download.md` 可能提供项目的下载链接、下载指南或者是相关依赖包的下载说明。`memo.md` 则可能包含了一些项目内部的开发笔记...
3)基于SSM的人事管理系统,适合初学者第一个实战项目: 4)Maven的搭建+用SpringMVC春+ MyBatis的框架,添加四郎权限控制,AOP日志管理与异常统一处理,Redis的缓存,ActiveMQ的通讯等功能: 5)基于SSM框架...
《家庭理财管理系统的设计与实现源码》 ...源码的学习和研究有助于提升开发者在Web开发领域的技能,特别是对于初学者,能够深入理解实际项目的架构设计和开发流程,对未来的软件开发工作有着积极的促进作用。
本项目通过集合了30个与Java基础编程相关的文件,全面覆盖了从基本语法到项目配置的各个方面,为Java编程初学者和中级开发者提供了实践和巩固基础知识的宝贵资源。 项目中的11个Java源文件,包含了多种类型的基础...
Java Swing 是Java平台上的一个图形用户界面(GUI)工具包,它是Java Foundation Classes (JFC) 的一部分。这个“1107.Java Swing...对于初学者来说,这是一个很好的学习案例,可以深入了解Java GUI编程和数据库应用。
- 开发环境:开发和运行代码所需的Java版本、IDE(如IntelliJ IDEA或Eclipse)、构建工具(如Maven或Gradle)等。 - 版本信息:项目的版本号,如果有,可能还有更新日志。 - 许可证信息:项目遵循的开源许可证,...
2. **“这个那个”**:这部分描述可能是创建者的随意备注,没有提供具体的技术细节,但暗示了项目可能包含多个部分或者涉及多种技术。 3. **“从这里开始,执行#4”**:这可能是指一个特定的Git标签或里程碑,比如...