GithubHelp home page GithubHelp logo

maven-hello-world's Introduction

A simple, minfdsfadsimal Maven example: hello world

To create the files in this git repo we've already run mvn archetype:generate from http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Now, to print "Hello World!", type either...

cd my-app
mvn compile
java -cp target/classes com.mycompany.app.App

or...

cd my-app
mvn package
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App

Running mvn clean will get us back to only the source Java and the pom.xml:

murphy:my-app pdurbin$ mvn clean --quiet
murphy:my-app pdurbin$ ack -a -f
pom.xml
src/main/java/com/mycompany/app/App.java
src/test/java/com/mycompany/app/AppTest.java

Running mvn compile produces a class file:

murphy:my-app pdurbin$ mvn compile --quiet
murphy:my-app pdurbin$ ack -a -f
pom.xml
src/main/java/com/mycompany/app/App.java
src/test/java/com/mycompany/app/AppTest.java
target/classes/com/mycompany/app/App.class
murphy:my-app pdurbin$ 
murphy:my-app pdurbin$ java -cp target/classes com.mycompany.app.App
Hello World!

Running mvn package does a compile and creates the target directory, including a jar:

murphy:my-app pdurbin$ mvn clean --quiet
murphy:my-app pdurbin$ mvn package > /dev/null
murphy:my-app pdurbin$ ack -a -f
pom.xml
src/main/java/com/mycompany/app/App.java
src/test/java/com/mycompany/app/AppTest.java
target/classes/com/mycompany/app/App.class
target/maven-archiver/pom.properties
target/my-app-1.0-SNAPSHOT.jar
target/surefire-reports/com.mycompany.app.AppTest.txt
target/surefire-reports/TEST-com.mycompany.app.AppTest.xml
target/test-classes/com/mycompany/app/AppTest.class
murphy:my-app pdurbin$ 
murphy:my-app pdurbin$ java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
Hello World!

Running mvn clean compile exec:java requires http://mojo.codehaus.org/exec-maven-plugin/

Running java -jar target/my-app-1.0-SNAPSHOT.jar requires http://maven.apache.org/plugins/maven-shade-plugin/

maven-hello-world's People

Contributors

pdurbin avatar fabio-he avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.