Eclipse error with osgi + maven + maven-pax-plugin - eclipse

I am trying to create an OSGi bundle and integrate it into eclipse. I am using the maven-pax-plugin to create the bundles. These are the steps I follow
I create an osgi project using pax
mvn org.ops4j:maven-pax-plugin:create-project -DgroupId=org.sonatype.mcookbook -DartifactId=osgi-project -Dversion=1.0-SNAPSHOT
and then create a bundle
mvn pax:create-bundle -Dpackage=org.sonatype.mcookbook -Dname=osgi-bundle -Dversion=1.0-SNAPSHOT
and then try to import the maven project into eclipse (file/import/existing maven project) the bundle project created in the second step always gives me this error
maven-pax-plugin:1.5:compile (1 error)
Execution default-compile, in org.sonatype.mcookbook/pom.xml
maven-pax-plugin:1.5:testCompile (1 error)
Execution default-testCompile, in org.sonatype.mcookbook/pom.xml
When I select one of the errors the description says
No marketplace entries found to handle Execution default-compile, in org.sonatype.mcookbook/pom.xml in Eclipse. Please see Help for more information.
If i ignore the error and import the project anyway this is what eclipse complains about
Plugin execution not covered by lifecycle configuration: org.ops4j:maven-pax-plugin:1.5:compile (execution: default-compile, phase: compile)
Has anyone seen this? any ideas how to fix it?
I am following this tutorial but adding integration with eclipse. Note however that if I build it with maven and don't use eclipse at all it all works fine, the problem is in eclipse/m2e
I am using Eclipse Indigo SR2 and m2e 1.0.200

I get rid of this problem by following the comment in the generated POM and move the <extensions>true</extensions> down to the maven-bundle-plugin below giving:
...
<plugins>
<plugin>
<groupId>org.ops4j</groupId>
<artifactId>maven-pax-plugin</artifactId>
<version>1.4</version>
<!--
| enable improved OSGi compilation support for the bundle life-cycle.
| to switch back to the standard bundle life-cycle, move this setting
| down to the maven-bundle-plugin section
-->
<!-- WAS HERE -->
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.3</version>
<!--
| the following instructions build a simple set of public/private
| classes into an OSGi bundle
-->
<extensions>true</extensions> <!-- MOVED HERE :-) -->
<configuration>
...
Then update the project (Right click on project name in Project Explorer: Maven -> Update Project...), wait for the build to complete and the error is gone.
Hope that helps!

The new m2eclipse versions require that every plugin that affects the build is supported using a m2eclipse plugin. So the maven-pax-plugin is not yet supported. As this basically happens with most maven plugins out there I still use the old m2eclipse version.
Unfortunately the old version 0.12 download seems to have been removed recently. So probably you will have to wait till maven-pax-plugin is supported.

Related

MILO OPC-UA Download with Maven

I tried to use the milo opc-ua Implementation. At first I download the source with Eclipse/Maven to my local working directory.
File -> Import -> "Checkout Maven Projects"
The Download works fine for me. After this, I tried to update the project files.
Right-Click -> Update Maven Project
The "build-tools" work well for me, everything is done without any errors. But when I try this with the other "folders" (client-examples, ...) I get the following error:
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (execution: validate, phase: validate).
The following code shows the pom-file of the client-examples:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<parent>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-examples</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<artifactId>client-examples</artifactId>
<dependencies>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>sdk-client</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>server-examples</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
</dependencies>
The pom.entries, shown in https://github.com/eclipse/milo, are in the file. I also checked this for the other sources. But whats going wrong?
I'm using eclipse-neon and maven2eclipse.
Thanks for helping,
Andreas
The errors says that the M2Eclipse plugin has no idea how to map the execution of checkstyle into some build step for the IDE. M2Eclipse tries to set up your local IDE project to replicate the behavior of the Maven build.
By default M2Eclipse is missing the support for the checkstyle Maven plugin. Therefore you get this error. There are two ways to handle this:
You can simply make Eclipse ignore those errors
You can install the checkstyle plugin for Eclipse and have checkstyle run the same way the maven build does it, getting all validation information right into your IDE.
In order to install checkstyle do the following:
Locate the location where the error is reported in Eclipse, issue the "Quick fix" command (normally Ctrl-1)
Select "Discover new m2e connectors":
Review the dialog and press "Finish":
Wait and let Eclipse restart
That should be it.

