Glassfish 4.1.1 and offline JSP compiler (JSP and OSGI) - java

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.

Related

How to generate java stubs from protobuf for Java target 11 using maven?

I am trying to generate stub using protobuf.
My pom.xml has below code
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<protocVersion>3.8.0</protocVersion>
<includeStdTypes>true</includeStdTypes>
<inputDirectories>
<include>src/main/proto</include>
</inputDirectories>
<outputTargets>
<outputTarget>
<type>java</type>
</outputTarget>
<outputTarget>
<type>grpc-java</type>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.24.0</pluginArtifact>
</outputTarget>
</outputTargets>
</configuration>
</execution>
</executions>
</plugin>
However, it generates the source files with target as Java1.8.
I am migrating my apps to Java 11, and have included the below jars in pom.xml file:
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.3.2</version>
</dependency>
However maven protoc plugin generates the files Grpc.java with annotnation javax.annotation.Generated instead of javax.annotation.api.Generated
Is there any other way for generating the java stub with target version as JDK 11.
If you follow the grpc-java documentation, it instructs you to use:
<dependency> <!-- necessary for Java 9+ -->
<groupId>org.apache.tomcat</groupId>
<artifactId>annotations-api</artifactId>
<version>6.0.53</version>
<scope>provided</scope>
</dependency>
Previous versions of the examples used javax.annotation:javax.annotation-api:1.2, which does work, but it was replaced with Tomcat for licensing reasons. In your pom.xml, it seems you might have mixed up "activation" vs "annotation", which look pretty similar at a glance.
I'm not aware of a javax.annotation.api.Generated annotation. I've not seen any real evidence that javax.annotation.processing.Generated is an appropriate replacement for javax.annotation.Generated either.

Error while having multiple servlet-api libs on classpath

