how to auto build jar by maven when i modify one java class? - maven

I have install m2eclipse plug-in for eclipse. I built a multi-module project by maven, each module are dependent, when i write a class,the eclipse can't automatically compile the class to jar file and install to M2 repository,i need to run MVN install command, then other modules can be reference the jar file, this is too much trouble, is there any good way to solve this problem?

This is because the "install" phase does not belong to m2eclipse's interesting lifecycle phases. In short, Eclipse and Maven build cycles differ a lot, and m2eclipse has a map that binds particular phases — and "install" is, by default, not mapped.
This map can be, however, configured in the POM of your project (ideally, the main POM). See: M2E_plugin_execution_not_covered

Related

How to create maven project as dependent jar to other projects without dependencies

I have a java project called "A" it has some custom annotations implemented in spring aop way and it is packaged as jar using maven jar plug-in, which contains only classes specific to project of A without any dependencies.now i have installed it in local maven repository using install command (mvn install:instlal-file) and used it as dependency in another maven project called "B".
I can able to get those annotations in project "B" but i cannot get dependencies automatically from pom file in dependent jar(project "A").due to which building project "B" is failing.
Q1: should we put all dependencies which we are using for project "A" in project "B" pom as well?
Q2: or it could get automatically downloaded from dependent jar pom file?
Note: am not interested in fat jar? but its working fine if we mention all dependencies in project "B". is there any way to get all dependencies when we build project "B" automatically?
Please help me in this.
I guess your error was to use mvn install:install-file. If you do not add the POM as parameter, an (almost) empty POM is created for you.
The right way:
Go to project A and run mvn clean install.
Then use A in B, and enjoy full transitive dependency resolution.
So, to summarize, the answer for Q1 is "no", and the answer for Q2 is "yes, use mvn clean install instead of mvn install:install-file.

Setup maven pom to work with dependencies across environments

I have a Java projects a-1.0.jar with ojdbc.jar dependency and b.jar that depends on a-1.0.jar and ojdbc.jar. I am trying to make it work on my machine, new user machine and a Bamboo server.
Desired behavior:
On local machine git clone <git_url>, mvn clean install, java -jar b.jar project should run. Bamboo should checkout and run project.
On Bamboo: a plan can check out a project and run it. Build should track version of b.jar built and a.jar used.
So far I saw these options:
<systemPath>${project.basedir}/lib/a-1.0.jar</systemPath>: maven warns that it will fail to resolve dependencies
A Perl script to run mvn install for each dependent jar before building the project
(1) defeats the purpose of DevOps automation
(2) makes it unclear which version of a jar was used
(3) installs the jar, but java -jar b.jar fails a.jar is missing
I can overcome this with another Perl script that adds the dependent jars to a classpath
These are basic tasks and as a build tool Maven should be able to do it.
How to tell Maven to three goals below?
(1) For each unknown import - get a jar from lib folder
(2) Make a set of dependent jars. That is don't import ojdbc twice
(3) Pack a self sufficient jar that runs, not fails with "stuff is missing"
Seems like you need to create an executable jar - and for this, you can use various approaches.
One of them is, add maven-shade-plugin which puts all dependencies into single jar, while taking care of potential resource collisions.
Try non-maven-jar-maven plugin. It adds jars that are not in the maven central.

Maven plugin Tycho -> when to use it and when not to use it

What is the purpose to use Maven Tycho plugins. I read here tycho is used for building eclipse plugins and OSGI bundle.
Questions:- Can not we build eclipse plugins and OSGI bundle just by using the plain old maven POM.xml file[by not using tycho plugin].
What does maven need tycho plugin to help it build eclipse plugin and OSGI bundles?
Why should we use Maven tycho plugin to build eclipse plugins and OSGI bundles?
When using maven (or other command line build tools) manifest.mf) in combination with Eclipse (or another IDE) the classpath ends up being written down twice - once in the pom.xml and once in the Eclipse .classpath (or, for OSGi, in the target platform and manifest.mf). This violates the DRY principle.
There are various solutions to this problem. One is something like m2e, where you use the pom.xml to generate the Eclipse .classpath. Alternatively, you can go in the other direction and start by getting things compiling in Eclipse, and then use a maven plugin to convert that Eclipse setup to a maven build. This is what Tycho does, with the extra wrinkle that it works from a PDE manifest + target platform rather than directly from the .classpath.
Maven doesn't have a built-in packaging type for OSGi bundles and/or Eclipse plugins. So unless you want to use the jar packaging type and manually add OSGi specifics, you need a Maven plug-in to help you with this.
Tycho is one of the plugins that add support for building OSGi bundles.

How to rebuild dependencies before running jetty from maven

I have a multi module maven project. One of the modules is a reusable part which is packaged into a jar, and the other is a war web-app which depends on the first module. When I use jetty:run-exploded on the second module, the packaged jar is taken from local maven repository whereas I want the first module to be rebuild and packaged into the resulting war. Is there any way to force such behavior instead of the default one?
From everything I can tell from reading documents about Maven's design and using Maven myself this cannot be done in the projects own directory.
Maven will not follow module paths UP a hierarchy. Using -amd (also make dependencies) will only work at the top level module that ties all the other multi-module pom's together. So what you can do is this:
At the TOP level directory
mvn -amd -pl jetty_module jetty:run-exploded
I think you can use maven Advanced Reactor Options to archive this.
http://www.sonatype.com/people/2009/10/maven-tips-and-tricks-advanced-reactor-options/
The -pl or –projects option allows you to select a list of projects from a multimodule project. This option can be useful if you are working on a specific set of projects, and you’d rather not wait through a full build of a multi-module project during a development cycle.
Maven -amd(also-make-dependents ) also help to build multi module project once. Using that you can build a project and any project that depends on that project.

How do I get IntelliJ 10 to deploy a project that uses JiBX?

I have a multi module maven project (a war) on of these modules utilized executes a post-compile step to update JiBX bindings.
I would like to use IntelliJ to build and deploy this project. However I can't seem to figure out how to get IntelliJ to kick off the JiBX compiler. Any thoughts?
If it isn't possible to kick off the JiBX compiler, I'd like IntelliJ to treat the module that requires the JiBX compilation step as a "normal" dependency and simply pull the appropriate jar from my local maven repository.
If you don't have this already... in your IntelliJ run/debug configuration check the "Run Maven Goal" checkbox and choose jibx:bind from the jibx entry under plugins.

Resources