Error with JavaFX Project: ImageIO and BufferedImage not visible - java

I'm working on revamping a JavaFX project I created back in 2018. I have the original main script but now there seems to be 2 FX related errors now. import javax.imageio.ImageIO; import java.awt.image.BufferedImage; I am using Apache NetBeans with Maven version 12.5 and I am using OpenJDK 17 and OpenJFX 17.
The error is saying for both that these packages are not visible, and that they are declared in module java.desktop but module com.mycompany.realestate2021 does not read it.
pom.xml portion below
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>RealEstate2021</artifactId>
<version>1.0-SNAPSHOT</version>
<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.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>com.mycompany.realestate2021.App</mainClass>
</configuration>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
</execution>
<execution>
<!-- Configuration for manual attach debugging -->
<!-- Usage: mvn clean javafx:run#debug -->
<id>debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000</option>
</options>
</configuration>
</execution>
<execution>
<!-- Configuration for automatic IDE debugging -->
<id>ide-debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</option>
</options>
</configuration>
</execution>
<execution>
<!-- Configuration for automatic IDE profiling -->
<id>ide-profile</id>
<configuration>
<options>
<option>${profiler.jvmargs.arg1}</option>
<option>${profiler.jvmargs.arg2}</option>
<option>${profiler.jvmargs.arg3}</option>
<option>${profiler.jvmargs.arg4}</option>
<option>${profiler.jvmargs.arg5}</option>
</options>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
How do I fix this issue(s)?

Check the module-info.java for your project, and make sure that it contains a line for "java.desktop":
module xyz {
requires transitive java.desktop;
... }
This declares that your project uses the definitions from java.desktop - which include BufferedImage. You may also need declarations for JavaFX such as:
requires transitive javafx.base;
requires transitive javafx.controls; // etc
requires transitive javafx.graphics;

Related

Unable to add javafx.web to Maven project on VS Code [duplicate]

This question already has an answer here:
Cannot resolve symbol 'WebView'. JavaFX WebView with Maven in IntelliJ IDEA [duplicate]
(1 answer)
Closed last month.
I'm new to maven and java projects as a whole and I've been trying to add javafx.web to my Maven project, specifically for the HTMLEditor class, on VS Code and so far have been unable to.
I've added the dependency to the pom.xml file and put in VM Arguments that lead to my installation of JavaFX and nothing has worked.
Is there a way to do this that I'm missing or would it be better to just add a copy of the javafx.web.jar that is in the JavaFX\javafx-sdk\lib folder directly somehow?
My pom.xml file:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dylan.gresham</groupId>
<artifactId>nottah</artifactId>
<version>1.0</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.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>19</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>19</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>dylan.gresham.Main</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>dylan.gresham.Driver</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My VM Arguments:
--module-path C:\Users\dylan\Downloads\JavaFX\javafx-sdk-18.0.1\lib --add-modules =ALL -MODULE-PATH
My module-info.java:
module dylan.gresham {
requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
opens dylan.gresham to javafx.fxml;
exports dylan.gresham;
}
Edit: Added module-info file above.
As pointed out by #James_D I needed to add requires javafx.web; to my module-info.java file. After adding that line I was able to import what I needed to.

Maven compiling with different JDK versions