I have Spring Boot app running with embedded Tomcat. I'm running it in docker container. When I try to follow this page about spring boot in container and build layered image I recieve error mentioned below when I try to start the container. I know that the best way would be to exclude old version of servlet-api from my dependecies but it's impossible as this dependency stops working while I'm doing that. Unfortunately I cannot also get rid of this dependency. Is there a way to force Spring Boot to use specific implementation from classpath? I've tried Jetty and Undertow and docker successfully started but then lib that is using older version didn't work properly.
Other question is why it's working when I'm copy just jar and start it?
Dockerfile that I'm trying to build:
FROM adoptopenjdk:11-jre-hotspot
ARG DEPENDENCY=target/dep
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.test.App"]
Dockerfile that works:
FROM adoptopenjdk:11-jre-hotspot
COPY /target/application.jar /app/application.jar
COPY /target/lib /app/lib
ENTRYPOINT ["java", "-jar", "app/application.jar"]
The one that works requires additional plugins in pom.xml to make it possible:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<finalName>ttom-osm-converter</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.tomtom.mep.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Dependecies from POM:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency> <!-- lib contains servlet-api-2.5 -->
<groupId>com.test.lib</groupId>
<artifactId>client</artifactId>
<version>${model.client.version}</version>
</dependency>
Error:
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [NonLoginAuthenticator[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[/path]
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1220)
The following method did not exist:
'java.lang.String javax.servlet.ServletContext.getVirtualServerName()'
The method's class, javax.servlet.ServletContext, is available from the following locations:
jar:file:/app/lib/servlet-api-2.5.jar!/javax/servlet/ServletContext.class
jar:file:/app/lib/javax.servlet-api-4.0.1.jar!/javax/servlet/ServletContext.class
jar:file:/app/lib/tomcat-embed-core-9.0.29.jar!/javax/servlet/ServletContext.class
It was loaded from the following location:
file:/app/lib/servlet-api-2.5.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
From the error about 'java.lang.String javax.servlet.ServletContext.getVirtualServerName()', we can see that is was added in Servlet 3.1: you should exclude servlet-api:2.5.
Use the following command:
mvn dependency:tree -Dincludes='*:servlet-api'
This will list you all all module/dependencies including servlet-api.
Then excludes the bad version from dependencies: the com.test.lib client should not even includes it in the first place, meaning the dependency should be provided in it as well.
<dependency> <!-- lib contains servlet-api-2.5 -->
<groupId>com.test.lib</groupId>
<artifactId>client</artifactId>
<version>${model.client.version}</version>
<exclusions> <exclusion> <groupId>...</groupId> <artifactId>servlet-api</artifactId> </exclusion> </exclusions>
</dependency>
Do note that the servlet-api groupId changed over the course of time: that's probably one reason why Maven does not select the "good" servlet-api.
And I would advise you to use maven-enforcer-plugin to lock these bad dependencies:
<rules>
<bannedDependencies>
<excludes>
<exclude>*:servlet-api:2.5</exclude>
</excludes>
</bannedDependencies>
</rules>
<fail>true</fail>
See http://maven.apache.org/enforcer/enforcer-rules/bannedDependencies.html for more information.
Now then you mention that your lib (com.test.lib) seems to not work without servlet-api 2.5, which means it use code that was probably removed between Servlet 2.5 and 3.1: your only course of action is to upgrade your lib as to not depends on said code:
The first servlet-api (2.5) is loaded
Tomcat and Spring Boot are compiled against later version
Tomcat/Spring Boot will may try to use a method added in later version
You will have another error and so on.
You can access to path:
~/.m2/repository/javax/servlet/servlet-api
And clear folder serverlet. For example:
rm -rf 2.5
Finally you re-run application and everything is ok.

Converting a regular Maven project to a Spring Boot project

My supervisor asked me to convert an old Maven project we have lying around into a Spring Boot project such that we are able to access the project's backend via RESTful interaction (before that the project's backend was only accessible via a console interface).
So, first I added a simple Spring Boot application in a separate package of project. After that I began to extend the pom.xml of the project by the dependencies needed for Spring Boot and adjusted the overall project setup. Now, I tried to run the backend of the old project, which turned out to be working. However, the simple Spring Boot application did not.
I narrowed down the problem to a conflicting dependency in the "old" part of the pom.xml:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.1</version>
</dependency>
When I leave this dependency in the pom.xml the old backend works, but the Spring Boot application fails with the following error:
WARN: Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
If I comment this dependency out the Spring Application works completely fine, but the old backend fails. I use the version 2.0.4.RELEASE of spring-boot-admin-starter-server. I think that the old backend's version of the logging package is different from the one included in spring-boot-admin-starter-server. However, I somehow need both versions in my project.
What's not possible:
Updating the old sources, since some of them have a coyright of an
external company
What I already tried, but I wasn't successful with:
Exclude the logging from then Spring Boot depedencies. This results in the following error:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
I also to tried to work with the shade plugin as some suggested from my web research. Unfortunately, I was not able to solve the problem with this approach.
Does anyone have suggestions how to solve this problem? I would be very grateful. I am not used to solve dependency problems of this kind. Please excuse me, if I am missing something obvious.
-lema
EDIT pom.xml (unfortunately I had to leave out bigger parts of it) :
<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>
...
<packaging>jar</packaging>
<description></description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-boot-admin.version>2.0.2</spring-boot-admin.version>
<spring-boot-dependencies.version>2.0.4.RELEASE</spring-boot-dependencies.version>
...
<rat.skip>true</rat.skip>
<log4j-version>2.6.1</log4j-version>
</properties>
<repositories>
...
</repositories>
<dependencyManagement>
<dependencies>
<!-- Necessary dependency for running Spring Boot without starter parent -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Fowler-SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
...
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>${spring-boot-admin.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
...
<!-- TODO The version of this dependency lets Spring Boot fail, but is
necessary tu run the old backend -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-iostreams</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
...
</dependencies>
<build>
<defaultGoal>verify</defaultGoal>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
...
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>prepare-config-zip</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${basedir}/src/main/assembly/config.xml</descriptor>
</descriptors>
<finalName>configs</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
<execution>
<id>prepare-dist-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>src/main/assembly/dist.xml</descriptor>
<finalName>...</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<configuration>
<rules>
<requireJavaVersion>
<version>1.8</version>
</requireJavaVersion>
</rules>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>attach-standalone</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>standalone</shadedClassifierName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>dont-attach-standalone</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<!-- Prevent huge shaded artifacts from being deployed to Artifactory -->
<outputFile>...</outputFile>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
EDIT: I just found out that if you remove the version element inside of the conflicting dependency the Spring Boot Application works, but unfortunately the backend then fails.
So I found a solution, but that's probably not the best way to do it:
I just replaced the <spring-boot-dependencies.version>2.0.4</spring-boot-dependencies.version> with an older version that is compatible with the conflicting logging dependency, namely version 1.4.7.RELEASE.
This is the latest version at which both the Spring Boot application and the backend are working simultaneously (found that out by try-and-error).
Anyway, thank you very much for your help.
Cheers

IKVM jar to dll issues

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

Maven: Missing dependency when using test-jar at runtime

My Maven project foo.web has its source files in src/main and the test sources in src/test. Of course, the test classes make use of the "main" classes. Now I want to use the test classes in another project during runtime, so I followed these instructions on how to create a test-jar.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
This works perfectly well, a jar like web-SNAPSHOT-tests.jar is created and I can include it in my other project.
<dependency>
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>test-jar</type>
</dependency>
But it seems like the dependency to web-SNAPSHOT is not correctly set, because at runtime I receive NoClassDefFoundErrors of classes which are available in foo.web. So I added another dependency:
<dependency>
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
Unfortunately, this changes nothing. Does anyone know what is wrong here?
WAR archives are structured differently from JARs. When running in an application server such as Tomcat or JBoss, the server will handle the WAR correctly. Since you are running outside of a server, the artifact will be used like to a normal JAR archive. Because WARs use different locations for the .class files, the NoClassDefFoundError is thrown at run time.
In a JAR, the class com.example.Foo will be stored at /com/example/Foo.class. Since WARs are designed to contain libraries, resources etc. the classes should not be stored relative to the root of the archive. Instead, they are contained in the folder /WEB-INF/classes, Foo would be stored as /WEB-INF/classes/com/example/Foo.class.
Fortunately, the Maven developers thought of this issue and added the attachClasses option to the WAR plugin. This option creates an additional JAR with the classes classifier that contains only the Java classes in JAR format (relative the the archive root).
To enable the building of this JAR, you can use this snippet in your WAR project's build section (in addition to the configuration for the maven-jar-plugin to build the test JAR):
<pluginManagement>
<plugins>
<!-- … -->
<plugin>
<!-- build the classes JAR (non-test classes) -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- … -->
<plugin>
<!-- build the test JAR (test classes) -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Since the classes are attached, they will be installed and deployed by Maven together with the WAR artifact. Note that this only provides you with the contents of the regular WAR archive, to use the test classes, you need to depend on both the classes artifact and the test jar. To do this, you can use:
<dependencies>
<!-- … -->
<dependency>
<!-- test classes only -->
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>test-jar</type>
</dependency>
<dependency>
<!-- non-test classes only -->
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>jar</type>
<classifier>classes</classifier>
<scope>runtime</scope>
</dependency>
</dependencies>
Try:
<dependency>
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>war</type>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Maven allows you some configuration regarding snapshots dependancy
<repository>
<id>foo-repository</id>
<url>...</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>XXX</updatePolicy>
</snapshots>
Check the above config. If its false in pom.xml maven will not update snapshots. Also you will find the following thread useful for your query What exactly is a Maven Snapshot and why do we need it?

Categories

Resources