Add Apache Thrift to OSGi Bndtools Project - java

I am working with Bndtools in Eclipse. I am trying to add Apache Thrift as dependency to a project. My build.bnd has this code for adding the Maven Central as well as our Nexus repository:
-plugin.5.Nexus = \
aQute.bnd.repository.maven.pom.provider.BndPomRepository; \
releaseUrls=https://<NEXUS_URL>:8081/content/groups/public/ ; \
snapshotUrls=https://<NEXUS_URL>:8081/content/groups/public/ ; \
index=${.}/release.maven; \
pom = ${workspace}/cnf/maven-nexus.xml; \
name="Nexus"
-plugin.6.MavenCentral: \
aQute.bnd.repository.maven.pom.provider.BndPomRepository; \
releaseUrls = https://repo1.maven.org/maven2/; \
pom = ${workspace}/cnf/maven-central.xml; \
name = Maven Central
I tried to add the dependency to both xml files like this:
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.10.0</version>
</dependency>
Other dependencies like Gson work just fine. The bnd.bnd file of the project where I want to use Thrift only has this content:
-buildpath: \
org.apache.thrift
I also tried org.apache.libthrift, but I found out that this should be the correct OSGi bundle name. I always get
Cannot find /error/org.apache.thrift;version=0 Not found
Am I missing something here? I am new to OSGi and so I might miss something really obvious. I am also not sure if my configurations of the repositories are correct. Still, other dependencies work just fine. Thanks for any advice!
EDIT:
Maybe as additional information: In Eclipse the build.bnd file is shown empty in the GUI view. Does this mean, that my project is somehow corrupted or is this normal?
EDIT2: For testing (didn't help) I also added the Maven Central using the MavenBndRepository Plugin additionally to the BndPomRepository:
-plugin.7.MavenCentralAlternative = \
aQute.bnd.repository.maven.provider.MavenBndRepository; \
releaseUrl=https://repo.maven.apache.org/maven2/; \
index=${.}/central.maven; \
name="Maven Central Alternative"
EDIT3: The problem has to be Thrift related. All other packages work just fine, only Thrift is not found. My current workaround is to add the Thrift jar to the project manually and reference its dependencies as OSGi bundle just like I tried to add Thrift in the first place. Obviously I get now this warning:
Bndtools: The .classpath contains a library that will not be available
during continuous integration

Related

Get NoClassDefFound Error in Apache Maven 3.8.6 (JDK-19+Gson2.10)

I am new to java and maven. I am learning and trying to make a system to help me build up JSON data by GOOGLE's gson and maven. This is my using command order:
mvn -f my-app\pom xml clean compile
mvn -f my-app\pom xml install
cd my-app\target
java -jar my-app-1.0.jar
After I run it it show me this error.
in GSONExample.java Line 13:
Gson gson = new Gson();
The following is my using software/IDE version.
Source Editor: VS Code
JDK: JDK-19
apache-maven: 3.8.6
Gson: 2.10 (https://github.com/google/gson/releases)
I have already gone through other websites and StackOverflow to find solutions.
GSON is not being imported into the maven project Changed scope role and still crash
error even though it is defined in my classpath /WEB-INF/lib can't find in my situation
Now below a part of my pom.xml
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
</dependency>
I also had try to import it(Gson) to local and try to fix it out.
mvn install:install-file -Dfile=C:\gson-2.10.jar -DgroupId=com.myself.gson -DartifactId=example-gson -Dversion=2.10 -f my-app\pom.xml
After I use the command, I changed pom.xml as follow. It can compile and install. But still show me "NoClassDefFound"
<dependency>
<groupId>com.myself.gson</groupId>
<artifactId>example-gson</artifactId>
<version>2.10</version>
</dependency>
May anyone provide any solution to this? Thanks in advance.
I had tried
changed scope to provided in pom.xml
put Gson in src\main\resources\lib and change pom.xml
Local gson-2.10.jar and change pom.xml
put gson-2.10.jar in C:\Program Files\apache-maven-3.8.6\lib
The problem is this command:
java -jar my-app-1.0.jar
Most likely your current Maven pom.xml creates a JAR file which contains only the classes of your project, but not the classes of dependencies, such as Gson. This is also not specific to Gson but applies to any dependencies you are trying to use. You can either:
use java -cp and specify the path to your JAR as well as the paths to all the JARs of dependencies you are using, for example java -cp gson-2.10.jar;my-app-1.0.jar com.mycompany.app.GSONExample
configure Maven to build a "JAR with dependencies", see this question whose answers describe multiple ways of how this can be achieved

Initializr service call failed, returned Bad Request: Unknown dependency 'rest'

I would like to replicate this Spring Initializr setup using the spring init cli.
However, the command returns the following error message whenever I try to add 'rest' as a dependency i.e. Rest Repositories that expose Spring Data repositories over REST.
Initializr service call failed using 'https://start.spring.io' - service returned Bad Request: 'Unknown dependency 'rest' check project metadata'
Here is the command I'm running:
spring init --build=maven \
--java-version=11 \
--artifact=explorecali \
--package-name=com.example.ec \
--name=explorecali \
--description="Explore California Microservice" \
--dependencies=web,h2,jpa,rest \
--packaging=jar \
sample-app.zip
If rest isn't the correct dependency name, what is? Moreover, how can one list the available dependencies from the command line to get their correct names.
Take a look at the url of the link you posted, it has the dependency names listed out.
https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.7.2&packaging=jar&jvmVersion=11&groupId=com.example&artifactId=explorecali&name=explorecali&description=Explore%20California%20Microservice&packageName=com.example.explorecali&dependencies=web,data-rest,h2,data-jpa
The final portion of the url, dependencies=web,data-rest,h2,data-jpa, shows us that the Rest Repositories are added with data-rest, not rest.
Spring Data JPA is added with data-jpa, not jpa.
Hope this helps.

Maven doesn't recognize parameter when containing "-"

I was trying to test this maven plugin on a simple spring-boot project. But I'm facing an issue with mojo parameters, when I use parameter containing a "-" along with goals it doesn't seem to work:
$ mvn clean install fabric8:build fabric8:resource \
> -Dfabric8.openshift.enableAutomaticTrigger=false \
> -Dfabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll=true
But when I put these parameters as system properties in project's pom.xml. They seem to be picked by maven plugin and work as they are supposed to do. I added this to pom like this:
<properties>
<fabric8.openshift.enableAutomaticTrigger>false</fabric8.openshift.enableAutomaticTrigger>
<fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>true</fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>
</properties>
I'm a big confused here. Can anyone please tell me why it's not working in former case? Is there some kind of naming convention for mojo parameters that we're supposed to follow?
I suggest you to use a workaround (seems to me a faster solution than debug maven) :
<properties>
<f8.autoTrigger>your_default_here</f8.autoTrigger>
<f8.enrichAll>your_other_default_here<f8.enrichAll>
<fabric8.openshift.enableAutomaticTrigger>${f8.autoTrigger}</fabric8.openshift.enableAutomaticTrigger>
<fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>${f8.enrichAll}</fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>
</properties>
And if you want to override your defaults you can invoke maven like :
$ mvn clean install fabric8:build fabric8:resource \
> -Df8.autoTrigger=false \
> -Df8.enrichAll=true
It is even shorter :)

Vaadin - QR code: Widgetset 'com.vaadin.DefaultWidgetSet' does not contain implementation

Eclipse Neon, Vaadin version 7.3.6. Java 1.8.
I want to show QR code on page , created by Vaadin. So I add dependency in pom.xml
<dependency>
<groupId>org.vaadin.addons</groupId>
<artifactId>qrcode</artifactId>
<version>2.0.1</version>
</dependency>
In my code in Vaadin I use this:
QRCode code = new QRCode();
code.setValue("The quick brown fox jumps over the lazy dog");
code.setWidth("400px");
code.setHeight("400px");
addComponent(code);
It's compile and run success. But when I try to load html page with QR code I get the next error:
Widgetset 'com.vaadin.DefaultWidgetSet' does not contain implementation for fi.jasoft.qrcode.QRCode.
Check its component connector's #Connect mapping, widgetsets GWT module description file and re-compile your widgetset.
In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions.
What is wrong? Thanks.
You need to re-compile the widgetset for your application. Actually there is a maven plugin for that. You can find the detailed instructions how to create&comiple custom wigetset here:
https://vaadin.com/directory/help/using-vaadin-add-ons/maven
It's a bit tricky to set everything up, but once it's done, it's only about running
mvn vaadin:update-widgetset install
You'll have to add some plugins to the pom.xml in order to make this work, the best way how to find out how to add the plugin is to generate the official archetype for the Vaadin application and copy&paste the plugin info from there:
mvn archetype:generate \
-DarchetypeGroupId=com.vaadin \
-DarchetypeArtifactId=vaadin-archetype-clean \
-DarchetypeVersion=LATEST \
-DgroupId=your.company \
-DartifactId=project-name \
-Dversion=1.0 \
-Dpackaging=war
Note that if you are using spring-boot then there'll be no web.xml where to define the widgetset, but you can actually follow info from this forum:
https://vaadin.com/forum#!/thread/9587133

how to add my custom jar in maven

I am able to create an object for a class in a jar file, which is another module.
I created a new java project with a main class, added the jar to the lib folder and I am able to create the object for that jar's class(com.canonical.client), while running the main class as a java application.
Now, I have converted this java project to maven. While I try to clean and install, I am unable to build successfully. The error given is " package com.canonical.client does not exist".
After Jespers's suggestion I am able to build the project. I am getting the following exception, while calling method which creates client object. In that jar, it looks for some other jars.
java.lang.ClassNotFoundException: ch.qos.logback.core.Context
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at com.mmf.controllers.PickEquifaxController.handleRequestInternal(com.mmf.controllers.PickEquifaxController:33)
My manifest file's first 2 lines in that jar are as follows, its refering 118 jars actually,
Manifest-Version: 1.0
Class-Path: . canonicalclient_lib/activemq-camel-5.8.0.jar canonicalclient_lib/activemq-core-5.6.0.jar
canonicalclient_lib/activemq-pool-5.6.0.jar canonicalclient_lib/activemq-protobuf-1.1.jar
What I need to do to get a solution in this. pls advice.
You can install your JAR in your local Maven repository with a command like this:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id>
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
where you'll have to fill in your own group id, artifact id, version and packaging - the packaging will most likely be jar - for example:
mvn install:install-file -Dfile=myjarfile.jar -DgroupId=com.canonical
-DartifactId=client -Dversion=1.0 -Dpackaging=jar
After doing this, you can use it like any other Maven dependency, by specifying the dependency using the group id, artifact id and version in your pom.xml:
<dependency>
<groupId>com.canonical</groupId>
<artifactId>client</artifactId>
<version>1.0</version>
</dependency>
You can add your custom jar by this way in POM.xml
<dependency>
<groupId>com.canonicalclient</groupId>
<artifactId>xxx</artifactId>
<version></version>
<systemPath>${basedir}/lib/xxx.jar</systemPath>
</dependency>

Categories

Resources