creating different types of projects using eclipse with maven - 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?

Related

Do we have to include jar files in eclipse project if we are using maven?

I am new to maven.
The POM file in maven contains all the dependencies that we need in our project.
So we don't have to externally add any JAR's to the buildpath in eclipse.Right?
That's right. Maven will download dependencies and M2Eclipse (Eclipse plugin for integrating Eclipse with Maven) will setup a build path for you.
Two Solutions - 1 Using Eclipse IDE
Install the Maven (M2E Eclipse Plugin) if you use older version of eclipse, If you download the latest eclipse.
Point your settings.xml and create a maven project from your eclipse, it is better keep Group Id as com.yourcompany.app Artifact Id as yourProjectName and Version 0.0.1-SNAPSHOT depends on your Architecture Standards set by your company. Also Packaging can be as WAR file for WebApplication, EAR file for Enterprise Application. You can find the numerous list of examples from Maven Site.
2 From Command Line
Install Maven from Apache Maven site, Would recommend to go for the latest version -apache-maven-3.3.9-bin.zip.
Set the Maven Home in the Environment Variables as shown in the below figure.
Edit Your Path variable as %MAVEN_HOME%\bin, verify your installation by using this command from your command prompt. It should display the Maven Home and Java Version, which confirms your maven successful installation.
Paste your settings.xml (C:\apache-maven-3.3.9\conf) given by your build team or Architecture team for accessing your internal repository. And keep a backup of the original settings.xml (which is default download from Maven site)
Run these commands from your command prompt.
mvn eclipse:clean -e
mvn eclipse:eclipse -e (which will automatically set your project build path as shown in the below figure)
It will resolve your compilation issues and your project is ready as an deploy-able artifact

run maven project with eclipse

I'm new to maven and eclipse. I added m2e-plugin in eclipse and I imported an example of a maven project that I've found in the net.
My problem is when I try to run the project in eclipse using the Run as item menu, I don't find the maven package menu as I learned in the different tutorials.
Is it a problem of installation?
Ok, lets go through this step by step to make sure you have everything you need to get going.
First of all make sure that you have Maven installed (and lets assume you have Java already). You can download it from http://maven.apache.org/download.cgi and installation instructions for Fedora (which I assume is what you are using from your tag) are further down the page.
To test that Maven is correctly installed and working type mvn --help in to the terminal. Eclipse and m2e pretty much just hop on to the terminal for everything Maven related so make sure this is working before proceeding.
Next download an appropriate version of Eclipse. For the sake of this example I've downloaded the Kepler version of the Java EE IDE. In this version of Eclipse m2e comes bundled and to check this you can go to Help > About Eclipse > Installation Details and on the plug-ins tab you should see the m2e connectors.
Now you can import your Maven project in to Eclipse. To do this go to File > Import and then choose Existing Maven Projects under the Maven section. Choose the directory with the example project that you've downloaded and then Finish.
Now, ensure that you have some file inside your example Maven project opened and when you go to Run As... you should now be able to see the maven options. Go to Run As > Maven build... and all you need to do is place the word package in the Goals field and you're ready to roll.
Convert your project to a maven project if you haven't done yet by right clicking on your project in the Eclipse Project/Package explorer. Then follow:
Configure -> Convert to Maven Project
After that you can just right click again on the project Run as and you will see all Maven possibilities to execute your project build/install/clean etc.

Can I make a Maven plugin that generates a project and then builds that project?

Is it possible to combine the capabilities of an archetype and a normal Maven plugin into a single plugin?
I have a custom language which I can compile into Java source code. I've written a Maven plugin which does this in the generate-sources phase, adds the Java source to the project, and builds the project. It works as I'd expect.
However, to use it, I need to first write out a pom.xml file referencing my plugin and describing where the input files live. I'd like to be able to go straight from raw input files to compiled code in a single maven command.
For example, suppose I have this directory structure:
my-project/
some-input-file.dsl
I want to run
bash$ mvn com.waisbrot.plugin:generate -DgroupID=com.waisbrot package
and after Maven's done running have:
my-project/
some-input-file.dsl
pom.xml
target/
generated-sources/
plugin/
SomeInputFile.java
classes/
com/
waisbrot/
SomeInputFile.class
some-input-file-1.0.jar
Actually, the integration testing of the archetype allows you to declare the parameter and goals. So do this:
Pick the template project you want to create
mvn archetype:create-from-project. It will create a new archetype
Review src/test/resources/projects, especially goal.txt and archetype.properties (source: http://maven.apache.org/archetype/maven-archetype-plugin/integration-test-mojo.html). Tweak so install will be implicity
mvn verify will be able to build the archetype, run the it, and get it installed
Hope it helps

is it possible to do a Maven build using Build Forge?

Is it possible to do a Maven build using Build Forge? Currently we use Build Forge, ClearCase and ClearQuest with Ant scripts; would like to try a Maven build. Not sure if I can I have no test environment so don't want to mess up any thing and still learning all this stuff too
Maven can be invoked from any build automation framework.
Create a buildforge step that invokes your Maven build as follows:
mvn -s /path/to/maven/settings/files/mysettings.xml clean package
Explicitly selecting the settings file is recommended as this enables you customise the Maven configuration for each project.
Project isolation can be further enhanced by ensuring that each project has it's own local repository location (See the "localRepository" parameter in the settings file documentation)

How maven pom.xml file convert configurations into system properties?

As we all know, suppose we define 'transportation' in pom.xml in maven,
after we run command like 'mvn jetty:run' the property 'db.name' can be discovered by other configuration, like 'hibernate.cfg.xml'. That's fine.
But now, I configure this project to run on tomcat directly , by 'run on server' from eclipse, instead of by maven command. (I did this by configure a project facets in eclipse, make it can use 'run on server' menu). You can see now I just run with eclipse, nothing to do with 'maven' or 'pom.xml', but it still use properties like 'db.name'. If I need change to another db, I had to change the 'db.name' property, then run some command in maven to make it take effect.
Can any body give some explanation about how it works? Does maven command generate some file at some place that takes the properties?
Properties are set for virtual machine. Maven run new/existing (dependent on configuration) instance of runtime environment. So you can pass properties as
-Dkey=value (or <key>value</key> in pom)
Check in eclipse configuration if you can pass arguments when you run tomcat?
Eclipse maven plugin (from Eclipse foundation) understands the pom.xml and usually syncs with any changes.
But sometimes I observed that it goes out of sync, and to fix that problem I need to delete the temporary folders/files created by Eclipse (.settings, .classpath and .project) and import again.

Resources