Maven dependency visualization in JEE7

19 07 2014

Another short, concise and informative Adam Biens’ scrrencast, this time about Visual EE Maven plugin that visualizes JEE 7 app dependencies, events, CDI, EJBs and JPA relations.

Watch the video here:





Eclipse: Aspectj Maven plugin execution not covered by lifecycle

7 06 2014

aspectj-logoMaven and eclipse integration is not straightforward. There is one m2e eclipse plugin giving support for Maven itself and a lot of other Eclipse plugins to support Maven plugins used in pom.xml.

One of these plugins is the org.codehaus.mojo:aspectj-maven-plugin – the aspectJ Maven plugin. So when you use it in pom.xml and import into eclipse, you will get error:

Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.2:compile (execution: default, phase: process-sources), Maven Project Build Lifecycle Mapping Problem

To fix it

Install AspectJ Maven Eclipse plugin from Eclipse update site (Via eclipse Help -> Install new software…):

http://dist.springsource.org/release/AJDT/configurator/

Prerequisities

To install above maven plugin Eclipse needs to have AspectJ Development Tools Eclipse Plugin and AspectJ compiler installed. If you do not have it, you need to install as well. This is where you can find it (install via eclipse Help -> Install new software…):

http://download.eclipse.org/tools/ajdt/43/update/

Did I help you?
I manage this blog and share my knowledge for free, sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





Maven and apklib: Duplicated file error

31 05 2014

The maven build error occurred when I had two Android projects: the one is apklib and the second one that is the actual application (the apk file) that uses apklib.

The error is saying that apk project contains duplicated R.java and BuildConfig.java files under target directory. The first file comes from apk project, and the second one from apklib.

There are two solutions for this problem:

Solution 1: Update android-maven-plugin

Update android-maven-plugin to the newest version (currently it is 3.8.2 or 3.9.0 release candidate to be checked here) where this bug is fixed.

The problem is that for example the 3.8.2 release is supporting only maven in version 3.1.1. no lower nor higher version will work. This would require downgrading maven on few machines so I decided to use another solution.

Solution 2: Remove conflicting files during apklib build with maven ant plugin

I’ve found solution on the Internet to remove duplicated files from the apklib target with ant plugin during build. The maven-antrun-plugin can do it. I added these lines to apklib pom.xml:

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-antrun-plugin</artifactId>
	<executions>
		<execution>
			<phase>process-classes</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<configuration>
				<tasks>
					<delete dir="${project.basedir}/gen" />
				</tasks>
			</configuration>
		</execution>
	</executions>
</plugin>

Then rebuild the apklib project and apk after that. This works!

Eclipse problems with ant plugin

Ant plugin is not recognized by eclipse maven m2e connector and eclipse displays errors. the project still can be built with either maven or eclipse build, but the error is visible on the pom.xml.

Then with plugin management in apklib you can force eclipse to ignore the ant plugin command. It does not affect maven build, just the eclipse compilation.

You can do it by eclipse quick fix or by adding manually plugin management directive to apklib’s pom.xml:

<pluginManagement>
<plugins>
	<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
	<plugin>
		<groupId>org.eclipse.m2e</groupId>
		<artifactId>lifecycle-mapping</artifactId>
		<version>1.0.0</version>
		<configuration>
			<lifecycleMappingMetadata>
				<pluginExecutions>
				<pluginExecution>
					<pluginExecutionFilter>
						<groupId>
							org.apache.maven.plugins
						</groupId>
						<artifactId>
							maven-antrun-plugin
						</artifactId>
						<versionRange>
							[1.3,)
						</versionRange>
						<goals>
							<goal>run</goal>
						</goals>
					</pluginExecutionFilter>
					<action>
						<ignore></ignore>
					</action>
				</pluginExecution>
				</pluginExecutions>
			</lifecycleMappingMetadata>
		</configuration>
	</plugin>
</plugins>
</pluginManagement>




Maven & Android: complete pom.xml files contents

17 11 2012

The complete pom.xml file I use for Android projects is as follows.

