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

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.

Related

How to run a maven plugin without a POM in Jenkins?

I have a plugin which can run either using a pom.xml or without (depends upon the version of the artifact we're building: new versions go without a pom. Strange, I know).
I want to have that plugin run in Jenkins.
But when creating a maven project, I have to set a pom (or as a default, Jenkins suppose there is one in the base folder given).
Question: Is it possible to configure Jenkins to not use a pom when there is none?
As per my comment, you should use a Jenkins freestyle project build in this case, in order to have more flexibility and avoid the default assumptions of a Jenkins Maven build.
In such a build, you can then configure a build step executing a shell or a Windows command (depending on the Jenkins server OS).
Indeed, in the Jenkins Maven build, a pom file is always required, as mentioned in the help support of the Configuration > Build > Root Pom entry
If your workspace has the top-level pom.xml in somewhere other than the 1st module's root directory, specify the path (relative to the module root) here, such as parent/pom.xml.
If left empty, defaults to pom.xml

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?

Specifying maven options when running maven lifecycle goals in Intellij

I have an Intellij maven project and am able to use the View|Toolbars|Maven Projects , then select a specific maven module. From there i click on some lifecycle components, e.g
clean compile package
and run them. So far OK. But I need to add some maven options. What are my choices here? Do i need to set a static MAVEN_OPTS environment variable? The downside is it would be applied equally to ALL invocations of maven.
Is there any way to apply maven options e.g. -DskipTests to a single maven run as part of selecting the lifecycle targets on the GUI?
UPDATE
There is actually a nondescript icon for "Toggle skipTests mode" on the maven toolbar. However we have other settigs to include on the maven command line so that icon is insufficient.
The solution is to create a Maven run configuration. There are two ways to do so:
Run - Edit Configurations - + - Maven, or
Right click on your goal in the Maven view and select Create {goal}... (see screenshot:)
In the opened Run Configuration dialog use the Command line field to specify any command including arguments like -DskipTests

How do I deploy a maven created webapp to tomcat

So I was following http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/ for a simple tutorial on how to use maven and jsf. I created a maven project by running mvn archetype:generate -Dfilter=org.apache:maven-archetype-webapp in my command prompt. Then I continued with the tutorial, I wound up creating all necessary files, but then when I got to the end, I realized I did have a server created. So I created one real quick, but when it came to the point of adding files to the server (from the add or remove dialog box), no projects or files showed up. I am not on my computer where the project is located so I can't copy/paste the .pom file in, but it looks practically exactly like the pom in the tutorial (only difference is groupId, artifact, ect.) No additional plugins, dependencies, or configs.
Do you want to deploy the webapp within Eclipse to Tomcat? Or as some sort of automatic/continuous deployment?
Within Eclipse you often need to add the Dynamic Web project and JSF facets to your project so Eclipse recognizes the project as deployment capable. If you are using m2eclipse make sure to install the m2eclipse wtp add on so this is done automatically.
If you want to add auto-deployment to the pom.xml I recommend using the maven cargo plugin: http://cargo.codehaus.org/Maven2+plugin - it supports the major containers.
For tomcat you need to modify the tomcat-users.xml to allow auto-deployment and leave the tomcat-manager application in place. If you have startet tomcat and pointing your browser to http://localhost:8080/manager/html/list it should either tell you to login or what to add to that file.
The configured user is then used in the configuration to deploy the war file via the tomcat-manager using the mvn cargo:deploy goal. The configuration has to be added to the pom.xml using war as packaging, not to the parent-pom.xml

IntelliJ steps through the wrong lines when debugging remote Java application

I tried to remote debug a maven plugin for a liquibase project with Intellij. IDEA is highlighting the wrong source code line.
I manually built and installed the plugin in my local maven repository from sources in my Intellij project. Intellij version is 11.1.3 and maven version is 3.0.4 running on Ubuntu 12.04.
For debugging the maven plugin I used mvnDebug comand.
If someone has any ideas please give me some advice. I'm not too used to remote debugging (in fact this is the second time I've done this).
For me, whenever IntelliJ is highlighting the wrong line, it was always because the version of the JAR/classes being used to run the application differs from my source files - i.e. different version of the sources were used to build the JAR and/or classes.
You are going to have to be sure that you are working from the exact source that was used to build the classes you are debugging.
You can verify this by looking at the classpath being used to launch the application, locating the JAR file or classes directory that contains the classes you are debugging, and verifying that they were built from the sources you are inspecting.
Note that when you are debugging third-party libraries, you often can download the "sources" jar (see IntelliJ2-IDEA get Maven-2 to download source and documentation).
If you stumbled across this post, and sure that the source and JAR are the same code, then this could be your problem.
http://youtrack.jetbrains.com/issue/IDEA-8021
Instead of doing remote debugging you can run the plugin directly from IntelliJ.
Have the liquibase plugin project loaded in IntelliJ by just pointing at the pom.xml.
Choose Edit Configurations...
Press the + button to Add New Configuration.
Select Maven.
Enter the Working directory to the project you want to run the plugin on.
Enter the Command line. Could be process-sources, compile or liquibase:status depending on what you want to do.
Press OK
Set a breakpoint in the Liquibase Mojo.
Now you can start this configuration by pressing Shift+F9.
Maven will start and finally you will see that your plugin is waiting at the breakpoint!
Make sure that you have defined the plugin in the target pom.xml with correct version and also that you build the plugin before launching it. You can ensure that by enabling Make in the Before Launch pane.

Resources