I am trying to integrate JavaFX inside of an SWT application using FXCanvas. For reference, I am following this oracle guide
Within my IDE this chunk of code displays an error
/* Create an FXCanvas */
final FXCanvas fxCanvas = new FXCanvas(shell, SWT.NONE) {
#Override
public Point computeSize(int wHint, int hHint, boolean changed) {
getScene().getWindow().sizeToScene();
int width = (int) getScene().getWidth();
int height = (int) getScene().getHeight();
return new Point(width, height);
}
};
Error:
(yes, I have imported the correct Point class: org.eclipse.swt.graphics.Point):
'computeSize(int, int, boolean)' in 'Anonymous class derived from javafx.embed.swt.FXCanvas' clashes with 'computeSize(int, int, boolean)' in 'javafx.embed.swt.FXCanvas'; attempting to use incompatible return type
However, I don't think this is the root cause... Because when I try to build the project (maven) I get this error:
package javafx.embed.swt does not exist. Which I believe is the true issue.
So after doing some research I have checked a few things, firstly, the jfxswt jar looks like it should be accessible:
and if I open the JAR, you can see FXCanvas is there:
I even tried adding the JAR manually as a library to my module, still doesn't work.
Here is my pom.xml, (i've intentionally anonymized certain info)
I will also mention that I have tried this in a fresh project without any maven dependencies, and just adding swt and such as libraries manually with the same error.
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
</parent>
<artifactId></artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name></name>
<description></description>
<dependencies>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-engine</artifactId>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-core</artifactId>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-ui-swt</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.gtk.linux.x86_64</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>jface</artifactId>
<version>3.3.0-I20070606-0010</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
</project>
Am I missing something, any ideas?
You will need to add the jfxswt.jar file to your classpath for compile and for execution.
This can be done by using the system scope as that jar file is part of your JDK under the jre/lib directory.
<dependency>
<!-- GroupId/ArtifactId/Version doesn't matter unless it clashes. -->
<groupId>jfxswt</groupId>
<artifactId>jfxswt</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${java.home}/lib/jfxswt.jar</systemPath>
</dependency>
This will instruct maven to add the jre/lib/jfxswt.jar to the classpath. This could cause an issue if someone uses different JDK what has that jar in other places but for Java 8 you should be okay.
You have to add the jfxswt.jar to your classpath when you execute your application.
In maven you can use the exec plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>twobuttons.TwoButtons</mainClass>
<additionalClasspathElements>
<!-- The run environment must configure the system jar. -->
<element>${java.home}/lib/jfxswt.jar</element>
</additionalClasspathElements>
</configuration>
</plugin>
Notes:
The system scope is deprecated in maven in favor of installing files to repositories. The solution above works fine at the moment.
The content of the jfxswt.jar can be part of some SWT libraries unfortunately I am not familiar with SWT. If you can find that jar in a Maven repo than just include that instead of messing with the system scope.
The twobuttons.TwoButtons class is from the tutorial you mentioned.
Related
I am honestly about to just give up, i've tried so many different possibilities, for multiple weeks now, almost a month, of multiple problems.
I am a new-ish programmer, especially with java, but i have a good understanding about java
I am able to create a maven project no problem, i have no problems with the structure of java itself, but i don't fully understand the pom.xml.
The file compiles just fine, but when i go to start it with java -jar (filename), i get the following output;
Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/Pi4J
at com.pi.rasberri.Main.main(Main.java:16)
Caused by: java.lang.ClassNotFoundException: com.pi4j.Pi4J
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 1 more
Heres my pom that i have figuratively almost dismembered;
(The long links)
<modelVersion>4.0.0</modelVersion>
<groupId>com.pi</groupId>
<artifactId>Rasberri</artifactId>
<version>3.6.1</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties> <dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.32</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-core</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-raspberrypi</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-pigpio</artifactId>
<version>2.0</version>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId>
maven-jar-plugin 3.1.0
true
com.pi.rasberri.Main
lib/
true
true
com.pi.rasberri.Main
false
true
And my code, which is com.pi.rasberri.Main
package com.pi.rasberri;
import com.pi4j.Pi4J;
import com.pi4j.io.gpio.digital.DigitalOutput;
import com.pi4j.io.gpio.digital.DigitalState;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Main {
private static final int PIN_LED = 6;
public static void main(String[] args) throws Exception{
var pi4j = Pi4J.newAutoContext();
int x = 0;
var ledConfig = DigitalOutput.newConfigBuilder(pi4j)
.id("led")
.name("LED Flasher")
.address(PIN_LED)
.shutdown(DigitalState.LOW)
.initial(DigitalState.LOW)
.provider("pigpio-digital-output");
var led = pi4j.create(ledConfig);
while(x != 5){
led.high();
sleep(1000);
led.low();
sleep(500);
x++;
}
}
static void sleep(int z){
try {
Thread.sleep(z);
} catch (InterruptedException ex) {
System.out.println("Thread.sleep went fucky wucky");
}
}
}
I would appreciate anything that can even direct me somewhere, because i am quite lost at this point, and of course, if i figure out the answer, i will let everyone know!
Thanks in advance
**UPDATE**
Thank you, tgdavies, the article you linked
https://stackoverflow.com/a/574650/17644313 was the answer to that
specific problem!**
Just in case anyone else has the same chain of issues as me;
But with that being said, i ran directly into another error;
[main] INFO com.pi4j.Pi4J - New auto context
[main] INFO com.pi4j.Pi4J - New context builder
[main] INFO com.pi4j.platform.impl.DefaultRuntimePlatforms - adding platform to managed platform map [id=raspberrypi; name=RaspberryPi Platform; priority=5; class=com.pi4j.plugin.raspberrypi.platform.RaspberryPiPlatform]
Exception in thread "main" com.pi4j.provider.exception.ProviderNotFoundException: Pi4J provider [pigpio-digital-output] could not be found. Please include this 'provider' JAR in the classpath.
at com.pi4j.provider.impl.DefaultRuntimeProviders.get(DefaultRuntimeProviders.java:238)
at com.pi4j.provider.impl.DefaultProviders.get(DefaultProviders.java:147)
at com.pi4j.provider.Providers.get(Providers.java:253)
at com.pi4j.context.Context.create(Context.java:316)
at com.pi4j.internal.IOCreator.create(IOCreator.java:58)
at com.pi4j.internal.IOCreator.create(IOCreator.java:96)
at com.pi4j.internal.IOCreator.create(IOCreator.java:176)
at com.pi.rasberri.Main.main(Main.java:27)
I cleaned the pom.xml a littlebit;
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.32</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-core</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-raspberrypi</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-pigpio</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<build>
<plugins> <!--Package all libraries classes into one runnable jar -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>com.pi.rasberri.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
At this point, i know of atleast 2 possibilities,
The code just needs to be run on the raspberry pi
I have entered the classpaths incorrectly
But i honestly dont really know as to where to start troubleshooting
I've tried a few things, one of which being to try another method of compiling the files,
but the other method just resulted in a even longer string of errors.
What should i try next?
Thanks in advance!
And thanks to anyone who has suggested troubleshooting steps thus far!
Oh, and the target is to hopefully just create a singular jar file to execute on the raspberry pi
update
I tried to run it on the Raspberri pi, and it resulted in the same error so it's not that
I do not have a Raspberry Pi to do final testing but I think I found a work-around.
Using this answer I managed to get 2021-10-30-raspios-bullseye-armhf-lite.img running in Docker. I built a project using your code and copied all files needed and tried to start it (mypiapp is my jar containing your main-class):
java -cp mypiapp-0.0.1-SNAPSHOT.jar:lib/pi4j-core-2.1.1.jar:lib/pi4j-library-pigpio-2.1.1.jar:lib/pi4j-plugin-pigpio-2.1.1.jar:lib/pi4j-plugin-raspberrypi-2.1.1.jar:lib/slf4j-api-1.7.32.jar:lib/slf4j-simple-1.7.32.jar com.github.fwi.mypiapp.MyPiApp
which then gave me the error:
[main] ERROR com.pi4j.library.pigpio.util.NativeLibraryLoader - Unable to load [libpi4j-pigpio.so] using path: [/lib/armhf/libpi4j-pigpio.so]
java.lang.UnsatisfiedLinkError: /tmp/libpi4j-pigpio1770932771276400506.so: libpigpio.so.1: cannot open shared object file: No such file or directory
which is a bummer. But at least there was no ProviderNotFoundException (which I also could reproduce using the "fat jar with dependencies"). The long java-command appears to prevent that exception from happening.
And I could improve the situation somewhat by running (in Raspbian)
apt install pigpio
and now the long java-command shows:
[main] WARN com.pi4j.library.pigpio.impl.PiGpioNativeImpl - PIGPIO ERROR: PI_INIT_FAILED; pigpio initialisation failed
which is to be expected when running in a Docker container. But at least the native library was found and loaded.
Now for the work-around which might solve the "fat jar" problems. We are gonna borrow some Maven setup and code from Spring. Spring can also build fat-jars and does it a bit more complicated but also better. The pom now looks like (update where needed with your project names):
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.1</version>
</parent>
<groupId>com.github.fwi</groupId>
<artifactId>mypiapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>11</java.version>
<start.class>com.github.fwi.mypiapp.MyPiApp</start.class>
<pi4j.version>2.1.1</pi4j.version>
</properties>
<dependencies>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-raspberrypi</artifactId>
<version>${pi4j.version}</version>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-pigpio</artifactId>
<version>${pi4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start.class}</mainClass>
<layout>ZIP</layout>
<executable>false</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Simply run mvn clean package to build the fat-jar. Run it using java -jar mypiapp-fat.jar In my case, it gave the exact same error as when running with the long java-command (i.e. there was no ProviderNotFoundException). So I think this could work on a real Raspberry-Pi (the apt install pigpio might still be required though).
Some notes:
the Spring parent sets some good Maven defaults and also sets good defaults for the spring-boot-maven-plugin
Java version MUST be set using the java.version property.
update start.class with the name of the class containing your main-method.
the 3 dependencies in the pom.xml will pull in all other dependencies (dependencies of dependencies)
Spring documentation references: packaging and nested-jars launcher options.
Thanks tgdavies, MadProgrammer, and khmarbaise for the answers, the fix was to create a fat jar, which is basically a jar file that contains all the dependencies in one file, example can be found in the original question/comments
UPDATE!!
Pi4j has posted instructions for the V2 fat jar on their website!
I tried it and it works perfectly now
https://pi4j.com/getting-started/minimal-example-application-fatjar/
I faced the same issue working with Raspberry P4, java 11 and pi4j v2. I solved it downloading pigpio library directly from the raspberry
sudo apt-get install pigpio
After the library was installed, the jar worked perfecrly.
Remember also to run your program with sudo if you are not root user
I have Java Maven project in Eclipse. When I do maven build and set goal to package maven builds jar file with name my-project-0.0.1-SNAPSHOT.jar. I need package to be always constant name since I put it system that starts it with script. my-project.jar would be fine. How to achieve that?
How to ask maven to put all jar libraries my project is using into my-project.jar?
How to ask maven to place my-project.jar into particular folder target/ready_release. Currently maven puts jar into target folder. How to ask maven copy all libraries and configuration files project is using into this folder too.
Maybe I'm mistaking and all these jobs should be done under some other maven goal or any other operation?
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>com.aaa.rfid.scaleandlabel</groupId>
<artifactId>my-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<organization>
<name>aaa</name>
<url>www.aaa.lt</url>
</organization>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.scream3r</groupId>
<artifactId>jssc</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
</project>
You can specify the name of the package by configuring the jar plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<finalName>ready_release/my-project</finalName>
</configuration>
</plugin>
This will create the jar file at <project-root>/target/ready_release/jar-name.jar and every subsequent build will overwrite it.
This question already has answers here:
How can I create an executable/runnable JAR with dependencies using Maven?
(33 answers)
Closed 6 years ago.
i might have completely missundestood how maven works, but i have the following issue.
i created an application with maven in netbeans. it runs in netbeans fine, but when i make Clean and Build it just compiles my source files, and the maven dependendencies are not in the jar file, so cannot run in command window.
this is my pom file. it has build section, the dependencies are in the classpath of mainfest.mf
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ibh</groupId>
<artifactId>SafePassword</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.ibh.safepassword.TestMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.192</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>4.2.0.Final</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
i came from c# world, thought maven is similar than NuGet which is playing the game only in DEV phase, but at compile time everything is there ...
what is missing? how to execute the jar file to have the other dependencies in place and so the app can run?
thanks for your hints!
EDIT
i don't agree that this question is fully duplicated to the one you're referring to.
as i can read these many solutions maven is quite complicated, there is no ONE solution for every issue
By default Maven builds a jar that is basically a library - it doesn't contain its dependencies. If you want to include dependencies, making a runnable application, you have two main options:
Bundle everything in that one jar using some plugin that allows it, such as maven-shade-plugin. You can then run this jar.
Create a distribution bundle with your jar and all dependencies:
Use packaging that is designed to be a distribution, such as war or ear - if one of them matches your intent
Otherwise use generic bundling plugin, such as standard maven-assembly-plugin or even more advanced appassembler-maven-plugin
I downloaded this project(to convert docs to Pdf as the project name say) https://github.com/yeokm1/docs-to-pdf-converter on github then I tried to import in Eclipse but something is wrong. I got this error.
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6
I also have errors(I have a red cross on this file) in my pom.xml but this is my first project with maven, I'm not able to detect the problem. Here the code:
<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>docs-to-pdf-converter</groupId>
<artifactId>docs-to-pdf-converter</artifactId>
<version>1.8</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<version>2.32</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>org.apache.poi.xwpf.converter.pdf</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.6</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>org.odftoolkit.odfdom.converter.pdf</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.xdocreport.itext.extension</artifactId>
<version>1.0.5</version>
</dependency>
</dependencies>
</project>
I tried to see many other questions with a lot of solutions, but no one worked for me.
1) I tried to delete the .m2 folder : Not Worked
2) Try to make right click on the project and then Maven-Update Project: same error. Not Worked
3)I tried to go to WINDOW-PREFERENCE-MAVEN-INSTALLATION and then I changed Embedded with the folder that contains Maven, in my case C:\Maven Not Worked
4)I tried to go to WINDOW-PREFERENCE-JAVA-INSTALLED JREs where at the begin I just had C:\Program Files\Java\jre1.8.0_65, then I have read somewhere that I need Jdk 7, so I downloaded and install it but it doesn't work too. So, Now I have these two C:\Program Files\Java\jdk1.7.0_79 and C:\Program Files\Java\jre1.8.0_65
I also post a picture( I have not enough reputation to post two, in ordert to see also the Path Environment Variable) about the Environment variable, maybe I don't see something obvious. enter image description here
I'm sorry in advance because it could be a very easy question, but as I said above this is my first project with maven/eclipse and I'm not expert in this field.
I downloaded this project, and it compiled fine using Eclipse Mars.
It sounds like your Maven installation does not know how to go out to the internet to find artifacts. Could there be a firewall in the way?
Also, in Eclipse go to Window/Preferences/Maven/User settings. Make sure the settings.xml is the same one as used by your external Maven installation (assuming you are using an external Maven engine). For instance, I have set both the global and user config files to C:\development\tools64\apache-maven-3.3.3\conf\settings.xml
I checked my settings.xml, and there is no configuration that points to the maven central repository - Maven 3 must just know where to find it.
On the first compile, you should see lots of info messages saying that Maven is downloading artifacts. The next time you compile, these messages will not appear, as the dependencies are now cached in your local repository.
Currently I am moving from karaf 3.0.5 to the newest version 4.0.2, I do assembly my own karaf with the karaf-maven-plugin. This is how my pom looks like.
<?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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>my.own.group</groupId>
<artifactId>assemble</artifactId>
<version>1.14.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>karaf-customize</artifactId>
<modelVersion>4.0.0</modelVersion>
<packaging>karaf-assembly</packaging>
<dependencies>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>framework</artifactId>
<version>${karaf.version}</version>
<type>kar</type>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>standard</artifactId>
<classifier>features</classifier>
<version>${karaf.version}</version>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf.karaf</groupId>
<artifactId>apache-cxf</artifactId>
<classifier>features</classifier>
<version>${cxf.version}</version>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>enterprise</artifactId>
<classifier>features</classifier>
<version>${karaf.version}</version>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>my.own.group</groupId>
<artifactId>kar-archive</artifactId>
<version>1.14.0-SNAPSHOT</version>
<type>pom</type>
<optional>true</optional>
</dependency>
<dependency>
<groupId>my.own.group</groupId>
<artifactId>karaf-branding</artifactId>
<version>1.14.0-SNAPSHOT</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.alutam</groupId>
<artifactId>ziputils</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>${karaf.version}</version>
<extensions>true</extensions>
<configuration>
<javase>1.8</javase>
<bootFeatures>
<feature>jasypt-encryption</feature>
<feature>config</feature>
<feature>standard</feature>
<feature>region</feature>
<feature>management</feature>
<feature>bundle</feature>
<feature>package</feature>
<feature>kar</feature>
<feature>ssh</feature>
<feature>http</feature>
<feature>cxf</feature>
<feature>service-wrapper</feature>
<feature>jdbc</feature>
<feature>system</feature>
</bootFeatures>
</configuration>
</plugin>
</plugins>
</build>
</project>
With this configuration I do get the following error for several dependencies.
Caused by: org.osgi.framework.BundleException: Unsupported 'Bundle-ManifestVersion' value: 1
at org.apache.karaf.features.internal.resolver.ResourceBuilder.doBuild(ResourceBuilder.java:88)
at org.apache.karaf.features.internal.resolver.ResourceBuilder.build(ResourceBuilder.java:78)
I guess it happens within this parser. The reason is some old third party libraries have only Bundle-ManifestVersion: 1 set within their manifest file.
With karaf-maven-plugin 3.x this didn't matter at all. In contrast the karaf-maven-plugin 4.x fails with message above.
The only way I know to fix this is either rebuild from source or repack the hole jar again.
Is there any other way like a configuration for the karaf-maven-plugin to disable this constraint check? Because it would be awful lot of work to get all of this bundles up an running, again.
I faced the same error when updating to Karaf 4 and you have two choices:
Osgify conflictive dependency using bndtools:
Download bnd tools
Open a shell where you have downloaded bnd-2.4.0.jar.
Type:
java -jar bnd-2.4.0.jar wrap -o osgify-dependency.jar dependency.jar
where dependency.jar is your third party and osgify-dependency.jar will be the output.
Deploy to maven repo overriding the previous maven coordinates, or deploy your thirdparty with different coordinates.
mvn deploy:deploy-file -Dfile osgify-dependency.jar ..
Enable the wrap protocol
Add to you maven karaf plugin wrap and wrapper features.
So you can use wrap protocol to fix your corrupted MANIFEST.MF
Inside some karaf features:
<bundle>wrap:mvn:group.id/third.party.artefact.id/version</bundle>
Inside your pom.xml notice feature wrap / wrapper.
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
</executions>
<configuration>
<!-- no startupFeatures -->
<bootFeatures>
<feature>feature</feature>
<feature>jaas</feature>
<feature>shell</feature>
<feature>ssh</feature>
<feature>management</feature>
<feature>bundle</feature>
<feature>config</feature>
<feature>deployer</feature>
<feature>diagnostic</feature>
<feature>instance</feature>
<feature>kar</feature>
<feature>log</feature>
<feature>package</feature>
<feature>service</feature>
<feature>system</feature>
<feature>wrap</feature>
<feature>aries-blueprint</feature>
</bootFeatures>
<installedFeatures>
..
<feature>wrapper</feature>
</installedFeatures>
</configuration>
</plugin>
Here you have the full code where i tested:
https://github.com/antoniomaria/gazpachoquest/blob/master/karaf-assembly/pom.xml