1. Main Android application’s pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>pl.looksok</groupId>
	<artifactId>ColCalc</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>apk</packaging>

	<build>
		<sourceDirectory>${project.basedir}/src</sourceDirectory>
		<plugins>
			<plugin>
				<groupId>com.jayway.maven.plugins.android.generation2</groupId>
				<artifactId>android-maven-plugin</artifactId>
				<version>3.3.2</version>
				<configuration>
					<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
					<assetsDirectory>${project.basedir}/assets</assetsDirectory>
					<resourceDirectory>${project.basedir}/res</resourceDirectory>
					<genDirectory>${project.basedir}/gen</genDirectory>
					<deleteConflictingFiles>true</deleteConflictingFiles>
					<undeployBeforeDeploy>true</undeployBeforeDeploy>
					<sdk>
						<platform>7</platform>
					</sdk>
				</configuration>
				<extensions>true</extensions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.5.1</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<!-- java project dependency -->
		<dependency>
			<groupId>pl.looksok.logic</groupId>
			<artifactId>ColCalcLogic</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>

		<!-- android apklib project dependency -->
		<dependency>
			<groupId>pl.looksok.currencyedittext</groupId>
			<artifactId>CurrencyEditText</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<type>apklib</type>
		</dependency>
	</dependencies>
</project>

Please remember to set target Android SDK and java version in file above. In my case Java version is 1.6, and SDK is 7. Keep the same config in AndroidManifest.xml.

2. apklib – Android library project pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>pl.looksok.currencyedittext</groupId>
  <artifactId>CurrencyEditText</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <!-- set up packaging -->
  <packaging>apklib</packaging>
  <build>
    <sourceDirectory>${project.basedir}/src</sourceDirectory>
            <plugins>
                <plugin>
			<groupId>com.jayway.maven.plugins.android.generation2</groupId>
			<artifactId>android-maven-plugin</artifactId>
			<version>3.1.1</version>
			<configuration>
				<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
				<assetsDirectory>${project.basedir}/assets</assetsDirectory>
				<resourceDirectory>${project.basedir}/res</resourceDirectory>
				<genDirectory>${project.basedir}/gen</genDirectory>
				<deleteConflictingFiles>true</deleteConflictingFiles>
				<undeployBeforeDeploy>true</undeployBeforeDeploy>
				<sdk>
					<platform>7</platform>
				</sdk>
			</configuration>
			<extensions>true</extensions>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>2.5.1</version>
			<configuration>
				<source>1.6</source>
				<target>1.6</target>
			</configuration>
		</plugin>

        </plugins>

        <pluginManagement>
		<plugins>
		<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
		<plugin>
			<groupId>org.eclipse.m2e</groupId>
			<artifactId>lifecycle-mapping</artifactId>
			<version>1.0.0</version>
			<configuration>
				<lifecycleMappingMetadata>
				<pluginExecutions>
				<pluginExecution>
				<pluginExecutionFilter>
					<groupId>com.jayway.maven.plugins.android.generation2</groupId>
		  			<artifactId>android-maven-plugin</artifactId>
		  			<versionRange>[3.3.0,)</versionRange>
		  			<goals>
		  				<goal>proguard</goal>
		  			</goals>
		  		</pluginExecutionFilter>
		  		</pluginExecution>
		  		</pluginExecutions>
		  		</lifecycleMappingMetadata>
		  	</configuration>
		  </plugin>
		</plugins>
	</pluginManagement>
  </build>
</project>

The most important change to notice is the packaging tag at the beginning – set it to apklib.

Note that eclipse does not read maven apklib dependencies from pom.xml automatically. If you want your android project to use apklib project in eclipse, you have to manually add library in your main project’s settings:

Please note also, that your apklib project has to be marked as Android Library in its properties (check it in the same project properties window as shown above). Maven plugin however should automatically mark this project as library, based on its pom.xml file.

3. jar – standard java library’s pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>pl.looksok.logic</groupId>
  <artifactId>ColCalcLogic</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Just as a remainder – this is standard pom.xml for jar library

Summary

These files are operational, after performing all maven, m2eclipse and maven for android plugin configurations

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





Use Maven with Android project

12 05 2012

In order to mavenize (existing or not) Android project in Eclipse few steps are required:

1. install m2eclipse plugin

All instructions how to do it, You will find here.

2. install ‘Android Configurator for M2E

in Eclipse go to menu:

Help -> Eclipse Marketplace

search for ‘Android Configurator for M2E’ and install it:

Here is plugin’s website. Any additional info will be provided there. Moreover here is very detailed description about Android development with Maven.

3. Install Maven 3.0.3

Android Configurator for m2e requires Maven in version 3.0.3 or higher, and m2eclipse comes with lower version. There is need to update it. Use download source site for Maven 3.0.4 and unzip it. Then in eclipse go to:

Window -> Preferences -> Maven -> Installations

and set path to downloaded files (click ‘Add‘):

4. Create pom.xml

