diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..57407c3 --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + com.mycompany.app + my-app + my-app + 1.0-SNAPSHOT + http://maven.apache.org + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + + java + + + + + com.mycompany.app.App + + argument1 + + + + + maven-shade-plugin + 2.1 + + + package + + shade + + + + + com.mycompany.app.App + + + + + + + + maven-dependency-plugin + 2.3 + + + + properties + + + + + + maven-compiler-plugin + + 1.8 + 1.8 + true + + org.checkerframework.checker.nullness.NullnessChecker + + + -Xbootclasspath/p:${annotatedJdk} + + + + + + + + junit + junit + 3.8.1 + test + + + + ${org.checkerframework:jdk8:jar} + + + diff --git a/my-app/pom.xml b/my-app/pom.xml new file mode 100644 index 0000000..26d75b0 --- /dev/null +++ b/my-app/pom.xml @@ -0,0 +1,110 @@ + + 4.0.0 + com.mycompany.app + my-app + jar + 1.0-SNAPSHOT + my-app + http://maven.apache.org + + + + ${org.checkerframework:jdk8:jar} + + + + + junit + junit + 3.8.1 + test + + + org.checkerframework + checker + 1.9.4 + + + org.checkerframework + checker-qual + 1.9.4 + + + org.checkerframework + jdk8 + 1.9.4 + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + + java + + + + + com.mycompany.app.App + + argument1 + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.1 + + + package + + shade + + + + + com.mycompany.app.App + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.3 + + + + properties + + + + + + maven-compiler-plugin + + 1.8 + 1.8 + true + + + org.checkerframework.checker.nullness.NullnessChecker + + + + -Xbootclasspath/p:${annotatedJdk} + + + + + + \ No newline at end of file diff --git a/my-app/src/main/java/com/mycompany/app/App.java b/my-app/src/main/java/com/mycompany/app/App.java new file mode 100644 index 0000000..826f777 --- /dev/null +++ b/my-app/src/main/java/com/mycompany/app/App.java @@ -0,0 +1,29 @@ +package com.mycompany.app; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + + System.out.println("A NullPointerException is a drag..."); + Object myObject = null; + /** + * Checker prevents this from compiling... + */ +// System.out.println("myObject: " + myObject.toString()); + /** + * ... which is simply fantastic. It shows: + * + * error: [dereference.of.nullable] dereference of possibly-null + * reference myObject + * + * http://checkerframework.org + */ + System.out.println("... but thankfully, Checker has our back: http://checkerframework.org"); + } +} diff --git a/my-app/src/test/java/com/mycompany/app/AppTest.java b/my-app/src/test/java/com/mycompany/app/AppTest.java new file mode 100644 index 0000000..3355990 --- /dev/null +++ b/my-app/src/test/java/com/mycompany/app/AppTest.java @@ -0,0 +1,38 @@ +package com.mycompany.app; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d998204 --- /dev/null +++ b/pom.xml @@ -0,0 +1,110 @@ + + 4.0.0 + com.mycompany.app + my-app + jar + 1.0-SNAPSHOT + my-app + http://maven.apache.org + + + + ${org.checkerframework:jdk8:jar} + + + + + junit + junit + 3.8.1 + test + + + org.checkerframework + checker + 1.9.4 + + + org.checkerframework + checker-qual + 1.9.4 + + + org.checkerframework + jdk8 + 1.9.4 + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + + java + + + + + com.mycompany.app.App + + argument1 + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.1 + + + package + + shade + + + + + com.mycompany.app.App + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.3 + + + + properties + + + + + + maven-compiler-plugin + + 1.8 + 1.8 + true + + + org.checkerframework.checker.nullness.NullnessChecker + + + + -Xbootclasspath/p:${annotatedJdk} + + + + + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..51ad35b --- /dev/null +++ b/readme.md @@ -0,0 +1,59 @@ +# A simple, minimal 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/