My application is split between users on Java 1.6u45 and Java 1.8. Our problem is that we cannot specify the project system library and have two different compiler settings for the code at the same time.
Project Structure:
Project >
> src/main/java/com/us/javafx/... (Java 8 code)
> src/main/java/com/us/... (Java 6 code)
> src/main/resources/...
Our POM.xml:
<?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.us</groupId>
<artifactId>PROJECT</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>PROJECT</name>
<description>DESCR</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<!-- Copy all dependencies to jars directory -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/jars</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- Maven Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<!-- Necessary to avoid setting JRE on Maven project update! -->
<!-- SEE PHOTO FOR WHY THIS IS HERE -->
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<!-- Compile Java 6 directory -->
<execution>
<id>java6</id>
<configuration>
<excludes>
<exclude>com/us/javafx/**/*</exclude>
</excludes>
<!-- Non working attempt to set compiler version -->
<source>1.6</source>
<target>1.6</target>
</configuration>
</execution>
<!-- Compile Java 8 directory -->
<execution>
<id>java8</id>
<configuration>
<includes>
<include>com/us/javafx/**/*</include>
</includes>
<!-- Non working attempt to set compiler version -->
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
</plugin>
<!-- Create JAR in jars folder -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<outputDirectory>${project.build.directory}/jars</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
If we tell the Maven compiler plugin to use Java 1.8, Java 1.6 users get the unsupported major minor version error. Or we tell the Maven compiler plugin to use Java 1.6 but our Java 8 code will complain about errors when performing Right Click Project > Maven > Update Project... (which causes the screen shot below):
Is there a way we can achieve both:
1) Compile Java 6 and 8 code with their respective compilers
2) Choose Java 8 as our project's JRE System Library
I recently learned about toolchains.xml. Maven has it even documented and supports it from 2.0.9! See toolchains documentation
So I added a toolchain.xml file to my ~/.m2/ folder with following content:
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 http://maven.apache.org/xsd/toolchains-1.1.0.xsd">
<!-- JDK toolchains -->
<toolchain>
<type>jdk</type>
<provides>
<version>1.8</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>/opt/java8</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>1.7</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>/opt/java7</jdkHome>
</configuration>
</toolchain>
</toolchains>
It allows you to define what different JDKs Maven can use to build the project irrespective of the JDK Maven runs with. Sort of like when you define JDK on project level in IDE. I used it when I needed to build another project with Java 7 while having Java 8 as a default.
I guess this can solve your issue.
Maven profiles is the simplest and most effective one.
You can elect and run them from your IDE too.
You design a profile for each different JDK you need. You put in each different JDK profile :
properties like source code target
dependencies that are specialised for that profile.
Project
+properties
+dependencies
+Profiles
Profile JDK8
+jdk8-properties
jdk.version
maven.compiler.source
maven.compiler.target
+jdk8-dependencies
Profile JDK11
+jdk11-properties
jdk.version
maven.compiler.source
maven.compiler.target
+jdk11-dependencies
Picture of maven profiles tree
And an example
<project>
<name>x</name>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.210</version>
</dependency>
</dependencies>
<profiles>
<!-- different Java versions -->
<profile>
<id>jdk8</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<jdk.version>1.8</jdk.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core-jakarta</artifactId>
<version>5.6.10.Final</version>
</dependency>
<!-- needed if jakarta is used -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.25</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>jdk11</id>
<properties>
<jdk.version>11</jdk.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.1.2.Final</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.4.2</version>
</dependency>
</dependencies>
</profile>
</profiles>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
<junit-version>4.13.2</junit-version>
</properties>
</project>

How to generate HTML report with Maven FindBugs?

I know a similar question has been asked here, but my setup within pom.xml is a bit different and that answer isn't working for my case.
I have findbugs set up so that when I run [mvn compile findbugs:findbugs], I get the default findbugsXML.xml generated. I would like to get an html file generated so that it's more readable. Below is what I've added to pom.xml in order to get findbugs set up. I'm not sure why the html file isn't being generated given that I've included that specification when making the pom.xml edits. The below was added into the plugins section of build in 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>findbugs-cookbook</artifactId>
<packaging>jar</packaging>
<version>3.0.1</version>
<name>FindBugs Maven plugin Cookbook</name>
<description>FindBugs Maven plugin Cookbook</description>
<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
<properties>
<jdk.version>1.7</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>findbugs</finalName>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<!--</plugins>
<plugins> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<effort>Max</effort>
<failOnError>false</failOnError>
<findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
<threshold>Low</threshold>
<xmlOutput>true</xmlOutput>
</configuration>
<executions>
<execution>
<id>analyze-compile</id>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<transformationSets>
<transformationSet>
<dir>${project.build.directory}/findbugs</dir>
<outputDir>${project.build.directory}/findbugs</outputDir>
<!--<stylesheet>fancy-hist.xsl</stylesheet> -->
<!--<stylesheet>default.xsl</stylesheet> -->
<!--<stylesheet>plain.xsl</stylesheet>-->
<!--<stylesheet>fancy.xsl</stylesheet>-->
<!--<stylesheet>summary.xsl</stylesheet>-->
<fileMappers>
<fileMapper
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>.html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
</transformationSets>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
I'm using Apache Maven 3.2.3 and Java version: 1.8.0_20. I've also included findbugs-3.0.1.jar and findbugs-maven-plugin-3.0.1.jar in my apache-maven-3.2.3 directory.
There are 4 variables:
java/JDK version
maven version
findbugs plugin version
findbugs version
With java-1.7, it works on my Windows system with the specified versions of maven, findbugs, findbugs-maven-plugin. Essentially older versions of findbugs does not work with java 8.
With java-1.8, it works if I use version 3.0.1 of findbugs and findbugs-maven-plugin.
Since you have bound findbugs goals to compile task, you just need to run mvn clean compile.

Upgrade application using OpenJPA to Java 8

