顯示具有 Maven 標籤的文章。 顯示所有文章
顯示具有 Maven 標籤的文章。 顯示所有文章

2015年8月4日 星期二

Maven study

Gossip
I don't like Maven indeed. Xml configuration method is more complex for now. But, my most work still need Maven. The principle is same as other dependency tools. So, let us still work on it for now.  If you don't have any constrain, you can learn Gradle which is a modern dependency tool. Otherwise, I also don't like Eclipse, but I still work on it. Intellij IDEA is also good choice, but it is not free. You think you need to improve your production of coding, then buy it. However, I still need Eclipse for my working tool, so it is not necessary to learn two IDA as same time.

The reason why I return to study Maven is Spring 4. Spring 4 use Maven to set up Spring Boot or other Spring stuff. So, I need to understand Maven in some kind of level.

Resoure
Official Maven web site on Apache

Tutorial






2015年6月27日 星期六

Maven Note - Basic

I have study this project manage tool, Maven, for a while. But, I still feel confused for this tool. I used Ant for my previous job. This is an easy tool to manage project. But, it does not have the dependency management. So, we still need to learn it. Actually, if you are java coder, you should learn it for its basic mech anism. Other program languages also have their own project manage tool, but this is not our main goal. So, I make a list which your should learn.

Installation
The Concept of Maven
Create a project
Know about pom.xml



Installation


How to install maven, you can google. If you use mac, you can used Homebrew is a very great package manage tool.
brew install maven



The Concept of Maven


There are some good tutorials of Maven
Chinese-
http://www.codedata.com.tw/java/understanding-gradle-2-maven/
http://juvenshun.iteye.com/blog/213959
http://takeshi-experience.blogspot.tw/2011/12/java-mvc-sample-2-with-maven.html
English-
http://www.javacodegeeks.com/?s=maven

Using a simply way to explain, there are three life cycle clean, default, site.
clean life cycle - you should clean your previous building content, before you build new one.
build life cycle - build your project, and deploy it.
site life cycle - Analyze the project data.

There are many phases defined for each life cycle. You can read this
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference 

Each phase define its workflow and goal to execute.
goal is a maven plugin to execute the command, like compiler:compile.
compiler is the plugin name, and compile is the goal name.

You can also combine these three lifecycle, like mvn clean compile site. compile is a phase of default lifecycle.



Create a project


You can use command line to build a simple project, like

mvn archetype:generate -DgroupId=com.di.maven -DartifactId=hello-world -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false


Actually, you can also use Eclipse( or other IDE which support Maven) to build Maven Project.
There pictures are how to create a Maven project in Eclipse.








Know about pom.xml


This is a simple pom.xml file
<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>com.di.maven</groupId>
  <artifactId>hello-world</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>hello-world</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Maven is a convention over configuration software design pattern.  This is why pom.xml file is so sample. We have a super pom.xml which config a lot of detail. So, we can start a sample project faster. But, it still confused for me. Actually, when you need to setup other configuration, you still need to figure out the correct way to config. This topic is still a problem for me. Anyway, let start it easier. In this pom.xml file, we only need to understand how to add the jar files which is needed for our project. You only add the dependency config to <dependencies>. It will auto download the jar files we need. This is also why we need to use Maven. Maven can solve the dependency hell in some situations. Otherwise, <scope> is mean the dependency will effect which s cenario will be used.

You also can search the dependency you need in
http://mvnrepository.com/

Further, there is an example which we had built before.
https://github.com/bpmabpma/JBossExmple/blob/master/springMvc/pom.xml

We can see a lot new Xml elements show up, such as <properties>, <dependencyManagement>,  <<build>, <plugin>, <profiles>. I think they are very important. But, in my present situation, I should build my project be my primary job. So, when I finish build the major part of coding. I should return Maven, and build the CI system based on Maven.

Moreover, if you really need to an expert of Maven. You should read this
http://maven.apache.org/guides/index.html




2015年1月10日 星期六

[Maven]基本概念

2014一下子就過去了
轉眼間就2015了…
也一陣子沒有寫Blog了
一直想整理一下常用的framework和開發工具
不過大部分的時間都在混水摸魚
希望2015能完成這個目標丫

2015的首po
就從一個很基礎的開發工具開始
Maven