Here is sample pom.xml from plugin’s website. The most important differences between this, and standard pom.xml are marked with green.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.simpligility.android</groupId>
    <artifactId>helloflashlight</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>HelloFlashlight</name>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>1.6_r2</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <sourceDirectory>src</sourceDirectory>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>3.2.0</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <configuration>
                    <sdk>
                        <!-- platform or api level (api level 4 = platform 1.6)-->
                        <platform>4</platform>
                    </sdk>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

If you need some more info on basic configuration of pom.xml for m2eclipse, look  here.

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





Basic Maven (m2eclipse / pom.xml) configuration

5 05 2012

Introducing Maven to Eclipse projects from scratch was described in my previous post. Now the basic usage and configuration will be described.

1a. Addind external jars (Maven dependencies)
To add some external jar file or reference to another workspace project you will need to:

Right Click on project -> Maven -> Add dependency

You can add it by filling in groupId, version etc. manually or search Maven repository by keyowrds. For example searching for JSON lib looks like in the picture below. After confirm, you will see changes reflected in pom.xml file.


1b. Another workspace project dependency
It is also possible to refer to another project, however it also has to be the Maven one (has its own pom.xml). Some instructions can be found here. Sample snippet of dependency in pom.xml is:

<dependency>
  <groupId>com.maventest</groupId>
  <artifactId>mytest</artifactId>
  <version>1.0-SNAPSHOT</version>
  <scope>compile</scope>
</dependency>

2. Setting the src folder
The issue after adding Maven nature to project in my case was Eclipse missing the source folder in project. src was present in workspace, however it was not recognized as source folder. The solution is to add following lines in pom.xml file (if more info is needed look at this source):

 <build>
   <sourceDirectory>${basedir}/src</sourceDirectory>
 </build>

Note: Setting source folder by eclipse standard way (Build path -> Configure Build Path) will have no effect, because it will be reverted after Updating Maven Configuration.

3. Set jre for project
If you want to use specific Java version in Maven project, you can use Maven plugin: compiler-plugin, as described here. It’s easy and requires only adding this entry to pom.xml file:

<plugins>
  ..
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.6</source>
      <target>1.6</target>
    </configuration>
  </plugin>
</plugins>

4. Problem with selecting targets for Maven builds
If You have problem with selecting targets (empty goals list), see solution here and corresponding bug description here.

It did not help me :D However solution makes sense and worth to try it anyway :)

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





Incorporate Maven into Eclipse project

28 04 2012

Here is short instruction how to incorporate Maven into existing Eclipse projects from scratch, step by step. The goal of Maven introduction presented here is quite generic, however I installed Maven to manage dependencies (jars). Maven build, installs or clean functions are not used by me. If You need to know more about maven itself - this screencast is good start.

1. Install eclipse plugin for maven
I recommend m2eclipse as it is most popular and works quite well. It is supported by Eclipse: 3.6 Galileo and 3.7 Indigo. Install it by ‘Install new software‘ Eclipse option. Update site link you will find on this site.

This will install its own Maven instance, so you don’t need to install Maven yourself – m2eclipse will handle it. However manual Maven installation is necessary if You need another version that is provided in m2eclipse by default.

Some very good introduction about m2eclipse is here. If m2eclipse doesn’t suit you, then you can find another plugins comparison here. The best one decided on StackOverflow.com is however m2eclipse.

2. Update existing project with maven functionality
(If You are creating new project use Eclipse -> New Project and choose type: Maven. Params to enter are the same as described below)

To create pom.xml file and tell to m2eclipse to use this file:

Right click on project -> configure -> Convert to maven project

On the project configuration dialog You need to fill in these fields:

  • groupId – in fact this is main package name that is used in eclipse project. Param states that project belongs to some group, pointed by package name.
  • artifactId – project name that is used in Eclipse. This will be the name of the file that will be produced by Maven after compilation (e.g. name of external jar)
  • archetype – project type. This is similar to creating new project in Eclipse, where You choose on of the project types at the beginning (Android project / Java project / Dynamic Web Project etc.). Like Eclipse project types, Maven provides its archetypes. Choosing proper one, eases project configuration. Maven preconfigures its structure and pom.xml file.
  • dependencies – list of all jars or another workspace projects required for Mavenized project to run. Referenced workspace projects should also be maven ones.

3. Updating Maven project configuration
After making changes in Maven config (pom.xml file) you will have to update project configuration to reflect these changes in project.
Do it by:

Right Click on th project -> Maven -> Update project configuration

4. That’s all

On another computer, where this project is used it is enough to install m2eclipse (point 1.) and trigger ‘Update Project Configuration’ (point 3.).

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!








%d bloggers like this: