JOOQ : Generate sources with maven in Eclipse is not generating any file - java

I am new to JOOQ and Maven. I want to generate Pojo by giving schema, as per JOOQ's documentation says. I tried with commandline way, and it was working perfectly. I added same configuration in Eclipse java project. Below is my pom.mxl
<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>PojoGenerator</groupId>
<artifactId>PojoGenerator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rutherford.pojo</name>
<build>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<!-- <artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin> -->
<!-- Specify the maven code generator plugin -->
<!-- Use org.jooq for the Open Source edition org.jooq.pro for commercial
editions, org.jooq.pro-java-6 for commercial editions with Java 6 support,
org.jooq.trial for the free trial edition -->
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.8.4</version>
<!-- The plugin should hook into the generate goal -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<!-- Manage the plugin's dependency. In this example, we'll use a PostgreSQL
database -->
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
</dependency>
</dependencies>
<!-- Specify the plugin configuration. The configuration format is the
same as for the standalone code generator -->
<configuration>
<!-- JDBC connection parameters -->
<jdbc>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/test</url>
<user>postgres</user>
<password>test</password>
</jdbc>
<!-- Generator parameters -->
<generator>
<database>
<name>org.jooq.util.postgres.PostgresDatabase</name>
<includes>.*</includes>
<excludes></excludes>
<inputSchema>public</inputSchema>
</database>
<target>
<packageName>com.generated.pojo</packageName>
<directory>${project.build.directory}/src</directory>
</target>
</generator>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I tried generate resources. It says BUILD SUCCESS, but I can't see my generated Pojos anywhere. Please let me know what am I missing.

You still need to add the plugin to your build, as <pluginManagement> only helps you declare common configurations for reuse.
<build>
<pluginManagement>...</pluginManagement>
<plugins>
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<execution>...</execution>
</plugin>
</plugins>
</build>
See also this question here: Maven: What is pluginManagement?
In this case, it's probably simpler to just ignore this well-known issue in Eclipse and avoid the <pluginManagement> element.

Related

Execution of Scala and Maven project

I have created a simple maven project of Scala in eclipse's scala ide using below details -
Artifact Id - scala-archetype-simple
Group Id - net.alchim31.maven
After created the project I have modified the 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>com.test</groupId>
<artifactId>scalapoc</artifactId>
<version>0.0.1</version>
<name>${project.artifactId}</name>
<description>Test scala app</description>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.version>2.11.5</scala.version>
<scala.compat.version>2.11</scala.compat.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2-core_${scala.compat.version}</artifactId>
<version>2.4.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2-junit_${scala.compat.version}</artifactId>
<version>2.4.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.compat.version}</artifactId>
<version>2.2.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<!-- <arg>-make:transitive</arg> -->
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
<archive>
<manifest>
<mainClass>App.scala</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<useFile>false</useFile>
<disableXmlReport>true</disableXmlReport>
<!-- If you have classpath issue like NoDefClassError,... -->
<!-- useManifestOnlyJar>false</useManifestOnlyJar -->
<includes>
<include>**/*Test.*</include>
<include>**/*Suite.*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have also added manifest entry inside plugin tag.
<archive>
<manifest>
<mainClass>App.scala</mainClass>
</manifest>
</archive>
I have only one App.scala file and one test file available in project. Build was successful. But when trying to execute the jar using java -jar <jar_name> getting below error -
no main manifest attribute, in scalapoc-0.0.1.jar
When trying to execute the command java -cp scalapoc-0.0.1.jar com.test.scalapoc.App.scala getting below error -
Error: Could not find or load main class com.test.scalapoc.App.scala
Please suggest what to be needed to execute the jar.
try
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.test.scalapoc.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
.scala is for source only, source is not executable
archive tag is part of the configuration of a plugin
see https://maven.apache.org/shared/maven-archiver/examples/classpath.html#Make
UPDATE 2018-06-05:
To create a standalone jar (without need to defined a classpath with scala-library and other dependencies on command line), you should create a jar that included other classes/jar.
see:
Apache Maven Shade Plugin – Executable JAR and the rest of the doc of the plugin for tuning & configuration
or the old one-jar tool Deliver Your Java Application in One-JAR™ !

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