I am trying to upgrade my application to Java 8, but it uses OpenJPA with build time enhancement through the openjpa-maven-plugin 2.3.0, which seems to be the last version.
When I build my application, I get an IllegalArgumentException because that version of the plugin is using a PCEnhancer that depends on org.apache.xbean.asm4.ClassReader, that is not compatible with Java 8. I found this ticket: https://issues.apache.org/jira/browse/OPENJPA-2386, but still it is not solved.
Do you know any other way to implement the build enhancement for openjpa without using the openjpa-maven-plugin?
As you pointed out, Java 8 with its additional syntax is not compatible with OpenJPA 2.3.0 class enhancement. However, if you absolutely need to use code with OpenJPA 2.3.0 which is written for the Java 8 standard library, you can still compile your code using a JDK for Java 8 which outputs Java version <8 bytecode. For example, I use this workaround in Maven:
POM:
<?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.stackoverflow.examples</groupId>
<artifactId>openjpa-2.3.0-jdk8</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>openjpa-2.3.0-jdk8</name>
<url>http://stackoverflow.com/a/29343171/1391325</url>
<properties>
<!-- NOTE: As of OpenJPA version 2.3.0, Java 8 is still unsupported -->
<javac.version>1.7</javac.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<openjpa.version>2.3.0</openjpa.version>
<openjpa.entityDir>com/stackoverflow/examples/persistence/entities</openjpa.entityDir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>${openjpa.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${javac.version}</source>
<target>${javac.version}</target>
<!-- NOTE: The variable "JAVA_8_HOME" must be set either in the Maven
settings.xml file or as an environment variable! -->
<executable>${JAVA_8_HOME}/bin/javac</executable>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>enforce-property</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireProperty>
<property>JAVA_8_HOME</property>
<message>Property "JAVA_8_HOME" not set.</message>
</requireProperty>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>${openjpa-maven-plugin.version}</version>
<configuration>
<includes>${openjpa.entityDir}/*.class</includes>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<!-- set the version to be the same as the level in your runtime -->
<version>${openjpa.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>java-8-home</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<JAVA_8_HOME>/usr/lib/jvm/java-8-oracle/</JAVA_8_HOME>
</properties>
</profile>
</profiles>
</settings>

Not generating OSGI-INF folder

I am new to OSGI.I have been having trouble to get OSGI-INF folder in generated jar file.
I need to have folder structure like as below
META-INF
OSGI-INF
Com.mine.cq
I am using Eclipse and m2e plugin. When I run my project I am getting BUILD SUCCESS. And I am getting the below folder structure in that generated jar file.
META-INF
Com.mine.cq
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>com.mine.cq</groupId>
<artifactId>mineCore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mineCore</name>
<url>http://maven.apache.org</url>
<properties>
<file.encoding>utf-8</file.encoding>
</properties>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-alpha-3</version>
<executions>
<execution>
<id>enforce-java</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<message>Project must be built with Maven 2.0.7 or higher</message>
<version>2.0.7</version>
</requireMavenVersion>
<requireJavaVersion>
<message>Project must be compiled with Java 5 or higher</message>
<version>1.5.0</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.3</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>
com.mine.cq.mineCore.*
</Export-Package>
<Import-Package>
*;resolution:=optional,
javax.servlet;version=2.4,
javax.servlet.http;version=2.4
</Import-Package>
<Embed-Dependency>
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Include-Resource>{maven-resources}</Include-Resource>
<Sling-Bundle-Resources>/var/classes</Sling-Bundle-Resources>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.0</version>
<configuration>
<goals>install</goals>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Why OSGI-INF folder is not in the .jar file? I need to set some information in OSGO-INF folder since I have to register my component as a OSGI service.
Please guide me to get it done.
Although being pretty late, I'll post my 2 cents about this issue for future reference.
As already pointed out, you can have the "packaging" of the bundle set to "jar" if you follow the instructions given in Maven bundle plugin documentation.
There is just a little gotcha: with that configuration, you need to explicitly add <exportScr>true</exportScr> inside the plugin configuration in order to properly create the SCR xml file (also remember to adjust manifest location, since in the documentation that piece is absent!).
You can see an example here (that's totally different from yours, but I assume you can easily reduce it on your code, if you're still interested):
<?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.massimobono.karaf.examples</groupId>
<artifactId>user-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<!-- Here you specifiy that you want to use the manifest file generated by maven bundle plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<!-- Here you generate the whole MANIFEST by using maven-bundle-plugin -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.2.0</version>
<extensions>true</extensions> <!-- make sure this is present -->
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<manifestLocation>${project.build.outputDirectory}/META-INF/</manifestLocation> <!-- make sure this is present! in the example of maven bundle plugin documentation, this piece is NOT present -->
<exportScr>true</exportScr> <!-- be sure to add this line as well -->
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<_dsannotations>*</_dsannotations>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.osgi/org.osgi.service.component.annotations -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
</project>
Your pom.xml needs to have a packaging type of "bundle" rather than "jar". If you want the packaging type to be "jar", use this:
http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html#ApacheFelixMavenBundlePlugin%28BND%29-AddingOSGimetadatatoexistingprojectswithoutchangingthepackagingtype
EDIT: Oh! That's only problem one. The other problem is that I don't think you can generate
OSGI-INF with the maven-bundle-plugin. You need to create the OSGI-INF folder yourself within src/main/resources or use a plugin that generates OSGI-INF.
The maven-scr-plugin can generate OSGI-INF, but it's only useful if you are using SCR. Maven SCR Plugin - Not generating OSGI-INF folder

Categories