Maven Documentation
52°North Repositories
The 52-North Artifact
<parent>
<artifactId>52-North</artifactId>
<groupId>org.n52</groupId>
<version>5.6.13</version>
</parent>
Always check for the
latest version.
Maven Installation
Get Maven from
http://maven.apache.org/download.html and follow the installation instructions at the bottom of the page.
Configuration
Besided the information on this page there are the following specific Maven-related topics:
General Configuration
Maven's backend is its repository
http://repo1.maven.org. The
Human Readable Interface is here:
http://mvnrepository.com/.
You can get many commonly used Java libraries there. However for our development we need our own repository. In order to tell Maven how to use it, you have to change your settings.xml file, which can be found in
<user folder>/.m2/settings.xml
. More documentation about Maven settings can be found here:
http://maven.apache.org/settings.html.
Adding 52°North Repositories
To specify and activate the 52°North repositories add the following sections to your
settings.xml
.
[...]
<profiles>
[...]
<profile>
<id>52n-start</id>
<repositories>
<repository>
<id>n52-releases</id>
<name>52n Releases</name>
<url>http://52north.org/maven/repo/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>n52-snapshots</id>
<name>52n Snapshots</name>
<url>http://52north.org/maven/repo/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>apache</id>
<name>apache Releases</name>
<url>http://people.apache.org/repo/m2-snapshot-repository/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
[...]
</profiles>
[...]
<activeProfiles>
<activeProfile>52n-start</activeProfile>
</activeProfiles>
[...]
</settings>
Adding SpringSource Enterprise Bundle Repository
When building projects depending on SpringSource dependencies, please take a look at and add the following repositories to your project or configuration using:
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/release</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
Using Maven
Checking out a project
Check out the project you want into a local directory (this directory
must not be an eclipse workspace!)
Please take a look at the
52°North portal, because the location of the
svn repositories has changed (
more information...).
|
Please incorborate the instructions into this page Take a look for the
walkthrough for Linux (adaptable for Windows as well). Please remind, for the WPS software you'll need additional repositories. Take a look
here (under "Installation of the service (CVS and maven instructions)").
After dowloading the files from the remote repository you can continue with loading the dependencies and optionally integrate you local copy into eclipse.
Installing in local repository
Installing into your local maven-repository means that maven downloads all dependencies from remote repositories into its local cache. Furthermore Maven complies your local sourcecode and creates packages in your local maven-repository.
You can skip this step if it fails and you just want to get the project into eclipse.
mvn install
Deploying to the remote repository
Deploying into the remote 52°North repository is only needed if you want to share libraries with other projects or you want to upload something for your team that is not in a shared repository.
For more instruction have a look here:
MavenDeploymentInfos
52°North Distribution Servers
The n52-sites-dist points to
http://52north.org/maven/project-sites/ location, but don't be afraid to override this location, because the maven-site-plugin will extend this url with the artifactId of your project,
e.g , or concrete
http://http://52north.org/maven/project-sites/52n-security
n52-releases-dist
Upload URL:
dav:https://52north.org/maven/repo/releases
Points to
http://52north.org/maven/repo/releases
n52-snapshots-dist
Upload URL:
dav:https://52north.org/maven/repo/snapshots
Points to
http://52north.org/maven/repo/snapshots
n52-sites-dist
Upload URL:
dav:https://52north.org/maven/project-sites
To use this site add the following section to your pom.xml with the respecitve
artifactID
, e.g.
http://52north.org/maven/project-sites/swe
, and the the parent to the 52-North artifact.
<project>
<parent>
<artifactId>52-North</artifactId>
<groupId>org.n52</groupId>
<version>5.6.4</version>
</parent>
[...]
<distributionManagement>
<site>
<id>n52-releases-dist</id>
<name>repository for 52°North project sites</name>
<url>dav:https://52north.org/maven/project-sites/[$artifactId here]</url>
</site>
</distributionManagement>
[...]
</project>
Best Practices
- BestPracticeJarsInMaven - How to include libraries, i.e. jar files or dll's, into Maven projects which are not available in on-line repositories, for example because of licensing issues, patched versions, or custom libs.
- BestPracticeDifferentPropertySetsInMaven - How to separate different property sets containing sensible property information for arbitrary target environments (test, development, serverA, serverB, etc)
Maven and Eclipse
Create Eclipse Projects
Maven can automatically create eclipse project files. Additionally maven creates links from your local repository to eclipse for all the jars you need.
Once for each workspace, Eclipse needs to know the path to the local maven repository. Therefore the classpath variable M2_REPO has to be set. Execute the following command: mvn -Declipse.workspace= eclipse:add-maven-repo
|
Now you can run
mvn eclipse:eclipse
from the root of you you module (e.g.
/home/user/52n-repo/sas/trunk/
).
Checkout Maven Projects with Eclipse
If you have the latest Eclipse and
m2e plugin installed you can easily download Maven projects. Open the project root folder, e.g.
MyProject/trunk
, which is the one with the
pom.xml
file. Then right click on the folder and select "Check out as Maven Project..." and follow the (few) steps in the Wizard. If neccessary, install SCM connectors for m2e by clicking the link in the lower right corner of the dialogue. You also might have to update the project configuration.
Debug Unit Tests with Maven in Eclipse
If you want to debug the unit tests but still run them with Maven (for example because the tests need resource filtering), add the option
-Dmaven.surefire.debug
to the goal in the Run Configuration, e.g.
test -Dmaven.surefire.debug
. Then run the test. The console will stop at a line like
Listening for transport dt_socket at address: 5005
and wait for a remote debugger connection before continuing with the tests. You have to create that connection now (Debug Configurations > Remote Java Application > Create New) and set the host to localhost and the port to the one mentioned in the console (in our example
5005
). Name the Debug Configuration accordingly and start it by clicking
Debug.
Maven and XMLBeans
There are detailed instructions how to build ogcschema with maven and xmlbeans:
MavenOgcXmlbeans. Furthermore there is the former general
MavenXMLBeans description.
Frequently Asked Questions and Troubleshooting
StackOverflowException during compile
Sometimes you can receive errors this the following during any maven compile run:
[INFO] Compilation failure
Failure executing javac, but could not parse the error:
The system is out of resources.
Consult the following stack trace for details.
java.lang.StackOverflowError
at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:1799)
at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1522)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:360)
at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:377)
at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1241)
at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1210)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:360)
... then trace repeats multiple times
The solution is to increase the JVM stack size by adding
-Xss2048k
to your
MAVEN_OPTS
. Further reading:
If you have any working solution how to add this parameter to the POM, please share it! The solution presented at stackoverflow.com did not work for me. --
EikeHinderkJuerrens - 2014-04-16
Unable to download the artifact from any repository
I get the error:
> [INFO] Scanning for projects...
> Downloading: http://repo1.maven.org/maven2/org/n52/swe/swe/1.0/swe-1.0.pom
> [INFO] -------------------------------------------------------------------
> -
> [ERROR] FATAL ERROR
> [INFO] -------------------------------------------------------------------
> -
> [INFO] Failed to resolve artifact.
>
> GroupId: org.n52.swe
> ArtifactId: swe
> Version: 1.0
>
> Reason: Unable to download the artifact from any repository
>
> org.n52.swe:swe:pom:1.0
If maven cannot find the swe-xxx.pom or on of the 52North-xxx.pom files, you need to add the 52North repository to your settings-file. See section configure above. --
JanTorbenHeuer - 02 Nov 2007
Cannot find parent: org.n52
i get the error:
> [INFO] Scanning for projects...
> [INFO] artifact org.n52:52-North: checking for updates from central
> [INFO] ------------------------------------------------------------------------
> [ERROR] FATAL ERROR
> [INFO] ------------------------------------------------------------------------
> [INFO] Error building POM (may not be this project's POM).
>
>
> Project ID: org.n52.security:52n-security-api:pom:2.0-SNAPSHOT
>
> Reason: Cannot find parent: org.n52:52-North for project: org.n52.security:52n-s
> ecurity-api:pom:2.0-SNAPSHOT for project org.n52.security:52n-security-api:pom:2
> .0-SNAPSHOT
Make sure that your settings.xml is confgured correctly and located at USER_HOME\.m2. You can obtain the file below.
Generics are not supported in -source 1.3
I get the error (or similar):
D:\workspace\common\src\main\java\org\n52\swe\common\types\IAnyNumerical.java:[4
1,30] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
public interface IAnyNumerical> {
This means, that you have java code which is not compilable by java compiler less java5. Since mavens default java compiler level is less than 5 you have to add to your pom file the following:
<dependencies>
<!-- your dependencies here -->
</dependencies>
<build>
<!-- For annotations and other Java5 stuff -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
The current stable release of Maven (2.0.9) does not allow to specify more than one proxy server which is a problem if you need to deploy releases, snapshots, and sites from behind a proxy via webdav with https, while other urls need to be accessed via simple http. I created patches for Maven 2.0.10-RC6 (
https://svn.apache.org/repos/asf/maven/components/tags/maven-2.0.10-RC6) and the maven site-plugin 2.0-beta-7 (
https://svn.apache.org/repos/asf/maven/plugins/tags/maven-site-plugin-2.0-beta-7) that allows to specify more than one proxy.
Eclipse and m2e plugin
Archive for required libray ... cannot be read or is not a valid ZIP file.
Using the Eclipse Maven plugin can sometimes be a bit bumpy. The error message above often means that a download of a library was not successful, which you can easily check by opening the path in the error message and checking the file
<library name>-<versiong>.jar
. If its
size is 0 KB then is invalid. To fix this, just delete the whole folder
<library name>/<version>
and update the project dependencies. Maven should now re-download the library and hopefully install it properly.
Progress is stuck in ... "download sources and javadoc"
If you check out a project for the first time, Eclipse and m2e might get stuck in a task (shon in the Progress view) called "Downloading Sources and Javadoc" for a long time, possibly forever. You cannot quit Eclipse or change anything in the project while Eclipse is waiting for this to happen. However, it might not ever happen and Maven probably checks all the repositories if the source files and Javadoc files of all the dependencies are available.
You can disable this in the Maven configuration:
Window > Preferences > Maven >
Disable "Download Artifact Sources" and "Download Artifact
JavaDoc".
You can also run mvn install from the console, which often solves these kinds of problems and less prone to errors during downloading. Afterwards, "Update Dependencies" in Eclipse and everything should work.
The container 'Maven Dependencies' references non existing library '...jar'
Take a look in the shown path wether the library is missing. You can try to force a redownload of the library by deleting the whole folder
<library name>/<version>
.
You can also run
mvn install
from the console, which often solves these kinds of problems and less prone to errors during downloading. Afterwards, "Update Dependencies" in Eclipse and everything should work.
The Maven-skin sources are located at:
https://svn.52north.org/svn/52n/maven-skin/trunk
Install the skin locally simply with
install
If you are going to update the Maven-skin version, you will also have to update the 52n parent project located at:
https://svn.52north.org/svn/52n/maven-root-project/trunk
Install the parent locally with
install site:attach-descriptor
The basic layout for all community sites is generated using Apache Velocity (
http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html). in the Maven-skin project you will find a velocimacro file (site.vm) in the folder /src/main/resources/META-INF/maven.
Until today (2012-03-08) there are three communities, who build their sites with maven, Sensor Web, Geoprocessing and Security & Geo-RM. If there is going to be an new community, who will also build their sites with Maven, here is what you have to do to highlight the name in the drop-down menu:
The community names are highlighted via an if-statement. You can find it in the
site.vm
circa line 580ff. The beginning should look like the following:
580 #if ($communityName.equalsIgnoreCase("Geoprocessing"))
581 <li><a href="http://52north.org/communities/geoprocessing" class="active" id="menu174" title="Geoprocessing"><span class="menu-title">Geoprocessing</span></a></li>
582 #else
583 <li><a href="http://52north.org/communities/geoprocessing" id="menu174" title="Geoprocessing"><span class="menu-title">Geoprocessing</span></a></li>
584 #end
The code is bassically the same for Sensor Web and Security & Geo-RM. The property
$communityName
in line 580 must be initialized in the respective pom of the project the sites are build with, meaning there has to be a property
in the pom. Example:
<properties>
<communityName>Geoprocessing</communityName>
</properties>
If the property exists and is one of the three:
SensorWeb, Geoprocessing, Security, the respective menu item will be highlighted. Otherwise nothing will be highlighted.
If you want to add a new community to the menu and also allow highlighting you will have to add the following to the site.vm (replace with real values where necessary):
580 #if ($communityName.equalsIgnoreCase("NewCommunity"))
581 <li><a href="http://52north.org/communities/new-community" class="active" id="menu174" title="New Community"><span class="menu-title">New Community</span></a></li>
582 #else
583 <li><a href="http://52north.org/communities/new-community" id="menu174" title="New Community"><span class="menu-title">New Community</span></a></li>
584 #end
Add the following to the pom you build the sites with:
<properties>
<communityName>NewCommunity</communityName>
</properties>
You will have to deploy the updated Maven-skin to the repository, so that the changes are available for the other communities. This is described in the next section.
Deploying updated Maven-skins
There are two ways of deploying updated Maven-skins. The first one, deploying without increased version, is simple, but not entirely clean. The second one, deploying with increased version, requires updating the version of th 52n parent (root) project.
Deploying without increased version
If you have changed something in the Maven-skin source code, you can deploy it simply by executing
mvn deploy
If you want to deploy to a specific repository add something like the following
mvn deploy -DrepositoryId=n52-releases-dist
Now the current version of the Maven-skin will be replaced by your updated version.
NOTE: This can lead to problems for others, who want to build their sites with the updated skin, because the local version of the skin will not be automatically updated. They will have to delete it manually from their local maven repository first, to get the updated version from the 52n repository.
Deploying with increased version
A more clean method to deploy an updated skin is to increase the version. After you have modified the sorce code of the Maven-skin project, increase the version in the pom. E.g. from 8 to 9. Deploy the skin as described in the previous section.
Now you will have to adjust the version in the 52n parent project. Open /src/site/site.xml and change the version of the Maven-skin accordingly. To avoid the same pitfall as described in the previous section you should increase the version of the parent pom as well. You can do this in the pom, e.g. from 5.6 to 5.7. The 52n parent project can deployed with the following command:
deploy site:attach-descriptor
Add specific repository:
deploy -DrepositoryId=n52-releases-dist site:attach-descriptor
Now updated versions of skin and parent should exist in the repository. To build the community sites with the new skin you will have to increase the version of the parent in the pom used for building the sites. The new skin and parent should be automatically fetched from the repository.