Convert java plugin into maven project with eclipse-plugin packaging - java

I am quite experienced with java but i'm using maven for the first time.
i have installed Eclipse Kepler (Eclipse for RCP and RAP Developers), I have installed Tychus as well with the "add new software" button.
There is an Internet of things project that I cloned and built called OM2M.
I followed the install wiki step by step and everything work until then.
cloning wiki here
I want to develop my own OSGI module so I went to the 'developer' section of the wiki and once again and created a new plugin project.
When i try to convert this plugin project into a maven project ( link to the step i'm talking about ) I don't have to "eclipse-plugin" packaging type for my pom wiki screenshot here.
I looked it up on the web and apparently it has something to do with Tychus that needs configuration, I tried typing it in the box but obviously I have problems when i try to build, I tried editing the main pom.xml with stuff I found but none of them work and I really don't know what to do to make it work.
Do you guys have an idea ?
Thanks
Edit : i forgot to mention that i read this thread but I don't understand the the answers, I don't know where to put the code the top answer is talking about nor do i know where to but the OSGI manifest.
Edit 2 : pom.xml i get when i enter eclipse-plugin by hands :
If i write eclipse-plugin by hand here is my 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>org.eclipse.om2m</groupId>
<artifactId>org.eclipse.om2m.sample.ipu</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
Edit 3 : I managed to remove the error by setting the main pom.xml as a parent but now when i try to build i have the following error :
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-packaging-plugin:0.20.0:validate-version (default-validate-version) on project org.eclipse.om2m.sample.ipu: Unqualified OSGi version 1.0.0.qualifier must match unqualified Maven version 0.0.1-SNAPSHOT for SNAPSHOT builds ->
I've searched for the goals but I don't know where to set or edit them.
Edit 4 : Thanks to #Wim Anckaert i've dropped the .qualifier and the .snapshot from the pom.xml and the manifest and now it seems to be working !
Thanks a lot guys.

The last error seems to be a problem with the <version> of your ./pom.xml and Bundle-Version of your ./META-INF/MANIFEST.MF file. These should be equal to each other.
A part of our pom.xml:
<artifactId>be.cs.fashion.awg.core</artifactId>
<name>CERPS</name>
<version>2.1.0</version>
<packaging>eclipse-plugin</packaging>
A part of our MANIFEST.MF
Bundle-Name: CERPS
Bundle-SymbolicName: be.cs.fashion.awg.core;singleton:=true
Bundle-Version: 2.1.0
Bundle-Localization: plugin
So in your case version in pom.xml version should be "1.0.0-SNAPSHOT" or you should use Bundle-Version "0.0.1.qualifier"
We dropped the "-SNAPSHOT" and the ".qualifier" in our versions.

The value "eclipse-plugin" is not included in the combo (i.e. the drop-down listbox here), you ought to write it by hand.
Upd: Firstly you must enable tycho. To do this, add
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>0.24.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
to your pox.xml (or, preferably, to its parent).
Then, you need to know that the wizard you show on screenshot does not search for all possible values of tag, instead it adds to "Packaging" drop-down listbox most usable values and allows you to enter any value that you want.
For more details check out here

Related

Importing Java owlexplanation libraries in Eclipse [duplicate]

I don't know how to use Maven at all. I've been developing for a couple years with Eclipse and haven't yet needed to know about it. However, now I'm looking at some docs that suggest I do the following:
"To include it within your project, just add this maven dependency to your build."
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/maven2</url>
</repository>
...
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>1.1.GA</version>
</dependency>
How do I do this with my Eclipse project?
Please assume I know nothing about Maven. I just figured out it might be installed on my computer by typing mvn on the command line, but that's seriously the extent of my knowledge. I would be happy to continue knowing nothing about Maven if there is an equivalent, non-Maven way of following these instructions with Eclipse.
On the top menu bar, open Window -> Show View -> Other
In the Show View window, open Maven -> Maven Repositories
In the window that appears, right-click on Global Repositories and select Go Into
Right-click on "central (http://repo.maven.apache.org/maven2)" and select "Rebuild Index"
Note that it will take very long to complete the download!!!
Once indexing is complete, Right-click on the project -> Maven -> Add Dependency and start typing the name of the project you want to import (such as "hibernate").
The search results will auto-fill in the "Search Results" box below.
In fact when you open the pom.xml, you should see 5 tabs in the bottom. Click the pom.xml, and you can type whatever dependencies you want.
You need to be using a Maven plugin for Eclipse in order to do this properly. The m2e plugin is built into the latest version of Eclipse, and does a decent if not perfect job of integrating Maven into the IDE. You will want to create your project as a 'Maven Project'. Alternatively you can import an existing Maven POM into your workspace to automatically create projects. Once you have your Maven project in the IDE, simply open up the POM and add your dependency to it.
Now, if you do not have a Maven plugin for Eclipse, you will need to get the jar(s) for the dependency in question and manually add them as classpath references to your project. This could get unpleasant as you will need not just the top level JAR, but all its dependencies as well.
Basically, I recommend you get a decent Maven plugin for Eclipse and let it handle the dependency management for you.
Open the pom.xml file.
under the project tag add <dependencies> as another tag, and google for the Maven dependencies. I used this to search.
So after getting the dependency create another tag dependency inside <dependencies> tag.
So ultimately it will look something like this.
<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>doc-examples</groupId>
<artifactId>lambda-java-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lambda-java-example</name>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
Hope it helps.
I have faced the similar issue and fixed by copying the missing Jar files in to .M2 Path,
For example: if you see the error message as Missing artifact tws:axis-client:jar:8.7 then you have to download "axis-client-8.7.jar" file and paste the same in to below location will resolve the issue.
C:\Users\UsernameXXX.m2\repository\tws\axis-client\8.7(Paste axis-client-8.7.jar).
finally, right click on project->Maven->Update Project...Thats it.
happy coding.
I have faced same problem with maven dependencies, eg: unfortunetly your maven dependencies deleted from your buildpath,then you people get lot of exceptions,if you follow below process you can easily resolve this issue.

Another own Maven project as dependency - how to solve it?

I have three Java console applications - A, B and C, all are managed with Maven. Application A contains common tools classes and these tools are used by another two applications - B and C. I need to know how to solve this dependency with Maven.
I have an idea - please correct me if I am wrong, to package and install application A into local Maven repository via mvn install command and this library set as new dependency for app B and C in their pom.xml files.
Is this a good idea or is there some better way how to solve this issue?
This question seems to be related to my issue, but I'm not able to judge if is it a good solution in my situation - How do I add a project as a dependency of another project?
Yes, it's perfectly fine. This solution also scales - you may later install you artifacts to remote repositories or even Maven Central.
Some other option is to place these three projects as modules under a common parent POM with packaging set to pom. The advantage is that you would be able to install all three artifacts with a single command and i.e. update dependencies on-the-fly when using Maven Release plugin.
Yes, this seems like the right way to solve this problem. Alternatively you can deploy to a real repository. That would be even better if you want other people to build project B and C without installing A first.
I would put the code that B and C use in its own separate jar. That way B and C don't use all of project A, but just a library with the code that they need.
I would not use the advice of the linked article. It uses a system path which is not ideal because it needs an absolute path so it will only work if someone installs the projects in the same place on their file system as you.
Running mvn install will solve your problem, but then you are solving it manually. It creates many complications when your projects change. What you need is a pom.xml that makes references to your sub projects:
<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>X</groupId>
<artifactId>X</artifactId>
<version>0.1</version>
<name>X</name>
<packaging>pom</packaging>
<modules>
<module>project_A</module>
<module>project_B</module>
<module>project_C</module>
</modules>
<build>
<defaultGoal>package</defaultGoal>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptors>
<descriptor>src/assemble/bin.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Put this in a directory that contains those 3 directories in which each of your projects are. Then you can call mvn clean package on this directory and Maven will magically solve the problem for you, building each project in the right order and making one project available to the others if there are dependencies.
BONUS: On the example above I am also adding a reference to a Maven Assemble, which you can use to pack all your projects into a single distribution.

Is there a way to configure the version of the Maven POM from command line?

Is there a way to change the version number without editing the POM?
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
We have a CI system where we want to release nightly builds, but without using the -SNAPSHOT solution of Maven, so if 1.0.0 is the current version, we just want to have CI-NIGHTLY-BIULD-20120426.
I suggested this would be possible with something like mvn deploy -Dversion=CI-NIGHTLY-BIULD-20120426, but obviously not. The bad solution would be to let the CI server edit the pom.xml every time, but I think this is very unhandy.
Thank you!
I suggest to use classifier.
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<properties>
<!-- default classifier is empty -->
<my.project.classifier></my.project.classifier>
</properties>
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<classifier>${my.project.classifier}</classifier>
</configuration>
<executions>...</executions>
</plugin>
</plugins>
</build>
and
mvn package -Dmy.project.classifier=NIGHTLY-2012-04-26_02-30
Maven documentation says about classifier:
classifier: You may occasionally find a fifth element on the
coordinate, and that is the classifier. We will visit the classifier
later, but for now it suffices to know that those kinds of projects
are displayed as groupId:artifactId:packaging:classifier:version.
and
The classifier allows to distinguish artifacts that were built from
the same POM but differ in their content. It is some optional and
arbitrary string that - if present - is appended to the artifact name
just after the version number. As a motivation for this element,
consider for example a project that offers an artifact targeting JRE
1.5 but at the same time also an artifact that still supports JRE 1.4. The first artifact could be equipped with the classifier jdk15 and the
second one with jdk14 such that clients can choose which one to use.
Another common use case for classifiers is the need to attach
secondary artifacts to the project's main artifact. If you browse the
Maven central repository, you will notice that the classifiers sources
and javadoc are used to deploy the project source code and API docs
along with the packaged class files.
I think you could also use versions maven plugin. I find it quite useful for things like this.
You could do it in 2 steps:
set necessary version: mvn versions:set -DnewVersion=CI-NIGHTLY-BIULD-20120426
deploy: mvn deploy
in case you need to revert back the changes, use mvn versions:revert (as Mark suggests)
I highly recommend reading Maven Releases on Steroids (part 2, part 3) by Axel Fontaine. It is great, and I'm quite happy using it.
It not only details how you con do what you ask, but also contains good advice how you can tie your build versions with your CI server.
In a nutshell, here are the main points:
Maven Release is slow, needs to be done faster
You parametarize your project version like
<version>${VERSION_NUMBER}</version>
...
<properties>
...
<VERSION_NUMBER>1.0-SNAPSHOT</VERSION_NUMBER>
...
</properties>
Local builds get that version: 1.0-SNAPSHOT
Release builds are done only from your CI server
In your Jenkins/Hudson project configuration you use
clean deploy scm:tag -DVERSION_NUMBER=${BUILD_NUMBER}
That way you get a new release with each Jenkins build, not only nightly.
You can change the configuration to use
clean deploy scm:tag -DVERSION_NUMBER=1.0.0-CI-NIGHTLY-BIULD-${BUILD_ID}
and you would get versions like 1.0.0-CI-NIGHTLY-BIULD-2012-04-26_12-20-24
You could parameterize the version number as
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>${my.project.version}</version>
<properties>
<my.project.version>1.0</my.project.version>
</properties>
and drive the version number from command line using
mvn package -Dmy.project.version=NIGHTLY
Although this is possible, Maven 3 discourages it.

How do I upgrade maven.xml to pom.xml?

I'm working with the 1.14.4 branch of Heritrix and I'm unfortunately for the time being stuck in that branch.. The problem I'm encountering is, its maven.xml is dependent upon Maven 1.1 which is so old I had trouble even finding the dependencies to get it to build.
Moreso, because it's a maven.xml and not a pom.xml, no reasonably old or recent IDE can load the project up - I have to build it by hand running the 'maven' script.
I'll freely admit I'm fairly ignorant when it comes to Java and maven, but surely someone out there has to have some pointers on how I could upgrade to a more recent version of Maven.
Help me Obi-Wan! You're my only hope!
An embarrasing 5 minutes later update..
After wasting 3 hours on this I stumbled on the answer here
Install maven2
cd project_dir
mvn one:convert (automatically converts 1.x to 2.x)
mvn3 is supposedly backwards compatible.. So I should be good to go!
A couple hours later.. reality sets in..
Upgrading to maven-2 or maven-3 has introduced a new new modules which are all out of whack from what got promoted out of my maven.xml into the pom.xml. Additionally, there's no pom.xml for 'the project' which seems to be a bit of a snag too.
So, if I want to play this way, I have to play for keeps - upgrade my modules, format everything as if it were a new project. The upgrade technique got me a little of the way, but this is going to take a while I think.. Accepting Tim's prompt and detailed answer, thanks again. I realize in a way 'Hai guys make maven work for me?' is somewhat like asking someone to fix your makefile.. If it's busted, it's busted. :D
Well, there is an official guide to this sort of thing, but here's a quick start.
Start with a minimal POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
The easiest (although not strictly necessary) step is to ensure the project has the Maven 2 default directory structure.
Essentially just:
src/main/java - your java files, e.g. /com/mycompany/...
src/main/resources - other dependencies (e.g. xml files)
You should then be able to load up that empty project into an IDE as a valid Maven 2 project.
However, it will be full of errors because you have not yet specified the dependencies. Now you have two choices:
1) Add dependencies to the POM by hand. E.g.:
<project>
...
<dependencies>
<dependency>
<groupId>commons-math</groupId>
<artifactId>commons-math</artifactId>
<version>1.2</version>
<type>jar</type>
</dependency>
</dependencies>
...
</project>
2) Or use the IDE to pull in the required dependencies. Depending on your IDE, this may be significantly easier as it may offer the ability to automatically search Maven central for the right library and you can pull in the latest version easily. Netbeans for example, will provide a tooltip on the left of a code line where there is a missing class definition that allows you to search Maven for the dependency.

