├── .gitignore ├── README.md ├── UNLICENSE ├── build.xml ├── checkstyle.xml ├── ivy.xml ├── pmd.xml ├── pom.xml ├── project.properties ├── src └── sample │ └── java │ └── project │ ├── SampleJavaProject.java │ └── package-info.java └── test └── sample └── java └── project └── SampleJavaProjectTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | dist 3 | cache.properties 4 | TAGS 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sample Java Project 2 | 3 | This is a reference for setting up a new Ant-based Java project. It 4 | contains most of the little Ant tricks I've learned over the 5 | years. When I start a new Java project I clone this repository, remove 6 | sections of build.xml that I don't care about for that particular 7 | project, set the project properties, clear out the sample sources, and 8 | get to work. 9 | 10 | ## Setup 11 | 12 | Building this project requires that Ivy be available to Ant. All you 13 | need is ivy.jar in Ant's classpath (in your `$CLASSPATH`, 14 | `$ANT_HOME/lib`, or `~/.ant/lib`). 15 | 16 | ## Dependencies 17 | 18 | You will need to have Astyle installed and in your path for the 19 | "format" target to work. If it's missing, that's fine. It won't affect 20 | any other targets. 21 | 22 | There is a "hotswap" target for replacing live code while an 23 | application is running. You'll need the hotswap Ant extension 24 | installed to use it. This target is to be used alongside the 25 | "run-hotswap" target, which enables hotswapping in the JVM. You can 26 | demo this for yourself by running "run-hotswap" in a terminal, editing 27 | the printed string in the code, and running "hotswap" in another 28 | terminal. The printed message in the running program should change to 29 | the new string. 30 | 31 | ## Bundles 32 | 33 | Take note of the sample `pom.xml` file. This is not actually for Maven 34 | builds -- this is an Ant project afterall -- but for publishing builds 35 | for a Maven repository. It's packed up by the "bundle" target, which 36 | creates a `bundle.jar` containing your project's signed artifacts. To 37 | use the "bundle" target you need to have GnuPG set up in your path, a 38 | generated key pair, and a running `gpg-agent`, unless you like typing 39 | your passphrase a bunch of times in a row. 40 | 41 | ## Philosophy 42 | 43 | I hate coding absolute paths in my build script and I hate including 44 | built files as part of the base project. My philosophy is that the 45 | *environment* should be set up so that the tool can easily find the 46 | external resources they need (JUnit, etc.) from the system or 47 | dependency manager. It's the system or dependency manager that 48 | provides the libraries. Anyone who has the proper development 49 | environment set up -- one that works across many projects -- should be 50 | able to clone the repository and do a build simply by running the 51 | build program with no special arguments. There should be no need to 52 | edit or install anything into the project space for the initial build. 53 | -------------------------------------------------------------------------------- /UNLICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 42 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 67 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 94 | 96 | 97 | 98 | 99 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 148 | 149 | pmd.xml 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 159 | 160 | 161 | 162 | 163 | 164 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 194 | 195 | 196 | 197 | 198 | 199 | 201 | 202 | 203 | 204 | 205 | 207 | 208 | 209 | 210 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | -------------------------------------------------------------------------------- /checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 32 | 33 | 34 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /ivy.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 17 | 18 | 19 | 21 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 32 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /pmd.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Custom set of preferred, sane rules 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | @groupId@ 4 | @artifactId@ 5 | @version@ 6 | jar 7 | 8 | @ant.project.name@ 9 | @description@ 10 | @project.url@ 11 | 12 | 13 | 14 | The Unlicense 15 | http://unlicense.org/UNLICENSE 16 | repo 17 | 18 | 19 | 20 | 21 | 22 | scm:git:@project.repo.url@ 23 | 24 | @project.scm.url@ 25 | 26 | 27 | 28 | 29 | Christopher Wellons 30 | mosquitopsu@gmail.com 31 | http://nullprogram.com 32 | -5 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # Project information 2 | artifactId = sample-java-project 3 | description = An Ant-based sample Java project. 4 | version = 1.0-SNAPSHOT 5 | package.main = sample.java.project 6 | 7 | # External information 8 | groupId = com.nullprogram 9 | project.url = http://nullprogram.com/blog/2010/10/04/ 10 | project.repo.url = https://github.com/skeeto/SampleJavaProject.git 11 | project.scm.url = https://github.com/skeeto/SampleJavaProject 12 | -------------------------------------------------------------------------------- /src/sample/java/project/SampleJavaProject.java: -------------------------------------------------------------------------------- 1 | package sample.java.project; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.Parameter; 5 | import com.beust.jcommander.ParameterException; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Getter; 8 | import lombok.NoArgsConstructor; 9 | import lombok.NonNull; 10 | import lombok.Setter; 11 | 12 | /** 13 | * The main class of the application. It contains the main() method, 14 | * the first method called. 15 | */ 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class SampleJavaProject implements Runnable { 19 | 20 | /** The delay between printed messages. */ 21 | private static final long PRINT_DELAY = 1000L; 22 | 23 | /** The name to be printed in the output message. */ 24 | @Getter @Setter @NonNull 25 | @Parameter(names = "--name", description = "set the user's name", 26 | required = true) 27 | private String name = "world"; 28 | 29 | /** Command line parameter for --loop. */ 30 | @Parameter(names = "--loop", description = "print endlessly, hotswap demo") 31 | private boolean loop = false; 32 | 33 | /** Command line parameter for --help. */ 34 | @Parameter(names = { "-h", "--help" }, description = "print help message") 35 | private boolean help = false; 36 | 37 | /** 38 | * Print the "Hello, world!" string. 39 | * @param args application input arguments 40 | */ 41 | public static void main(final String[] args) { 42 | /* Parse command line arguments. */ 43 | SampleJavaProject sjp = new SampleJavaProject(); 44 | try { 45 | JCommander jc = new JCommander(sjp, args); 46 | if (sjp.help) { 47 | jc.usage(); 48 | return; 49 | } 50 | } catch (ParameterException e) { 51 | System.err.println("error: " + e.getMessage()); 52 | new JCommander(new SampleJavaProject()).usage(); 53 | System.exit(-1); 54 | } 55 | 56 | sjp.run(); 57 | } 58 | 59 | /** 60 | * Print the "Hello, world!" string. 61 | */ 62 | public final void sayHello() { 63 | System.out.printf("Hello, %s!%n", name); 64 | } 65 | 66 | @Override 67 | public final void run() { 68 | do { 69 | sayHello(); 70 | try { 71 | Thread.sleep(PRINT_DELAY); 72 | } catch (InterruptedException e) { 73 | return; 74 | } 75 | } while (loop); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/sample/java/project/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * An example Ant-based Java project. 3 | */ 4 | package sample.java.project; 5 | -------------------------------------------------------------------------------- /test/sample/java/project/SampleJavaProjectTest.java: -------------------------------------------------------------------------------- 1 | package sample.java.project; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNull; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | /** 9 | * Sample JUnit tests. 10 | */ 11 | public class SampleJavaProjectTest { 12 | 13 | /** 14 | * Holds an instance of the class we are testing. 15 | */ 16 | private SampleJavaProject sjp; 17 | 18 | /** 19 | * JUnit set up method. 20 | */ 21 | @Before 22 | public final void setUp() { 23 | sjp = new SampleJavaProject(); 24 | } 25 | 26 | /** 27 | * Tests the generated setter and getter methods. 28 | */ 29 | @Test 30 | public final void testGetSet() { 31 | sjp.setName("foo"); 32 | assertEquals("foo", sjp.getName()); 33 | } 34 | 35 | /** 36 | * Tests that the null check in the setter. 37 | */ 38 | @Test(expected=NullPointerException.class) 39 | public final void nullTest() { 40 | sjp.setName(null); 41 | } 42 | } 43 | --------------------------------------------------------------------------------