This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
start:maven:totalnewbieintro [2016/08/12 13:26] fiisch [Empty project structure] |
start:maven:totalnewbieintro [2016/08/12 15:14] (current) fiisch [Conclusion] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Total newbie introduction to Maven ====== | ====== Total newbie introduction to Maven ====== | ||
| - | <note warning> | + | Anybody who wanted to start with [[https:// |
| - | + | ||
| - | Anybody who wanted | + | |
| < | < | ||
| mvn archetype: | mvn archetype: | ||
| Line 9: | Line 7: | ||
| | | ||
| </ | </ | ||
| - | Oh God, whyyyy!? | + | Oh God, whyyyy!? |
| ==== Empty project structure ==== | ==== Empty project structure ==== | ||
| Line 45: | Line 43: | ||
| ./ | ./ | ||
| </ | </ | ||
| - | Also there is a generated pom.xml file which you have to edit if you take it seriously. Now let me explain the project-generation command: | + | Also there is a generated |
| * **mvn** - Execute Maven binary. | * **mvn** - Execute Maven binary. | ||
| * **archetype: | * **archetype: | ||
| Line 51: | Line 49: | ||
| * **-DartifactId=my-app** - Root directory of your project. There is a //pom.xml// and //src// and //test// directories. There also appears //target// directory after you compile your application. | * **-DartifactId=my-app** - Root directory of your project. There is a //pom.xml// and //src// and //test// directories. There also appears //target// directory after you compile your application. | ||
| * **-DarchetypeArtifactId=maven-archetype-quickstart** - This option specifies which // | * **-DarchetypeArtifactId=maven-archetype-quickstart** - This option specifies which // | ||
| - | * **-DinteractiveMode=false** - This is to not scare off beginners, see [[https:// | + | * **-DinteractiveMode=false** - This is because nobody wants to scare beginners |
| ==== Creating empty project by hand ==== | ==== Creating empty project by hand ==== | ||
| - | Now we will try to create empty project by hand. First, create directory for your project and then a structure, the archetype originally created for you: | + | Now we will try to create empty project by hand. First, create directory for your project and then a structure the archetype originally created for you: |
| < | < | ||
| fiisch@mothership:/ | fiisch@mothership:/ | ||
| Line 102: | Line 100: | ||
| </ | </ | ||
| - | And that's it. We managed to setup empty project without using the archetype. | + | And that's it, no black magic necessary. We managed to setup empty project without using the archetype. |
| <note info> Please note that this project (and also its // | <note info> Please note that this project (and also its // | ||
| ==== Interactive mode and problem of too many choices ==== | ==== Interactive mode and problem of too many choices ==== | ||
| + | Last thing I want to explain in this post is generating empty (or any other) project using interactive mode and also reasons why probably nobody uses it. Let's start with simple // | ||
| + | |||
| + | < | ||
| + | fiisch@mothership:/ | ||
| + | fiisch@mothership:/ | ||
| + | fiisch@mothership:/ | ||
| + | [INFO] Scanning for projects... | ||
| + | |||
| + | ... very long output here ... | ||
| + | |||
| + | 1639: remote -> us.fatehi: | ||
| + | 1640: remote -> us.fatehi: | ||
| + | 1641: remote -> us.fatehi: | ||
| + | Choose a number or apply filter (format: [groupId: | ||
| + | </ | ||
| + | |||
| + | So... we have neat 1641 choices of // | ||
| + | |||
| + | < | ||
| + | fiisch@mothership:/ | ||
| + | 141 | ||
| + | fiisch@mothership:/ | ||
| + | 28 | ||
| + | fiisch@mothership:/ | ||
| + | 68 | ||
| + | fiisch@mothership:/ | ||
| + | 14 | ||
| + | fiisch@mothership:/ | ||
| + | 102 | ||
| + | </ | ||
| + | |||
| + | Maven is built around the idea that most projects have the same structure. In theory, this is very good thinking about standardization of project structure. Problem is that anyone can write such template and publish it for everyone else to see. In practice, we end up with almost 1700 templates to choose from. For a newbie, this is something really off putting. | ||
| + | |||
| + | Sad truth is, that there is no good way of choosing particular // | ||
| + | |||
| + | But okay, let's give interactive mode a shot: | ||
| + | < | ||
| + | fiisch@mothership:/ | ||
| + | fiisch@mothership:/ | ||
| + | fiisch@mothership:/ | ||
| + | [INFO] Scanning for projects... | ||
| + | |||
| + | ... very long output here ... | ||
| + | |||
| + | 1639: remote -> us.fatehi: | ||
| + | 1640: remote -> us.fatehi: | ||
| + | 1641: remote -> us.fatehi: | ||
| + | Choose a number or apply filter (format: [groupId: | ||
| + | |||
| + | # 821 is the quickstart archetype we previously specified as argument, hit ENTER | ||
| + | |||
| + | Choose org.apache.maven.archetypes: | ||
| + | 1: 1.0-alpha-1 | ||
| + | 2: 1.0-alpha-2 | ||
| + | 3: 1.0-alpha-3 | ||
| + | 4: 1.0-alpha-4 | ||
| + | 5: 1.0 | ||
| + | 6: 1.1 | ||
| + | Choose a number: 6: | ||
| + | |||
| + | # What the hell am I choosing? yeah, version of archetype. | ||
| + | # No idea about differences, | ||
| + | |||
| + | Define value for property ' | ||
| + | Define value for property ' | ||
| + | Define value for property ' | ||
| + | Define value for property ' | ||
| + | Confirm properties configuration: | ||
| + | groupId: com.mycompany.app | ||
| + | artifactId: my-app | ||
| + | version: 1.0-SNAPSHOT | ||
| + | package: com.mycompany.app | ||
| + | Y: : y | ||
| + | |||
| + | ... | ||
| + | |||
| + | [INFO] BUILD SUCCESS | ||
| + | [INFO] ------------------------------------------------------------------------ | ||
| + | [INFO] Total time: 03:22 min | ||
| + | [INFO] Finished at: 2016-08-12T16: | ||
| + | [INFO] Final Memory: 17M/477M | ||
| + | </ | ||
| + | |||
| + | Well, without much explanation, | ||
| + | //Version// property allows you to specify your app's first version - which is written into POM. Maven, as I show in some later post, is not very good at keeping version numbering by itself - and it cannot be, everyone numbers versions differently - so we need to adjust it according to project or development habits. | ||
| + | |||
| + | When we look at generated project, we see that it is the same as in the non-interactive generator created for us. In my case, //pom.xml// contains also this extra property: | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | Interactive mode fills it in by itself and according to [[https:// | ||
| + | |||
| + | ==== Conclusion ==== | ||
| + | I have shown three ways of creating basic Java project with Maven - interactive, | ||
| + | |||
| + | Also, from discussion with some of my colleagues, we got to the realization that none of us actually use project generation through Maven and that we do things by hand. The only thing we agreed upon is that specific project structure generation is useful when somebody else tells you which // | ||
| + | |||
| + | Although it is very good idea to provide templating capabilities to Maven, it failed to restrict which templates are in core Maven installation - which lead to 1641 templates (at the time of writing). Solution to this may be pretty simple: Maven, as we see later, allows you to configure additional repositories for JAR libraries. It shouldn' | ||