Maven project initializer - maven

Is there an easy way to initialize maven projects which is equal to spring initializer? (https://start.spring.io/).
What I meant was an easy interface rather than going through command line or without using paid IDE.

In Eclipse, you can create a new Maven Project in "File -> New -> Project". Then you can choose a Maven archetype (which is essentially a project template) and enter the parameters.

Or from the command line, using the spring-boot-sample-simple-archetype
mvn archetype:generate -DarchetypeGroupId=org.springframework.boot -DarchetypeArtifactId=spring-boot-sample-simple-archetype -DarchetypeVersion=RELEASE
For basic maven projects I have a shell script in my work directory, using the maven quick start archetype:
$ cat quickArch.sh
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=RELEASE

Related

How to build a maven scaffold like spring initializr

As the title, is there such a maven plugin that can achieve such a function, I can manually select the required dependencies, or even generate the code automatically?
There is https://code.quarkus.io/ for generating projects from the browser and also the quarkus https://quarkus.io/guides/cli-tooling if you want to use a command line application
You can create Maven project with mvn archetype:generate command. For example:
mvn archetype:generate -DgroupId=com.roamch007 -DartifactId=my-app -DinteractiveMode=false
This command will create project in may-app directory.
If you need specific dependencies you can create Maven Archetype, and re-use this archetype while generating new projects.
Read more: Guide to Maven Archetype

Maven 3 - Unable to find archetype

I have created a customized archetype, customA-web-archetype. Within the project folder, customA-web-archetype , I ran mvn clean install archetype:update-local-catalog which was successful. Now when I run mvn archetype:generate -DarchetypeCatalog=local outside the folder to use the archetype, I am getting the following error:
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
Your filter doesn't match any archetype (hint: enter to return to initial list)
FYI- When I was setting up Maven, I moved the .m2 to a different directory rather than using the default home directory. I made the appropriate change to settings.xml so that it can find the .m2 in the updated directory structure.
I am not using any repo manager such as Nexus. Just a local m2 repo sitting on the same box as the archetype project.
To run the archetype command, you need to specify the groupId, artefactId and version of your archetype, as well as those of your future maven project.
You should try the following command, with your own parameters:
mvn archetype:generate -DarchetypeCatalog=local -DarchetypeGroupId=yourArchetypeGroupId -DarchetypeArtifactId=yourArchetypeArtifactId -DarchetypeVersion=yourArchetypeVersion -DgroupId=projectGroupId -DartifactId=projectArtifactId -DinteractiveMode=false
After upgrading from Maven 2 to 3 we found the same problem. The fix was to change the version of the archetype-packaging and maven-archetype-plugin from 2.2 to 3.0.0 in the archetype pom.
I looks like maven moved the location of it's archetype repository file from ~/.m2 to ~/.m2/repositories which is why generate wasn't finding it.
One strange behavior I'm still seeing is that if I just do
mvn archetype:generate
it doesn't show my local archetypes, however if I do a
mvn archetype:generate -DarchetypeCatalog=local
it shows up. Hope this helps.
Have you tried crawling the repo to create a catalog? Perhaps it's missing / broken? Archetype plugin has crawl goal, which parses the repo and creates catalog.xml.
mvn archetype:help
[... snip ...]
archetype:crawl
Crawl a Maven repository (filesystem, not HTTP) and creates a catalog file.

creating different types of projects using eclipse with maven

I know creating the project using maven with command prompt but if i want to import this project into eclipse i have to run some commands and it will be modified suitable for eclipse, My question is can I create different archetype projects using maven plug in to eclipse, without using maven with cmd ?
You can entirely use Eclipse without using the command prompt. Though I prefer to use both terminal and Eclipse interfaces to utilize the maven project, and is a dynamic way of development. Eclipse Mars already include Maven.
Two ways to do this:
Create a new general project, create new POM file, define dependency and build, and Eclipse will recognize to configure as Maven project without applying Eclipse Project facets.
Create a new Maven project, do not skip archetype selection and use quickstart only if creating a simple Java project with main and test source folders, define module properties (group, artifact, version, etc.), and Eclipse will configure project as Maven project without applying Eclipse Project facets.
To execute a clean install, you need to create a goal "clean install" in Eclipse Run Configuration under Maven. Caution, Eclipse use embedded Maven runtime by default so if you'd like to link with your copy of Maven, you'll need to configure Eclipse to point at your Maven installation directory.
Basically, every command you entered in command prompt need to be a goal in Eclipse Maven Run Configuration to separate yourself from using command prompt.
Example Java Maven Project:
Step 1: Create New Maven Project
The first step to begin Maven-enabled Java development without using command prompt.
Step 2: Eclipse Project Configuration
Most of the time, I usually skip this section unless special circumstance requires a working set.
Step 3: Specifying Archetype
Maven archetype quickstart comes with two source package: test and main. This is the most simplest and efficient option to begin Java development. This is equivalent to -DArchetypeArtifactId=maven-archetype-quickstart option.
Step 4: Define Archetype Parameters
Define your own archetype parameters.
Step 5: Confirm Eclipse generated a Maven-enabled Java project
Double check POM and ensure Eclipse throws no error. In this case, Eclipse warns of Java 1.5 not defined. You can fix this by specifying Java version in maven-compiler-plugin within build tag in POM but that's entirely another thread.
Step 6: Define a Maven Goal
We want to test whether Eclipse can do a "mvn clean install" by creating a new run configuration. You can see the console output in background that Eclipse successfully output Maven build.
Is this what you were asking about?

Creating a Maven Project Programmatically Runtime

I have created a number of java classes using sun code model library. Now, I would like to create a maven project add those classes and upload it to a Nexus Sonatype Internal Maven Repository. Does anyone know how to create a maven project programmatically. Any help will be appreciated.
It is not really programmatically, but maven archetype can generate a project squeleton for you:
mvn archetype:generate -DgroupId={project-packaging}
-DartifactId={project-name}
-DarchetypeArtifactId=maven-archetype-quickstart
You can also run simply :
mvn archetype:generate
And choose an archetype from the list displayed.
Once done, you can put your java file in src/main/java.
https://maven.apache.org/guides/introduction/introduction-to-archetypes.html

Is there any Apache Click maven archtype similar to Wicket's?

Is there any Apache Click maven archetype similar to Wicket's quick start? Similar to http://wicket.apache.org/start/quickstart.html
Basically what I need is a way to get started using Apache Click quickly using Maven.
Thanks in advance.
I never tried it myself, but this project provides a maven archetype for click. It doesn't look like they provide it in a public repository, so you will need to check the sources, compile&install it and than you'll be able to use it, e.g.:
$ svn checkout http://construtor.googlecode.com/svn/trunk/ construtor-read-only
$ cd construtor-read-only/maven-archetype-click/
$ mvn clean install
$ mvn archetype:generate
[...]
387: local -> maven-archetype-click (An archetype which generates a simplifed sample of the Apache Click Framework.)
[...]
For the benefit of future enquirers, there are instructions to achieve this here. However, the remote build did not work for me using Maven 3 nor did the local installation suggested without some modifications. This is what worked for me:
Download the archetype jar file
Install the archetype in the local maven 3 repo:
mvn install:install-file -DgroupId=com.google.constructor.archetypes -DartifactId=maven-archetype-click -Dversion=1.0 -Dpackaging=jar -Dfile=\maven-archetype-click-1.0.jar
Generate skeleton project:
mvn archetype:generate -DarchetypeGroupId=com.google.constructor.archetypes -DarchetypeArtifactId=maven-archetype-click -DarchetypeVersion=1.0 -DgroupId=com.test -DartifactId=clickprimer -DarchetypeCatalog=local
cd clickprimer
mvn clean package
mvn jetty:run

Resources