Eclipse plugin with Maven dependencies for third party libraries

I am converting Subclipse to build with Eclipse Tycho and Maven.
Subclipse depends on a few third party JAR files that are not Eclipse plugins so do not exist in any p2 repository. Currently, I just include these in a lib folder within the plugin.
Since these JAR files do exist in Maven, I was hoping that by converting the plugins to build with Maven I could use Maven dependencies. IOW, the plugin would have a pom.xml where I used Maven dependencies to grab and include the third party jar's that have to be included in the plugin. Basically, it would just automate having to refresh what I include in the lib folder of the plugin.
Is this possible? I tried doing what I said above by when I build, I saw no sign that Maven/Tycho was trying to fetch the dependencies. I imagine it is because when the packaging is eclipse-plugin it looks solely at the Eclipse configuration files for the dependency information.
Thanks
To add plain (without OSGi metadata) jar files into your folder at biuild time, you can specify an <execution> of the maven-dependency-plugin to fetch them. However it will require to update your MANIFEST.MF Bundle-Classpath directive whenever a version changes.
It's usually better to hunt for OSGi-able jars or to make an extra effort to package existing libs as OSGi bundles/p2 artifacts like Eclipse Orbit or JBoss Tools Locus do.
Did you try doing the following after adding the dependencies to the pom.xml file?
Project->Clean
Right click on project: Maven->Update dependencies
Right click on project: Maven->Update project configuration
Just adding the plugin to pom dependencies and including the entry <pomDependencies>consider</pomDependencies> in the configuration of target-platform-configuration makes it work.
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<!-- The configuration to make tycho consider the maven dependencies -->
<pomDependencies>consider</pomDependencies>
<!-- other configurations -->
</configuartion>
</plugin>
<!-- other plugins-->
</plugins>
<dependencies>
<!-- An example third-party bundle (plugin) present in maven repository-->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.shell</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
Reference link here.

m2e error in MavenArchiver.getManifest()