Java Maven enforcer rule error

Hi all I'm new to apache maven. I imported a project into netbeans everything seems well but i get this error when trying to build it:
[WARNING] Rule 2: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
Property "loadVersion" is required for this build.
I think this means that the version of one of the dependencies in the pom.xml file are wrong but not sure.
Any help is appreciated.
More detail from the question poster:
I'm working on a small part of a project and the part I'm working on has a pom.xml file. This file doesn't have any enforcer rules. However the top level (or highest level pom.xml file) does have an enforcer rule with the required version:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version>
</plugin>
Shouldn't this be enough?
More details from the OP:
It seems I could have just commented this line out in the top level pom file:
<requireProperty>
<property>loadVersion</property>
</requireProperty>
But then I would get other errors. I then read the project sites thoroughly and found out that the project's code can and only should be built with their provided build scripts. When building with their scripts the build is successful. This is good and bad it because now I have to edit code in the IDE and then build it in the terminal, but at least it's a solution.
Your project is using the Maven Enforcer Plugin which is somewhere configured (in a parent POM, in an active profile) to "enforce the existence and values of properties" using the requireProperty rule, in your case a loadVersion property.
Declaring such a custom property with Maven can be done in a pom.xml directly under the project element or in a profile or in a profile in the settings.xml by adding the following:
<properties>
<loadVersion>someValue</loadVersion>
</properties>
And this property can then be referenced by ${loadVersion}. I have of course no idea of the value that should be set.
See also
POM Reference
The complete reference for the POM structure
Settings Reference
I'm going to guess that your pom.xml uses the enforcer plugin and that you have not defined the loadVersion property as per the rule constraints.

Categories