How to include predefined set of netbeans platform modules in maven project? - netbeans

I am working on maven netbeans platform project consisting of several modules. I need to depend on some modules (say java.source module), but when I try to run the application, it reports, that required modules are not installed. And event despite I have dependency on java.source declared in my pom.xml
I think, that I have to tell maven somehow, to install (and turn on) these modules in the final assembled application before my module is loaded.
How could I do something like this?
UPDATE:
When I try to create complete netbeans application project from maven artifact and add Java Source API as a dependency into pom.xml... when I run the application, window with following message appears:
Warning - could not install some modules: Editor Library 2 - None of the modules providing the capability org.netbeans.modules.editor.actions could be installed. Editor Indentation for Projects - The module named org.netbeans.modules.editor.settings.storage/1 was needed and not found. Editor Indentation for Projects - The module named org.netbeans.modules.options.editor/1 was needed and not found. Project UI API - No module providing the capability org.netbeans.modules.project.uiapi.ActionsFactory could be found. Project UI API - No module providing the capability org.netbeans.modules.project.uiapi.OpenProjectsTrampoline could be found. Project UI API - No module providing the capability org.netbeans.modules.project.uiapi.ProjectChooserFactory could be found. Editor Error Stripe Impl - The module named org.netbeans.modules.editor.errorstripe.api/1 was needed and not found. Java Source - The module named org.netbeans.libs.javacimpl/1 was needed and not found. Java Source - The module named org.netbeans.modules.editor.indent.project/0-1 was needed and not found. Java Source - The module named org.netbeans.modules.java.preprocessorbridge was needed and not found. Java Source - The module named org.netbeans.modules.options.editor/1 was needed and not found. Java Source - The module named org.netbeans.modules.parsing.api/1 was needed and not found. Editor Settings - No module providing the capability org.netbeans.api.editor.settings.implementation could be found. Diff - The module named org.netbeans.modules.options.editor/1 was needed and not found. 11 further modules could not be installed due to the above problems.

