`
mangoo1
  • 浏览: 19257 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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.

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

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

1.2 Add eclipse support for the project above.
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.

1.3 The Best Practices is diffenciate the source folder and the development folder.  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.

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

1.3.3 Run the hello world

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

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

1.4 Generate a Jar for later use.

C:\tutorials\simple>mvn clean package

1.4.1  Finally, run the jar package:

C:\tutorials\simple>java -cp .\target\simple-1.0-SNAPSHOT.jar com.mytutorial.App
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics