If I have 6 modules in my project is it possible to build only one out of six ? without commenting out others ?
EDIT
Submodule will not work itselft because or parent tags. I need to install the parent first to make it build. how can I do it without installing parent
is it possible to build only one out of six ? without commenting out others ?
My understanding is that you want to launch maven from the aggregating project (i.e. a reactor build) but only build one module. This is possible using the -pl, --projects project list option (see advanced reactor options):
mvn --projects my-submodule install
This is a very powerful option, especially when combined with --aslo-make (to also build the projects on which the listed modules depend) or the --also-make-dependents (to also build the projects that depends on the listed modules). On the basis of your update, you might want this actually:
mvn --projects my-submodule --also-make install
Launching Maven from the directory of the module you want to build is of course an option but this won't allow you to do the things mentioned above nor to build a subset of all modules. For such use cases, the advanced reactor options are the way to go.
Opening a command shell, navigating to the submodule directory and executing mvn install (or whatever your preferred lifecycle is) should do the trick.
You can simply build the module by going in this module directory and run the mvn clean install.
However, note that with this method, the dependencies with the others modules will be taken from your local repository (or the entreprise repository).
Let's take a simple example:
project
+ commons
+ business
Now, imagine that you build, on the root directory the whole project, using the mvn clean install command. Consider that all your modules are in version 1.0.
Now, you move to version 1.1. If you run the mvn clean install on the business project only, it will try to get the 1.1 of module commons. You will then have an error, as Maven will not find any version 1.1 in your local repository.
Within Eclipse, assuming you have m2eclipse installed: Right-click on the module in question and choose Run As -> Maven package.
Related
I have a multi-module application with many sub-modules.
I want to be able to run maven install on the open projects ONLY at one shot.
Running maven install on the parent pom will install ALL modules (most of the projects are closed or not even imported).
How to achieve this (preferably without having to create an eclipse plugin for this)?
You have need to create childs POM.xml for each module so that it depends on you You want used child POM.xml or not.
Hope this solved your issue.
In your case, I think that the more relevant solution is specifying the command you want to execute in a script (.sh, .bat) and execute it from External Tool of Eclipse.
A more intrusive solution would be to add in the aggregator pom, one or several Maven profiles where you define the relevant modules for the build.
If several developers of your team have the same problematic as you, integrating it in the aggregator pom may be a very suitable solution otherwise if the need is not shared, scripts + External tools seems the better solution.
I'm hacking on a Maven-based project with a lot of dependencies; the project is normally meant to be developed in Eclipse but I need to work on it from the command line.
How to build+execute the project in a sane way? Something like mvn run, but of course Maven is not meant for running Java projects (for some reason).
The problem is specifying all the dependencies on java's commandline, I don't even know how to autogenerate that. I can currently deal with it using the assembly:single maven plugin (using the jar-with-dependencies descriptor) which will package the dependencies to a single .jar for me.
However, there really is a lot of dependencies and the assembly phase can take about two minutes, greatly disrupting my hack-test cycles so I'm looking for other ways to run the project with minimum build overhead - any recommendations, please?
Note: One possibility is running it in Eclipse once and capturing the java commandline. However, that's just a one-time hack, not a general solution in case I change pom.xml later or come to another project from the suite without Eclipse access anymore.
Have a look at the maven exec plugin
mvn exec:java -Dexec.mainClass="com.example.Main"
if you do this frequently, you can of course configure it via plugin configuration.
Regarding finding out project dependencies - you can use maven dependency plugin
http://maven.apache.org/plugins/maven-dependency-plugin/list-mojo.html
If you want to put them into file it'd be smth like
mvn dependency:list > dependencies.txt
See this question: How can I create an executable JAR with dependencies using Maven?. You can use the dependency-plugin to generate all dependencies in a separate directory before the package phase and then include that in the classpath of the manifest.
I see three solution to this:
onejar-maven-plugin - faster than assemlby with jar-with-dependencies descriptor
With onejar-maven-plugin, you'll (...) get a nice clean super jar with the dependency jars inside.
Spring Boot Maven Plugin - but this is dedicated to Spring projects
Maven Assembly Plugin with custom descriptor. This custom descriptor should grab all dependencies into lib folder, maven-jar-plugin should set Class-Path in Manifest.fm according to this new location. After this you can simply execute your program or zip your jar with lib folder as distribution.
After this is possible to run your program on your computer or any other with one command:
java -jar myjar.jar
I'm new to Maven and m2e. It frustrates me that I have to ask this question, but the sparse m2e documentation and Google are failing me.
How do get m2e to build a JAR? I understand that this should happen during the maven package phase, but m2e doesn't seem to do this as part of the build process and I can't find a way to explicitly execute the package phase in Eclipse (nor any other phases that aren't part of the default build).
Thanks.
As long as you have your POM.xml file with the following parameters:
<modelVersion>[a model number eg 4.0.0]</modelVersion>
<groupId>[a group id eg com.myapp]</groupId>
<artifactId>[a unique artifact id within your packages eg myapp]</artifactId>
<version>[the version number eg 1.0-SNAPSHOT]</version>
<packaging>jar</packaging>
<name>[the name eg myapp]</name>
then you just need to run maven build with the goals clean install to create a jar file from your project. You can run maven build by right clinking on the project and going to run > maven build ...
The jar will be created in [project dir]/target
Although "Run As maven install" would do the trick, it can be good
to know that m2e will perform the equivalent of the package phase when doing "Export... Jar/War/EAR file". It seems to understand the plugin configurations too, at least a little bit, and at least for EARs...
As it will resolve artifacts using projects and the m2 repository,
it will also work for "unrelated" modules, as the dependency that resolves to a project is good enough for eclipse to package.
(That is, you don't have to install the unrelated dependency separately, it will be built automatically from the eclipse project.)
I'm not sure I would deploy anything it builds though :-)
I was wondering if there is a standard way (i.e. a plugin) to apply a set of patches during a Maven build. Patching the code base in a dedicated step before building is getting tedious as soon as you have different builds or generated sources.
To give an example, this script should deploy 3 different versions from a fresh SVN checkout:
#!/bin/bash
# checkout project
svn checkout http://example-project.googlecode.com/svn/tag/v1_0 example-project-read-only
cd example-project-read-only
# build example-project-1.0
mvn deploy
# build example-project-1.0-a3
mvn -Dmaven.patch.dir=/path/to/patchesA -Dmaven.patch.buildSuffix=a3 clean patch:patch deploy
# build example-project-1.0-b0
mvn -Dmaven.patch.dir=/path/to/patchesB -Dmaven.patch.buildSuffix=b0 clean patch:patch deploy
Currently I'm doing similar things with another build script I'd like to get rid of. Therefore I'm considering to write such a plugin if it's not available yet. (Maybe with dedicated patch artifacts for easy distribution as an added bonus?)
The maven patch plugin might help.
The Patch Plugin has a single goal that can apply either a single declared patch or a directory of patches. Application of an entire patch directory can be configured with various patch-inclusion, -exclusion, and -ordering options:
I haven't heard of any such plugin. However I imagine that you could do something with profiles that applied patches and conditionalized the build dir. Sounds interesting.
Our software is written in Java and comprise many (7) projects.
These projects are Netbeans ant projects.
I'm considering to converting them to maven2.
Where can I find some hints for doing such thing?
Don't read that book. It will only make you confused. Read this book instead: "Maven - The definitive guide" http://www.sonatype.com/books/maven-book/reference/ .
Also, the maven site has a lot of information, but the structure is terrible so you'll need to use google to navigate in it.
Here is my suggestion:
Do this by hand, not with "automagic" "help" from the IDE. Maven integration doesn't work that good yet, not in any IDE.
Make sure you program project is divided into modules under a common umbrella module, so that each module produces a single binary artifact (jar, war,...) possibly accompanied by the javadoc of the source code behind that artifact, a zip with the source code etc. The basic principle is that each module produces a single artifact, containing all the non-test-code under that module. You can do this while the project is still built by ant.
Each module should conform to the standard maven directory layout. The build destination is under [module]/target/[output-type, e.g. "classes"]. The source code is under [module]/src/main/[src-type e.g. "java"] and [module]/test/[src-type]. The artifact consists of all the code under src/main, and none of the code under src/test, as it built to the target directories. You can do this while the is still built by ant.
Start by transforming the sub-module that has no dependencies on other modules in the project.
Now you can create the parent maven module pom.xml with artifact type "pom", consisting of one of the modules below. Make a child module for the first submodule (the one with only external dependencies), using the umbrella module as "parent". Remember that you need to specify version for the parent. Remember to add the child module as a "module" in the parent too. Always use ${project.version} as version in the child modules when you create multi-module projects like this. All modules under a parent must be released simultaneously in a single operation, and if you use this setting maven will make sure the version fields stay the same across all modules and gets updated everywhere during the release. This may make it difficult to re-use the existing numbering scheme, but that doesn't matter. You are never going to run out of version numbers anyway.
Add the necessary dependencies, and make sure you can build the parent and the child module together using the command "mvn clean install" from the parent module.
Proceed with the rest of the modules the same way. Dependencies to other modules under the same parent project should also use ${project.version} as the "version" they are depending on, meaning "the same version as this". NOTE THAT in order to build, the module you are depending on must be built using "mvn install", so that it gets deployed to you local (computer) repository. Otherwise the depending module will not be able to find the classes. There are NO source-code dependencies between modules in maven, only dependencies to built and packed versions installed in local and remote repositories. This can be very confusing if you come from ant-projects. Build from the root module until you get comfortable with this. It takes two days.
Don't use maven integration in IDEs. It is a bad idea. Use "mvn idea:idea" or "mvn eclipse:eclipse" to set up your workspace as a non-maven ordinary IDE project. The inter-module dependencies mechanisms in maven and the IDE aren't identical and will never be. Also, if you have several mavenized projects with dependencies in between, you want to have several of these in your workspace with dependencies set up between. You can do this with mvn idea:idea / eclipse:eclipse if you create a separate maven project file called "workspace.xml" (or whatever) in the same directory as parent module, set up as a multi-module project containing modules "." and "../otherproject" (only one-way reference here, no parent ref back). If you run "mvn idea:idea / eclipse:eclipse -f workspace.xml" you get a workspace with all these modules linked together. No IDE integration lets you do that. This sound like a lot of extra work, but the workspace.xml-file is really small. It doesn't have to contain all that dependency stuff and all that, only the reference to the modules you want to bind together in your IDE.
I did a succeful migration of NetBeans Ant project to Maven project using the instruccions by Joseph Mocker here: http://forums.netbeans.org/ptopic55953.html
I cite the important part:
close the project
rename the build.xml, nbproject files/folders to something so NB won't recognize them.
close and restart NB (so any memory cache knowledge of the project is gone)
copy in an empty pom from some other project.
open the project back up in NB (NB should now identify it as a maven project)
rearrange the files to follow the maven way (™)
This won't be an easy task since Maven2 expects the files to be organized in a specific way. Anyway Better Builds with Maven is a free book that should get you started. It will help you understand Maven and it also has a chapter on migration.
I discovered that the migration is not necessary. The real requirements that I need was automatic download of dependencies (libraries).
This is also achieved by Ivy which nonetheless uses maven repositories.
I solved converting project from ant to ant+ivy with IvyBeans.
I have built a script to migrate Ant builds to Maven. You can find more information here:
https://github.com/ewhauser/ant2maven
It won't help you with fixing your directory structure and or any additional Ant tasks, but it removes a lot of the tedious steps to get started.