The error-message "Module dependency has friend dependency [...] but is not listed as friend" means that you need to specify an implementation version of org.netbeans.modules.options.editor.
You can achieve this by editing src/main/nbm/module.xml to contain the following entry (I didn't use the actually needed values here. Make sure to find out which values to enter for id and explicitValue to satisfy the dependencies (You can find explanations / instructions in the article linked below):
<dependencies>
<dependency>
<id>org.netbeans.modules:org-netbeans-modules-editor</id>
<type>impl</type>
<explicitValue>org.netbeans.modules.editor/1 = 201107282000</explicitValue>
</dependency>
</dependencies>
I'm pretty sure that the following article will explain some issues and help you find out the needed values for id and explicitValue (language is english, author is me):
http://blog.macrominds.de/2011/08/open-favorites-per-default-in-netbeans-rich-client-platform-maven-standalone-application/
I'm currently having related problems with my application, so I might come back with a more concrete solution in a while.

the easiest way is to grab a class that its complaining about, say "org.netbeans.modules.editor.actions" and go to the Add Dependencies and plug it into the Query field.
From there you should be able to tell which module you will need to include

Related

Spring Boot + OSGI : NoClassDefFoundError on jackson databind

I fail to configure a project based on Spring Boot, extended with OSGI, and using Jackson in a bundle
by using import/export package system (I would like to avoid to embed the lib).
I started from this project.
Maven modules:
a Spring Boot module, the main app, initialized with Felix, like the referenced project above
a bundle module, where I want to use ObjectMapper on activation like this
#Activate
public void activate() {
ObjectMapper objectMapper = new ObjectMapper();
}
But on activation I got the following error:
NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
Yet, I had exported this package from the main app bundle (Spring Boot) and imported it in the bundle module.
This bundle module use maven-bundle-plugin (while the main app use nothing specific):
<instructions>
<_dsannotations>*</_dsannotations>
<_metatypeannotations>*</_metatypeannotations>
<Bundle-Vendor>Foo</Bundle-Vendor>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Service>
com.foo.bar.plugin.RestTaskPlugin
</Export-Service>
<Export-Package>
com.foo.bar.plugin.rest,
com.foo.bar.plugin.rest.web,
com.foo.bar.plugin.rest.config
</Export-Package>
<Import-Package>*;resolution:=optional</Import-Package>
<Embed-Dependency>*;scope=compile|runtime; type=!pom; inline=true</Embed-Dependency>
<Embed-Transitive>false</Embed-Transitive>
</instructions>
I only embed logback-classic and logback-core in this bundle (this could be another story...). In other words, I only have these 2 dependencies declared in the module. I also tried to add databind in provided scope but it changes nothing.
I don't get it since I have exported all "com.fasterxml.jackson" packages and sub-packages. To do so, the Spring boot initialize the Felix framework with a custom configuration, with the config key org.osgi.framework.system.packages.extra containing all packages to export automatically according to
the documention.
When I log them we can see around 100 exported packages including these ones :
....
com.fasterxml.jackson.databind.deser.impl,
com.fasterxml.jackson.databind,
com.fasterxml.jackson.core.sym,
....
The module bundle using databind MANIFEST.MF :
Export-Package: com.foooooooo.baaaar.plugin.rest;uses:="com.foooooooo.d
atagen.api.plugins,com.foooooooo.baaaaar.api.plugins.properties,com.baa
aaaaar.datagen.api.plugins.web,com.foooooooo.baaaaar.plugin.rest.config
,com.foooooooo.baaaaar.plugin.rest.web,com.foooooooo.baaaaar.task,com.d
atanumia.baaaaar.task.config,com.foooooooo.baaaaar.task.environment,com
.foooooooo.baaaaar.task.template,org.springframework.http,org.springfra
mework.web.client";version="0.1.0.SNAPSHOT",com.foooooooo.baaaaar.plugi
n.rest.web;uses:="com.foooooooo.baaaaar.api.plugins,com.foooooooo.baaaa
ar.api.plugins.web";version="0.1.0.SNAPSHOT",com.foooooooo.baaaaar.plug
in.rest.config;uses:="com.foooooooo.baaaaar.task.config,com.fasterxml.j
ackson.annotation,com.fasterxml.jackson.databind.annotation,org.springf
ramework.http";version="0.1.0.SNAPSHOT"
Export-Service: com.foooooooo.baaaaar.plugin.RestTaskPlugin
Import-Package: com.foooooooo.baaaar.api.plugins;resolution:=optional,c
om.foooooooo.baaaaar.api.plugins.properties;resolution:=optional,com.da
tanumia.baaaaar.api.plugins.web;resolution:=optional,com.foooooooo.baaa
aar.task;resolution:=optional,com.foooooooo.baaaaar.task.config;resolut
ion:=optional,com.foooooooo.baaaaar.task.environment;resolution:=option
al,com.foooooooo.baaaaar.task.template;resolution:=optional,com.foooooo
al,com.foooooooo.baaaaar.task.template;resolution:=optional,com.foooooo
oo.baaaaar.tools.file;resolution:=optional,com.fasterxml.jackson.annota
tion;resolution:=optional;version="[2.13,3)",com.fasterxml.jackson.data
bind;resolution:=optional;version="[2.13,3)",com.fasterxml.jackson.data
bind.annotation;resolution:=optional;version="[2.13,3)",com.jayway.json
path;resolution:=optional;version="[2.7,3)",java.io;resolution:=optiona
l,java.lang;resolution:=optional,java.lang.annotation;resolution:=optio
nal,java.lang.invoke;resolution:=optional,java.lang.management;resoluti
on:=optional,java.lang.reflect;resolution:=optional,java.net;resolution
:=optional,java.nio.channels;resolution:=optional,java.nio.charset;reso
lution:=optional,java.nio.file;resolution:=optional,java.security;resol
ution:=optional,java.security.cert;resolution:=optional,java.text;resol
ution:=optional,java.util;resolution:=optional,java.util.concurrent;res
olution:=optional,java.util.concurrent.atomic;resolution:=optional,java
.util.concurrent.locks;resolution:=optional,java.util.function;resoluti
on:=optional,java.util.logging;resolution:=optional,java.util.regex;res
olution:=optional,java.util.stream;resolution:=optional,java.util.zip;r
esolution:=optional,javax.mail;resolution:=optional,javax.mail.internet
;resolution:=optional,javax.management;resolution:=optional,javax.namin
g;resolution:=optional,javax.net;resolution:=optional,javax.net.ssl;res
olution:=optional,javax.servlet;resolution:=optional,javax.servlet.http
;resolution:=optional,javax.xml.namespace;resolution:=optional,javax.xm
l.parsers;resolution:=optional,javax.xml.stream;resolution:=optional,ja
vax.xml.stream.events;resolution:=optional,lombok;resolution:=optional,
org.apache.commons.lang3;resolution:=optional;version="[3.12,4)",org.co
dehaus.commons.compiler;resolution:=optional,org.codehaus.janino;resolu
tion:=optional,org.springframework.http;resolution:=optional,org.spring
framework.http.converter.json;resolution:=optional,org.springframework.
util;resolution:=optional,org.springframework.web.client;resolution:=op
tional,org.springframework.web.util;resolution:=optional,org.xml.sax;re
solution:=optional,org.xml.sax.helpers;resolution:=optional,sun.reflect
;resolution:=optional
It is difficult to see but we have the expected import-package:
com.fasterxml.jackson.databind;resolution:=optional;version="[2.13,3)"
I do not have any other loaded bundle excepted the framework bundles:
org.apache.felix.fileinstall-3.7.4.jar
org.apache.felix.scr-2.2.0.jar
org.osgi.service.cm-1.6.1.jar
org.osgi.util.function-1.2.0.jar
org.osgi.util.promise-1.2.0.jar
I spend days to understand what is happening but each new tests bring me new unresolved challenges.
I can have a working project if I change strategy and embed everything, but then in some particular situations I have a linkage problem since I use the same lib in different class loaders.
How to use import/export package system correctly ?
Any idea about the problem here ?
UPDATE: the export-import seems to work with other packages. For example I can use spring-web in provided scope, it is not in the final bundle module, and I can use some methods of spring-web, exported from main app. The problem seems to be the Jackson Databind or something in related to it.
UPDATE
If I use bnd-maven-plugin I do not have the problem, I will post it unless someone give a better answer.

GWT module xml source element to specify single class

I have a GWT application (FooGwtApp) and a library module (FooLib) used as a dependency in FooGwtApp. The package structure of FooLib looks like this:
packageFoo.ImportantClass
packageFoo.UnimportantClass
packageBar.OtherClass
I want ImportantClass (and only ImportantClass) to be compiled to JS by the GWT compiler. Moving ImportantClass to another package is not an option.
I created ImportantClass.gwt.xml within packageFoo with the following content:
<module>
<inherits name="com.google.gwt.user.User"/>
<source path="" includes="**/ImportantClass*"/>
</module>
Next I put an inherited reference to the ImportantClass module definition in FooGwtApp.gwt.xml (this seems to work: the IDE recognizes it, and is able to parse the reference to ImportantClass.gwt.xml).
Now If I put references to ImportantClass into FooGwtApp's client code, the GWT compiler fails, because it does not find ImportantClass on the source path:
No source code is available for type packageFoo.ImportantClass; did you forget to inherit a required module?
I likely messed up sommething in the source path / includes attribute in ImportantClass.gwt.xml - either defining the current package as root package with path="" is not a valid notation or something's wrong with the includes attribute. Or both. Or neither.
Can you give me a clue about where it all went wrong?
It turns out the problem was not in ImportantClass.gwt.xml, but in other Maven related stuff:
ImportantClass.gwt.xml should be placed under src/main/resources/packageFoo, not src/main/java/packageFoo, otherwise it won't be packaged into the binary jar.
GWT compiler compiles from Java source to Javascript source. This means we don't just need ImportantClass.class in FooLib.jar, but also its source. Best solution for this is to use maven-source-plugin in FooLib's pom.xml and also to import the FooLib dependency into FooGwtApp with sources classifier.
On the latter topic, see the following SO answers:
Maven: Distribute source code with with jar-with-dependencies
How to properly include Java sources in Maven?
After fixing the above problems, the source path declaration present in the question works.

How do I reference a UWP+NET46 portable library from a .NET 4.6 console application?

I have a portable class library project that targets .NET 4.6 and Universal Windows Platform. This class library contains just one class with the following line of code in its constructor:
Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
Now I create a new .NET 4.6 console application project in the same solution and add a project reference to the portable class library. Calling the method that houses the above line of code results in the following exception at runtime:
Could not load file or assembly 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
What am I doing wrong here? There are no compile-time errors or warnings.
Things I have tried: add missing(?) NuGet package manually
It seems that System.IO.FileSystem is a library delivered via NuGet, as part of the Microsoft.NETCore mega-package. Okay, perhaps I need to explicitly add this package to any project that uses my portable class library. I attempt to do so.
Could not install package 'Microsoft.NETCore.Platforms 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
No luck with this approach.
Things I have tried: create a project.json file
While there is no clear info on the web, I read a few tidbits about a new project.json based NuGet harness or build system. Just to experiment, I created the following project.json file in my console application project:
{
"dependencies": {
},
"frameworks": {
"net46": { }
},
"runtimes": {
"win-anycpu": { }
}
}
It works! The runtime error goes away! However, I soon found that this was either not the right solution or not a complete solution. I started writing some code to read configuration section values, which involved making use of the IConfigurationSectionHandler interface, and got the following compile-time error:
error CS0246: The type or namespace name 'IConfigurationSectionHandler' could not be found (are you missing a using directive or an assembly reference?)
This interface is part of the System assembly. I see a reference to this assembly, but it has a yellow exclamation mark icon, and a warning appears in the warnings window:
The referenced component 'System' could not be found.
This is where I ran out of ideas. Am I missing something totally obvious?
I have found the solution. My initial attempt was to install the Microsoft.NETCore package into the console application, resulting in the error shown in my original post.
However, if I install only the narrowly-scoped packages, e.g. System.IO.FileSystem, then I achieve success and the application works correctly. Apparently there is something special about the Microsoft.NETCore "master package" that prevents it from correctly installing into dependent projects.

Trouble with Importing Java Libraries into a project with NetBeans

I am having some issues with importing library which is needed to complete an assignment that I have been set.
I'm not sure if I have added the library to the project, but the classes from the library appear to be in the libraries section of the project.
http://imgur.com/Co6IOzq,qCJaXHh,ZJVUnbZ
I added the libraries by right clicking on project1 and going to properties:
http://imgur.com/Co6IOzq,qCJaXHh,ZJVUnbZ#1
However whenever I have "package project1" at the top of Project1.java I receive a message that MaInput - which is one of the classes in this library - is not recognised:
cannot find symbol:
symbol: class MaInput
Whenever I take away "package project1" when trying to compile it reads:
Error: Could not find or load main class project1.Project1
Java Result: 1.
The problem is that you are trying to access a class from default package from a named package and this is not allowed by the Java Specification.
So, in this case, create your assignment in the default package as well.

Problem with p2.inf file when building eclipse product

I have an eclipse product that depends on a feature. Now I would like to be able to update this feature. I would also like to be able to start the application with a predefined update site. I have created a p2.inf file which contains (based on: http://aniefer.blogspot.com/2009/07/composing-and-updating-custom-eclipse.html):
requires.0.name = com.application.feature.group
requires.0.range = [1.0.0.qualifier, 2.0.0.qualifier)
instructions.configure=\
addRepository(type:0,location:https${#58}//ccp.com/);\
addRepository(type:1,location:https${#58}//ccp.com/);
But the updatesite ccp.com does not shown when I go to the install manager in the build product (it works fine if I remove the 'requires' commands).
Are there anything wrong with the above p2.inf file?
I have now tried:
requires.0.namespace=org.eclipse.equinox.p2.iu
requires.0.name = com.application.feature.group
requires.0.range = [1.0.0.qualifier, 2.0.0.qualifier)
instructions.configure=\
addRepository(type:0,location:https${#58}//ccp.com/);\
addRepository(type:1,location:https${#58}//ccp.com/);
but when I build it I get the error:
Cannot complete the install because one or more required items could not be found.
Software being installed:
MyProduct 1.0.0.201102161136 (com.application.product 1.0.0.201102161136) Missing requirement:
MyProduct 1.0.0.201102161136 (com.application.product 1.0.0.201102161136) requires 'com.application.feature.group [1.0.0.qualifier,2.0.0.qualifier)'
but it could not be found
Application failed, log file location: ...
I have also tried to remove the qualifier from the p2.inf file in the version range and on my feature, but get the same error. Any ideas?
Try adding
requires.0.namespace=org.eclipse.equinox.p2.iu
I suspect that not specifying the namespace leaves it as null in the p2.inf parser, eventually leading to an assertion failure on a Assert.isNotNull(namespace), or an NPE. Either of these would probably cause the entire p2.inf file to be ignored.
I found that I needed to use the p2.context.repos option to pass in the repositories containing the items referred to in p2.inf. Using this and pluginPath in tandem was the key.