IKVM jar to dll issues - java

I'm having hard times trying to convert my .jar library in .dll and make it working by IKVM framework.
I wrote a Java library that works fine since it has been tested succesfully in several java projects, but I strongly need the .dll for .NET.
When I launch the command:
ikvm -jar mylib.jar
everything is ok (I also tried with a Main file to be sure: it works).
But, when I type:
ikvmc -target:library mylib.jar
I got a lot of warnings but still it creates the .dll file. It is important to say that ALL the warnings are related to libraries that I DO NOT use in my project, but I am pretty sure are in the packages I imported in Maven that are essential to me.
I don't know if the true problem is in this step since I read online to ignore those warnings, but to be sure I post a little bit of the output:
warning IKVMC0100: Class "junit.framework.TestCase" not found
warning IKVMC0100: Class "javax.servlet.http.HttpServlet" not found
warning IKVMC0100: Class "javax.servlet.ServletOutputStream" not found
warning IKVMC0100: Class "org.junit.Assert" not found
warning IKVMC0100: Class "junit.framework.TestSuite" not found
warning IKVMC0100: Class "org.apache.tools.ant.taskdefs.MatchingTask" not found
Let us suppose this step is ok, now I have to import the IKVM libraries and the mylib.dll file in the References of my C# app. I did and the outcome is pretty strange: the autocomplete environment suggest me to use only 4 Java classes, ignoring the 99% of the others. I suppose that something went wrong, but it's pretty hard to me understand where and how to fix it.
Just more helpful info: I'm using Maven, Java8 (sdk 1.8) and IKVM 8.
I also tried the same with IKVM 7 and still got the same errors.
In the end, this 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>org.fra.mylibrary</groupId>
<artifactId>MyLibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MYLIBRARY</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- https://mvnrepository.com/artifact/net.sourceforge.owlapi/owlapi-distribution -->
<dependencies>
<!-- https://mvnrepository.com/artifact/net.sourceforge.owlapi/owlapi-distribution -->
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>4.1.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.antlr/antlr4-runtime -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sourceforge.owlapi/jfact -->
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>jfact</artifactId>
<version>4.0.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- ANTLR4 -->
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.5.3</version>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<!-- Maven Assembly Plugin to create Jar -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<!-- Maven Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

Just remove all code related to latest version of method and classes , and change it to lower version of library of java , may it work , because I have same error like this

Related

Glassfish 4.1.1 and offline JSP compiler (JSP and OSGI)