I am seeing an error in my STS and am not sure how to debug it. Searching around I only see vague references to the error and no solutions.
The error is:
org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.MavenProject, org.apache.maven.archiver.MavenArchiveConfiguration) pom.xml /<maven projectName> line 1 Maven Configuration Problem
Question: Can anyone give any suggestions on how to get more information on the issue in order to debug it further or any possible solutions?
Maybe some more context on what the functionality of method is. The javadoc associated with the MavenArchiver.getManifest() method is not very detailed and there is no stack trace that I see. I've tried several refreshes and updates of the project and associated projects including clearing my local m2 repo.
STS info:
Version: 3.7.3.RELEASE
Build Id: 201602250940
Platform: Eclipse Mars.2 (4.5.2)
m2e info:
Version: 1.6.2.20150902-0002
I encountered the same issue after updating the maven-jar-plugin to its latest version (at the time of writing), 3.0.2.
Eclipse 4.5.2 started flagging the pom.xml file with the org.apache.maven.archiver.MavenArchiver.getManifest error and a Maven > Update Project.. would not fix it.
Easy solution: downgrade to 2.6 version
Indeed a possible solution is to get back to version 2.6, a further update of the project would then remove any error. However, that's not the ideal scenario and a better solution is possible: update the m2e extensions (Eclipse Maven integration).
Better solution: update Eclipse m2e extensions
From Help > Install New Software.., add a new repository (via the Add.. option), pointing to the following URL:
https://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-mavenarchiver/0.17.2/N/LATEST/
Then follow the update wizard as usual. Eclipse would then require a restart. Afterwards, a further Update Project.. on the concerned Maven project would remove any error and your Maven build could then enjoy the benefit of the latest maven-jar-plugin version.
Additonal notes
The reason for this issue is that from version 3.0.0 on, the concerned component, the maven-archiver and the related plexus-archiver has been upgraded to newer versions, breaking internal usages (via reflections) of the m2e integration in Eclipse. The only solution is then to properly update Eclipse, as described above.
Also note: while Eclipse would initially report errors, the Maven build (e.g. from command line) would keep on working perfectly, this issue is only related to the Eclipse-Maven integration, that is, to the IDE.
I found my answer! I looked into the pom for any plugins that have a dependency on the maven-archiver and found the maven-jar-plugin does. It was using the latest 3.0.0 version. When I downgraded to 2.6 it seems to fix the issue :-)
I had the same problem with a spring boot project. the solution was to downgrade the jar maven-jar-plugin from 3.2 to 2.6 . i had just to add this to the project pom:
<properties>
<maven-jar-plugin.version>2.6</maven-jar-plugin.version>
</properties>
I had exactly the same problem. My environment was:
Spring STS 3.7.3.RELEASE
Build Id: 201602250940
Platform: Eclipse Mars.2 (4.5.2)
The symptoms of the problems were:
There was a red error flag on my PM file. and the description of the error was as described in the original question asked here.
There were known compilation problems in the several Java files in the project, but eclipse still was not showing them flagged as error in the editor pane as well as the project explorer tree on the left side.
The solution (described above) about updating the m2e extensions worked for me.
Better solution (my recommondation):
update Eclipse m2e extensions
From Help > Install New Software.., add a new repository (via the Add.. option), pointing to the following URL: https://otto.takari.io/content/sites/m2e.extras/m2eclipse-mavenarchiver/0.17.2/N/LATEST/
Select the m2e extensions, accept the license.
After update, you will be asked for restarting STS. The problem goes away after STS comes back up.
I had the same problem with a spring boot project. The solution was to downgrade the spring-boot-starter-parent dependency version from 2.0.0.RELEASE to 1.5.10.RELEASE(you can move to any stable version)
from:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
to
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
I had also faced the same issue and it got resolved by changing the version from 3.2.0 to 2.6 as shown in below pom.xml snippet
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>Spring4MVC</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Upgrade your m2e extensions instead downgrade.
From Help > Install New Software.., add a new repository (via the Add.. option)
Specify name for your plugin and add path http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-mavenarchiver/0.17.2/N/LATEST/
once you are done with installation, please restart eclipse and update your project.
I also faced the similar issues, changing the version from 2.0.0.RELEASE to 1.5.10.RELEASE worked for me, please try it before downgrading the maven version
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
I solved this error in pom.xml by adding the below code
spring-rest-demo
org.apache.maven.plugins
maven-war-plugin
2.6
I had also faced the same issue and it got resolved by commenting the version element in POM.xml as show.
org.apache.maven.archiver.[MavenArchiver](https://maven.apache.org/shared/maven-archiver/apidocs/org/apache/maven/archiver/MavenArchiver.html).getManifest(org.apache.maven.project.MavenProject, org.apache.maven.archiver.MavenArchiveConfiguration)
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- <version>3.5.1</version> -->
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<!-- <version>3.1.0</version> -->
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
Use the steps given in this link. It worked for me.
Step - 1 Right click on your project in Eclipse
Step - 2 Click Properties
Step - 3 Select Maven in the left hand side list.
Step - 4 You will notice "pom.xml" in the Active Maven Profiles text box on the right hand side. Clear it and click Apply.
Step - 5 Run As -> Maven clean -> Maven Install
Hope it helps!

eclipse nullpointer exception for modulare maven project update

I'm using Eclipse 4.4.1 with m2e plugin and the latest gae dependencies. When I import the gae module sample project eclipse tells me that the project configuration is not up to date. If I run the suggested maven -> update project, I get a NPE.
There are a lot of bug reports according NPE on project updates out there. So far I've tried it with mvn eclipse:eclipse or maven project imports, in fresh or existing workspaces but I was never able to get the projects running in eclipse.
Are there any solutions to this?
EDIT:
That is the stacktrace:
java.lang.NullPointerException at
com.google.appengine.eclipse.wtp.maven.GaeRuntimeManager.getGaeRuntime(GaeRuntimeManager.java:85)
at
com.google.appengine.eclipse.wtp.maven.GaeRuntimeManager.ensureGaeRuntimeWithSdk(GaeRuntimeManager.java:55)
at
com.google.appengine.eclipse.wtp.maven.GaeFacetManager.addGaeFacet(GaeFacetManager.java:59)
at
com.google.appengine.eclipse.wtp.maven.GaeProjectConfigurator.configure(GaeProjectConfigurator.java:46)
at
org.eclipse.m2e.core.project.configurator.AbstractLifecycleMapping.configure(AbstractLifecycleMapping.java:120)
at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager$3.call(ProjectConfigurationManager.java:477)
at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager$3.call(ProjectConfigurationManager.java:1)
at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:166)
at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:142)
at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.updateProjectConfiguration(ProjectConfigurationManager.java:470)
at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.configureNewMavenProjects(ProjectConfigurationManager.java:250)
at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager$1.call(ProjectConfigurationManager.java:163)
at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager$1.call(ProjectConfigurationManager.java:1)
at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:166)
at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:142)
at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:96)
at
org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1348)
at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.importProjects(ProjectConfigurationManager.java:133)
at
org.eclipse.m2e.core.ui.internal.wizards.ImportMavenProjectsJob$1.doCreateMavenProjects(ImportMavenProjectsJob.java:73)
at
org.eclipse.m2e.core.ui.internal.wizards.AbstractCreateMavenProjectsOperation.run(AbstractCreateMavenProjectsOperation.java:62)
at
org.eclipse.m2e.core.ui.internal.wizards.ImportMavenProjectsJob.runInWorkspace(ImportMavenProjectsJob.java:82)
at
org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:38)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
You can comment out the appengine-maven-plugin to solve the problem, but by doing that you lose the command-line capabilities of the plugin. You can have the best of both worlds (Eclipse and Maven command-line) by using Maven profiles:
<profiles>
<profile>
<id>gae</id>
<build>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.target.version}</version>
</plugin>
</build>
</profile>
</profiles>
To activate it, for instance, to deploy the project from the command-line, you can do:
mvn appengine:update -P gae
When defining the appengine-maven-plugin only inside a profile, Eclipse won't use it, and the bug goes away. When using the command-line, just remember to activate it using the -P flag.
I had the same problem suddenly appear in one of my projects. Disabling the JPA validator seems to have resolved the issue for now.
Select Windows > Preferences > Validation
Disable the JPA Validator for both Manual validation and Build validation
It might be related to the "The persistence.xml file does not have recognized content" error described in here: www-01.ibm.com/support/docview.wss?uid=swg21616684 .
I had the same issue after updating from Eclipse Kepler (4.3) to Luna (4.4). Commenting out the app-engine-maven plugin from my pom.xml fixed it for me.
<!--
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.target.version}</version>
</plugin>
-->
I'm able to run and deploy my app without any issues so far.
seem to be a duplicate of An internal error occurred during: "Updating Maven Project". java.lang.NullPointerException
got to preferences / Server / Runtime Environemnt
--> select "Google App Engine" and associate a valid SDk to this runtime.

