Maven 2, The Simplist Practice (1) - A Pure Java Project

Talking about what I did in the hugh company was Enterprise Applicationi Development, but what most we did was building or managing the package dependency manually. So we need to work out a way to aotomize them.

First of all, we need to figure what out maven is and how we configurate Maven, according to the rich information from Google, I don't want to say here. So we move forward to the very simple practice for the Maven 2.

Another reminder, please use maven 2.0.7 as different Maven Version may have different behavior... BTW, use Eclipse 3.3 for the investigation purpose.

[b]1. Simple Pure Java Project.[/b] (Classic Hello World)
[b]1.1 Command to create the Simple Java Skeleton[/b], it can be used in any Java development tool.

c:\tutorials>mvn archetype:create -DgroupId=com.mytutorial -DartifactId=simple

[b]1.2 Add eclipse support for the project above.[/b]
As Eclipse has its own program structure and files, we could also apply the structure or the files ourselve. But a eclipse plug-in for Maven help to do so:

C:\tutorials\simple>mvn eclipse:eclipse

After running that command, a Eclipse Java Based folder structure would be created.

[b]1.3 The Best Practices is diffenciate the source folder and the development folder.[/b] So we need to import the source our workspace.
1.3.1 Add the class path variables

M2_REPO = c:\java\.m2\repository (in my case)

You could also try

mvn -Declipse.workspace=C:\java\eclipse-tutorial-workspace eclipse:addmaven-repo

To do so, but my environment did not accept this command.

[b]1.3.2 Import a Java Project[/b]
In the Eclipse UI, import the source as [b]Existing Projects into Workspace[/b].

[b]1.3.3 Run the hello world[/b]

Right Click src/main/java/com.mytutorial/App.java then run.

src/test/java/com.mytutorial.AppTest.java would be the JUnit tester.

[b]1.4 Generate a Jar for later use[/b].

C:\tutorials\simple>mvn clean package

[b]1.4.1 Finally, run the jar package[/b]:

C:\tutorials\simple>java -cp .\target\simple-1.0-SNAPSHOT.jar com.mytutorial.App
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值