As everyone knows jsp can't work with classes outside current osgi web archive bundle. This is a bug in GF. The developers of glassfish for workaround of this bug https://java.net/jira/browse/GLASSFISH-11208 offer to use offline jsp compiler (by other words to compile jsp files not during deployment time but during archive building time). Ok, and I used jspc-maven-plugin to compile my jsp during wab building.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<version>1.4.6</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<id>compile</id>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
The jsp are compiled and I see their .classes in built web archive.
Now the problem - how can I make glassfish use my compiled jsp but not to compile it itself? Because I see that GF ignores compiled .classes and generate .javas and compile them itself.
EDIT 1 What I make up to now:
1) I added to glassfish-web.xml
<jsp-config>
<property name="usePrecompiled" value="true"/>
<!-- to see it doesn't generate .javas -->
<property name="keepgenerated" value="true" />
</jsp-config>
2)And when I build my wab archive I have jsp classes in WEB-INF/classes/jsp/... However, I get exception that jsp file not found. When I manually move jsp classes to WEB-INF/classes/org/apache/jsp... I see that container now sees these classes but I get
StandardWrapperValve[default]: Servlet.service() for servlet default threw exception
java.lang.NoClassDefFoundError: org/apache/jsp/... (wrong name: jsp/...)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2370)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2154)
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1542)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1925)
at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:978)
at org.glassfish.osgijavaeebase.BundleClassLoader.loadClass(BundleClassLoader.java:79)
at org.glassfish.osgiweb.OSGiWebDeploymentContext$WABClassLoader.loadClass(OSGiWebDeploymentContext.java:169)
at org.glassfish.osgiweb.OSGiWebDeploymentContext$WABClassLoader.loadClass(OSGiWebDeploymentContext.java:154)
at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:654)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:202)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:695)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:626)
So know this is the right path - org/apache/jsp. The question is how to make maven plugin to output to this direction?
EDIT 2
So I found the settings of this maven plugin -
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<version>1.4.6</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<id>compile</id>
<configuration>
<packageName>org.apache.jsp</packageName>
</configuration>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
However, this is the final point but not result. As I get no exception, bute the returned http request is empty (blank page in browser). Seems I should use another maven plugin but which one?
So, to all steps which I did and explained in my edit it is necessary to modify web.xml file because plugin will add there mapping for servlets generated from jsp pages. So, the final settings are :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<version>1.4.6</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<id>compile</id>
<configuration>
<!-- package where the compiled jsp classes will be put -->
<packageName>org.apache.jsp</packageName>
<!-- the plugin adds servlets to this web.xml file -->
<outputWebXml>${project.build.directory}/web.xml</outputWebXml>
<verbose>true</verbose>
<target>8</target>
<source>8</source>
</configuration>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
EDIT
Finally I found out that the version of jasper in GlassFish 4.1 is not known or even can be modified -> I got exceptions that such method not found etc. So I ended with the following - I donwloaded the sources of this plugin and made it use the version of the jasper in glassfish. I did not do any modifications in source code of the plugin, only in pom.xml. So the final pom became:
<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">
<!--<parent>
<artifactId>mojo</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>11</version>
</parent>-->
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<version>1.4.6</version>
<packaging>maven-plugin</packaging>
<name>Maven Jspc plugin</name>
<developers>
<developer>
<name>Jeff Genender</name>
<email>jgenender#apache.org</email>
<organization>Savoir Technologies</organization>
<organizationUrl>http://www.savoirtech.com</organizationUrl>
<timezone>-7</timezone>
</developer>
</developers>
<contributors>
<contributor>
<name>Grzegorz Slowikowski</name>
<email>gs#tiger.com.pl</email>
<organization>Scott Tiger S.A.</organization>
<organizationUrl>http://www.tiger.com.pl</organizationUrl>
<timezone>+1</timezone>
</contributor>
<contributor>
<name>Pawel Pastula</name>
<email>pablo#tiger.com.pl</email>
<organization>Scott Tiger S.A.</organization>
<organizationUrl>http://www.tiger.com.pl</organizationUrl>
<timezone>+1</timezone>
</contributor>
</contributors>
<dependencies>
<!-- from glassfish 4.1.1 modules folder we need:
javax.servlet.jsp.jar
javax.servlet-api.jar
javax.servlet.jsp-api.jar
javax.el.jar
javax.servlet.jsp.jstl-api.jar
javax.servlet.jsp.jstl.jar
what versions of this jar you can find out in parent pom of glassfish
http://repo.maven.apache.org/maven2/org/glassfish/main/glassfish-parent/4.1.1/glassfish-parent-4.1.1.pom
and in manifest file
-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.2-b01</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp</artifactId>
<version>2.3.3-b02</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.4</version>
</dependency>
<!-- we need this dependency as it contais tld files for core tag library -->
<dependency>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>org.apache.jasper.glassfish</artifactId>
<version>2.2.2.v201112011158</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
When you will compile you bundle you will have to add the following dependencies:
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp</artifactId>
<version>2.3.3-b02</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.4</version>
</dependency>
Besides you will need to import some packages from glassfish to make it work. So in result you can use precompiled jps files with glassfish, but you need to make some things before it. And as you see you link your code to GF.
The most important thing - you can work with classes from other osgi bundles in jsp! For those who work with osgi in java-ee this can be very important. After doing all these steps I must conclude that GF IS NOT SUPPORTED TO BE USED WITH PRECOMPILED JPS FILES in spite of suggestions from the developers.
I hope at least one will appreciate all the solution, because it seems to me this is the first description in internet how to use precompiled jps pages with GF. By the way if you use osgi and it complains it can't find classes import the necessary packages.

PMD rule set is not getting downloaded/updated through MAVEN

I tried to integrate PMD in one of my project (I am using MAVEN Build tool)
When I try to integrate, I can see XML configuration files are mandatory.
I have tried to download PMD plugin - I expected global ruleset files might be available in PMD plug in, but they are not.
I used below link:
https://sourceforge.net/projects/pmd/?source=typ_redirect
After googling, I have seen one link to get ruleset
http://grepcode.com/file/repo1.maven.org/maven2/pmd/pmd/4.3
I cant download all XML files.
Is there any way to download/update through build or can we get all XML files in one location anywhere? I tried my level best to search in google and couldn't figure it out.
I attached pom.xml here. Can you please let me know how to add my ruleset automatically whenever PMD updated automatically?
<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.scm</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>SCM-PRODUCT</name>
<description>SCM Product for learning purpose</description>
<properties>
<java.version>1.7</java.version>
<hibernate.validator.version>5.2.4.Final</hibernate.validator.version>
<javax.el-api.version>2.2.4</javax.el-api.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<checkstyle-config-url>
D:/rules/checkstyle/2.0/checkstyle-2.0.xml
</checkstyle-config-url>
<checkstyle.version>6.18</checkstyle.version>
<log4j.version>1.2.17</log4j.version>
<!-- TEST CASES RELATED BEGINS-->
<junit.version>4.12</junit.version>
<!-- TEST CASES RELATED ENDS HERE-->
<!-- STATIC CODE ANALYSIS PROPERTIES -->
<findbugs.plugin.version>3.0.3</findbugs.plugin.version> <!-- Reports on common code mistakes and pitfalls -->
<checkstyle.plugin.version>5.0</checkstyle.plugin.version> <!-- Checks Code Style for Developers -->
<pmd.plugin.version>3.6</pmd.plugin.version> <!-- Source Code Analyzer -->
<doxia.module.markdown.version>1.3</doxia.module.markdown.version>
<javadoc.plugin>2.8.1</javadoc.plugin> <!-- Generates JavaDoc -->
<jxr.plugin>2.3</jxr.plugin> <!-- Cross reference report of project source code -->
<!-- REPORTING TOOL PROPERTIES -->
<project.info.reports.plugin>2.4</project.info.reports.plugin> <!-- A plethora of miscellaneous report: info, ci, dependencies, scm, plugins, etc. -->
<site.plugin>3.1</site.plugin>
<sonar.plugin>3.2-RC3</sonar.plugin> <!-- Analysis and metrics on code over time -->
<surefire.plugin>2.12</surefire.plugin> <!-- Reports Test Results -->
<taglist.plugin>2.4</taglist.plugin> <!-- Reports on Tags such as #todo and //TODO -->
<versions.plugin>1.3.1</versions.plugin>
<maven-compiler-plugin>3.1</maven-compiler-plugin>
<cobertura.plugin>2.5.1</cobertura.plugin> <!-- Reports Test Coverage -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<modules>
<module>services</module>
<module>presentation</module>
<module>service_validator</module>
<module>jsonvo</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate.validator.version}</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>${javax.el-api.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- http://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- http://mvnrepository.com/artifact/net.sourceforge.pmd/pmd -->
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>5.4.2</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugin</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<includeTests>true</includeTests>
<rulesets>
<ruleset>${checkstyle-config-url}</ruleset>
</rulesets>
<minimumTokens>100</minimumTokens>
<targetJdk>${java.version}</targetJdk>
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${pmd.plugin.version}</version>
<configuration>
<targetJdk>${java.version}</targetJdk>
<minimumTokens>20</minimumTokens>
<skipEmptyReport>false</skipEmptyReport>
<failOnViolation>true</failOnViolation>
<printFailingErrors>true</printFailingErrors>
<!--<includeTests>true</includeTests>-->
<rulesets>
<ruleset>${pom.basedir}/pmd-rulesets.xml</ruleset>
</rulesets>
<!--
<excludeRoots>
<excludeRoot>target/generated-sources/antlr</excludeRoot>
<excludeRoot>target/generated-sources/antlr/com/puppycrawl/tools/checkstyle/grammars/javadoc</excludeRoot>
</excludeRoots>
-->
</configuration>
<executions>
<execution>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
<goal>cpd-check</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${findbugs.plugin.version}</version>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
<excludeFilterFile>config/findbugs-exclude.xml</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
</plugins>
</build>
</project>
If you don't need to use your custom pmd rulesets you can omit the rulesets tag altogether.
If you want to use only some of pmd rulesets you can use predefined ones:
<rulesets>
<ruleset>/rulesets/java/braces.xml</ruleset>
<ruleset>/rulesets/java/naming.xml</ruleset>
</rulesets>
You are using version 3.6 of the maven-pmd-plugin. There is a default value for the rulesets - it's java-basic, java-imports and java-unusedcode. See the maven-pmd-plugin documentation.
If you want to start with these rulesets, you can omit the rulesets tag altogether, as krzyk mentioned.
Maven Plugin 3.6 uses PMD 5.3.5 - so downloading rulesets for PMD 4.3 will not work.
But, you don't need to download the rulesets. You can create your own custom ruleset, which references the rules you want to have checked in your code. And this would be your file pmd-rulesets.xml.
Is there any way to download/update through build or can we get all XML
files in one location anywhere?
There is no such a ruleset. Enabling all rules PMD provides, doesn't make sense, as some rules contradict each other. Please read "Best Practices": Choose the rules that are right for you.
Can you please let me know how to add my ruleset automatically whenever PMD
updated automatically?
You don't need to add your ruleset - you are using it already. However, if a new PMD version has new rules, you won't necessarily have these new rules activated. So, you might want to read the release notes of PMD and checkout if there are new interesting rules. Then you can reference the new rules in your ruleset file.
For the java language, you can see the available rules in the Rulesets index.

Specify both jar and test-jar types in Maven dependencies

I have a project called "commons" that contains common includes for both runtime and test.
In the main project I added a dependency for commons:
<dependency>
<groupId>com.alexb</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
However the test common files are not included. So I added :
<dependency>
<groupId>com.alexb</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
However when type is test-jar, the runtime is not included.
Unfortunatelly, it seems I cannot include both:
<type>jar,test-jar</type>
What can I do to include both?
As #khmarbaise mentioned in the comments you should separate your test-jar part project.
I presume you have in the commons pom.xml something like this which generates common test-jar.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
The problem with this approach is that you don't get the transitive test-scoped dependencies automatically.
Check this link for more details:
https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html

Add InstallerListener to IzPack installer project with Maven

I have a working IzPack installer project set up with maven and added following to my install script install.xml to [installation][listeners]:
<listener classname="(company-name).listener.InstallerListener" stage="install"/>
Sadly, the line seems to be ignored and the debugger does not halt on set breakpoints in the InstallListener class. I have read the documentation for InstallListeners, but it is not useful as I have the build process integrated with maven; here are the relevant parts of the Project Object Model pom.xml:
<properties>
<izpack-standalone.version>4.3.1</izpack-standalone.version>
</properties>
<dependencies>
<!-- izpack -->
<dependency>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-standalone-compiler</artifactId>
<version>${izpack-standalone.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
<plugins>
<!-- IzPack compiler -->
<plugin>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-maven-plugin</artifactId>
<version>${org.codehaus.izpack.izpack-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-standalone-compiler</artifactId>
<version>${izpack-standalone.version}</version>
</dependency>
</dependencies>
<configuration>
<izpackBasedir>${staging.dir}</izpackBasedir>
<customPanelDirectory>${staging.dir}</customPanelDirectory>
</configuration>
<executions>
<execution>
<id>standard-installer</id>
<phase>package</phase>
<goals>
<goal>izpack</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
What am I missing here?
Note: The compiled installer does contain the specified InstallerListener class file, so it is available at runtime.
You must place the jar file containing your panel classes into the {customPanelDirectory}/bin/panels folder where it will be picked up automatically by the izpack-maven-plugin.
In the case above this folder would resolve to {staging.dir}/bin/panels since you configured <customPanelDirectory>${staging.dir}</customPanelDirectory>.
Adding it to install.xml file will not work, since this would be resolved at install time, but not at installer build time.

Maven 3 - How to add annotation processor dependency?

I need to run an annotation processor on my project's sources. The annotation processor should not become a transitive dependency of the project since it's only needed for annotation processing and nothing else.
Here is the complete (non-working) test pom I use for this:
<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>test</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Test annotations</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hibernate-jpamodelgen.version>1.2.0.Final</hibernate-jpamodelgen.version>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<annotationProcessors>
<annotationProcessor>
org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</annotationProcessor>
</annotationProcessors>
<debug>true</debug>
<optimize>true</optimize>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<AaddGeneratedAnnotation>true</AaddGeneratedAnnotation>
<Adebug>true</Adebug>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate-jpamodelgen.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
I explicitly defined org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor as an annotation processor in the plugin configuration for tests and I know it shouldn't be required.
The problem I'm encountering is that the hibernate-jpamodelgen dependency is not added to the compiler classpath so the annotation processor is not found and the build fails.
As per this answer, I tried adding the dependency as a build extension (not sure I understand what those are supposed to be!) like so:
<extensions>
<extension>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate-jpamodelgen.version}</version>
</extension>
</extensions>
This also doesn't add hibernate-jpamodelgen to the compiler classpath.
The only thing I found which works so far is adding the dependency to the project in the <dependencies> section. This has the unfortunate side-effect of adding hibernate-jpamodelgen as a transitive dependency afterwards which I want to avoid.
My previous working setup uses the maven-processor-plugin plugin to achieve what I want. However, this plugin is not supported by eclipse m2e and the latest version of the maven-compiler-plugin now handles multiple compiler arguments properly so I'd rather use the latter.
The annotationProcessorPaths option can be used in recent versions of the Maven compiler plug-in:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.2.6.Final</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</pluginManagement>
That way the processor is separated from the actual project dependencies. This option is also picked up by the Eclipse M2E plug-in if annotation processing is enabled for the project.
Add the dependency as an optional dependency (<optional>true</optional>). This will add the dependency under compilation, but will prevent it for being a transitive dependency:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate-jpamodelgen.version}</version>
<optional>true</optional>
</dependency>
If you're creating an artifact in this module with all your dependencies in it (like a .war), you may use the <scope>provided</scope> instead. This both prevents the dependency to be transitive and to be included in the artifact the module produces.
For JDK 10 I really had to go a bit crazy to get it to work, Hoping someone finds this useful
<jaxb.version>2.3.0</jaxb.version>
<maven.hibernate.version>5.3.2.Final</maven.hibernate.version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/annotations</outputDirectory>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${maven.hibernate.version}</version>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
<annotationProcessors>
<annotationProcessor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</annotationProcessor>
</annotationProcessors>
<compilerArgs>
<arg>-AaddGeneratedAnnotation=false</arg>
</compilerArgs>
<compilerArguments>
<AaddGeneratedAnnotation>false</AaddGeneratedAnnotation>
<Adebug>true</Adebug>
</compilerArguments>
<failOnError>true</failOnError>
</configuration>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${maven.hibernate.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb.version}</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
The problem is really in 3.* version of the maven-compiler-plugin. It acts a bit different from the 2.* version. In particular, it seems that maven-compiler-plugin3.* doesn't add its dependencies and build extensions to the classpath because it uses javax.tools instruments for running compile process. To get back the old behavior for maven-compiler-plugin you should use a new configuration property forceJavacCompilerUse:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
....
</plugin>
Please take a look jpa-metamodels-with-maven
For further visitors, I found that there are some significant changes in maven-compiler-plugin 3.x series.
This is how I do this. (I'm the one who you linked)
The point is that my solution does not work with those 3.x series of maven-compiler-plugin.
<project ...>
<build>
<extensions>
<extension>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>1.3.0.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version> <!-- See this? -->
</plugin>
</plugins>
</build>
</project>
Not sure what kind of build error you got, but here is my case:
I got the following compile error in Idea:
Annotation processor 'org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor' not found error
But, when compiled from Maven, it was all fine.
So, the problem of mine was that somehow I got wrong configuration in Idea settings. Particularly, it appeared that Idea somehow detected the processor and put in into the settings of module processor profiles. It is discussed here.
I fixed it as the following:
Go to Idea > Settings > Annotation Processors.
For each processor profile make sure that:
Enable annotation processing is Yes;
There is no annotation processor FQ name of one you have error about (e.i. "JPAMetaModelEntityProcessor") in the list on the right side. If it is listed there, just select and click '-' minus button to remove it.
I think this is a better way to contain such dependencies in profiles to solve such problems.
<profile>
<id>XXX-profile</id>
<dependencies>
<dependency>
// XXX artifact path
</dependency>
</dependencies>
</profile>

Categories

Resources