Eclipse WTP not publishing Maven dependencies

I'm trying to set up a basic hello world project using Eclipse Indigo and a Tomcat server. I created a dynamic project with a simple servlet. Tested the servlet and that worked fine. Then I enabled Maven support and added logback to my pom. I put a logging statement in the servlet's doGet method. When running the servlet, it complains it cannot find any bindings because the logback jars are not being copied into the Eclipse tomcat instance. I expected to find the jars published somewhere in here:
${workspace}\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\
How do I get Eclipse to work with WTP/Maven properly? I also tried installing the m2e-wtp connector with no difference.
Check Deployment Assembly (context menu on project), there must be mapping Maven Dependencies -> WEB-INF/lib.
Coming from an ASP.NET background, I find it shocking how much work it takes to get a webapp running with Eclipse WTP and Maven especially if you are learning on your own. Hopefully this quick start guide will help someone else get up to speed quickly.
There are two ways to get a hello world project working in Eclipse WTP with Maven. You can create a Dynamic web project and then add the Maven nature or you can do the opposite.
Pre-requisites for Eclipse with update sites
"Web, XML, Java EE and OSGi Enterprise Development"
http://download.eclipse.org/releases/indigo
"Maven Integration For Eclipse"
http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/
"Maven Integration for WTP"
http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/
Startup configuration
Install copy of Tomcat 7 from http://tomcat.apache.org/download-70.cgi
Window -> Preferences -> Server -> Runtime Environment
Add Apache Tomcat 7.0 and select local installation directory
Option 1: Create Dynamic Web Project then add Maven Nature
Create new Maven project, select archetype
org.apache.maven.archetypes:maven-archetype-webapp
Change to Java EE perspective.
Create a new source folder, src\main\java. Notice how Eclipse is not smart enough to do this for you and also the ordering of the folders is incorrect.
src\main\java folder is listed after src\main\resources. This can be manually fixed later in the project properties.
Create a new servlet. Notice how Eclipse defaults this file in the wrong folder src\main\resources because the order is wrong. Instead, manually select src\main\java.
Change the URL mapping on the second page of the wizard to /* to make testing easier.
Now our servlet is ready but the dependencies on the servlet api are unbound. A) we can add the servlet api as a dependency to our project or B) we can bind to the Eclipse server config for Apache 7.0.
For option A, add this dependency to the pom:
.
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-api</artifactId>
<version>7.0.${set this}</version>
<scope>provided</scope>
</dependency>
For option B:
Project properties -> Java Build Path -> Libraries -> Add Library -> Server Runtime -> Apache Tomcat 7.0
Right click and run on server:
A blank page should come up in the internal browser like http://localhost:8080/${artifact}
Test of dependency publishing:
Add joda-time to the pom.
Add this line in the servlet created earlier for the doGet method and import the necessary dependencies:
.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().println("The time is now: " + new DateTime().toString());
}
Reload the test page and the output should now be:
The time is now: 2012-03-03T14:14:29.890-05:00
Now if you want to play with Servlet 3.0 and annotations this is not enabled by default, for what reason I don't know.
First force Maven to use Java 1.6 by adding this to your pom, otherwise each time you update your pom the configuration will revert to Java 1.5.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Open Project Properties -> Project Facets. Change the Version under "Dynamic Web Module" to 3.0, change java version 1.6
Create a new Servlet with class name AnnotatedServlet in src\main\java and notice how the #WebServlet annotation is auto created.
Option 2: Create Dynamic Web Project then add Maven Nature
Select Tomcat Runtime and Dynamic Module Version 3.0
Create source folder src\main\java
Set default output target\classes
Set context directory src\main\webapp
Check generate web.xml
Create servlet with mapping /* for quick testing
Add an output statement to the doGet method
response.getWriter().println("Another test");
Double click the "Deployment descriptor" and add this attribute to the root web-app element metadata-complete="false"
Right click project and select Run As -> Run On Server
Right click project -> Configure -> Convert To Maven Project
Select packaging as war
Edit pom and set compiler to use java 1.6 and add joda-time dependency:
.
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Right click on the web project in Project Explorer then choose Maven -> Update Project
I faced a similar problem and although I had configured Deployment Assembly correctly it still didn't work. Then I found that under Window -> Preferences -> My Eclipse -> Java Enterprise Project -> Web Project, under the Deployment tab, the management of Dependent projects was turned off. I changed it to deploy jars of dependent projects to the lib folder and then everything worked like a charm. I could even turn off the Deployment Assembly option.