Jersey Guice Integration exception - java

I'm struggling to get Guice to work with my Jersey/Grizzly classes. I started with console Java app, added Guice and got my injection working as well as my domain objects. Then I proceeded to add webservices through Jersey/Grizzly. As you might be able to tell from my coding style, I've come from a C# background. So I'm sure some of my struggle is learning Javas way of doing things.
What I want is that my non webservices classes can get injected into the webservices handlers so they can use the functionality I've built.
In my class below, I have a database instance handler I want to inject into the webservices classes:
#Path("/options")
public class OptionsServices {
private IDatabaseService dbService;
#Inject
public void setService(IDatabaseService svc){
this.dbService = svc;
}
#GET
#Path("{symbol}")
#Produces(MediaType.APPLICATION_JSON)
public Quote getOptionQuote(#PathParam("symbol") String symbol) {
// do stuff
}
}
I tried adding in GuiceBridge and binding that in my extension of the ResourceConfig class. But no matter what version I used, I get some really crazy exceptions about missing properties when I tried to initialize the webservices. Simply removing GuiceBridge from my pom.xml removes the exception. It seems like its version compatibility problem but I am at a loss to understand what version of what library.
Exception in thread "main" java.lang.NoSuchMethodError: org.glassfish.hk2.utilities.general.GeneralUtilities.getSystemProperty(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
at org.jvnet.hk2.internal.ServiceLocatorImpl.<clinit>(ServiceLocatorImpl.java:122)
at org.jvnet.hk2.external.generator.ServiceLocatorGeneratorImpl.initialize(ServiceLocatorGeneratorImpl.java:66)
at org.jvnet.hk2.external.generator.ServiceLocatorGeneratorImpl.create(ServiceLocatorGeneratorImpl.java:98)
at org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.internalCreate(ServiceLocatorFactoryImpl.java:312)
at org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.create(ServiceLocatorFactoryImpl.java:268)
at org.glassfish.jersey.internal.inject.Injections._createLocator(Injections.java:138)
at org.glassfish.jersey.internal.inject.Injections.createLocator(Injections.java:123)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:308)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:289)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:334)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:122)
at Application.Server.WebServer.startServer(WebServer.java:40)
at Application.Server.WebServer.Start(WebServer.java:45)
at Application.Startup.run(Startup.java:68)
at Application.Startup.main(Startup.java:87)
And 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>tatmancapital</groupId>
<artifactId>ServerConsole</artifactId>
<version>R1</version>
<properties>
<jersey.version>2.17</jersey.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>guice-bridge</artifactId>
<version>2.5.0-b32</version>
</dependency>
<dependency>
<groupId>commons-httpclient-ssl-contrib</groupId>
<artifactId>commons-httpclient-ssl-contrib</artifactId>
<version>3.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/commons-httpclient-contrib-ssl-3.1.jar</systemPath>
</dependency>
<dependency>
<groupId>etrade</groupId>
<artifactId>com.etrade.accounts</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/etws-accounts-sdk-1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>etrade</groupId>
<artifactId>com.etrade.order</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/etws-order-sdk-1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>etrade</groupId>
<artifactId>com.etrade.oauth</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/etws-oauth-sdk-1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>etrade</groupId>
<artifactId>com.etrade.markets</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/etws-market-sdk-1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>etrade</groupId>
<artifactId>com.etrade.common</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/etws-common-connections-1.0.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<mainClass>Application.Startup</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
<finalName>ServerConsole-V1</finalName>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I apologize I cannot explain this problem with more definitive here's what is wrong. I may have architected my app completely wrong and given this is just me learning, I am ok with that. I would like to avoid rewriting my domain logic construction and unit tests.
Thank you for your help
Matt

Error explanation
A java.lang.NoSuchMethodError is definitely an error with packages and library versions. It means that you have compiled code referencing a method that do not exist in your runtime code.
It's not an error commonly seen in your code because the compiler won't let you pass code referencing a non existent method. But in this case the code referencing the method and the referenced code are both libraries so that means that the code with the method reference was compiled against a different version of the target class.
Somehow this error is analogous to the more common ClassNotFoundException. But instead of not finding a class you are not finding a method inside a class.
Finding the source of your problem
Now you know what the problem is. Solving it, I'm afraid, is not that easy. Package managment and library resolution with Java is becoming harder every year. I see you are using the bom (Bill of Materials) for the Jersey library. Also, your pom file is not an easy one. I suggest you to build a test project only with the structure of your API (jax-rs) code with Guice and the HK2-Guice bridge. Maybe instead of using the BOM try this recent versions, they work for me:
com.google.inject:guice:4.1.0
org.glassfish.jersey.containers:jersey-container-servlet:2.25
org.glassfish.hk2:guice-bridge:2.5.+
I'm using the servlet container but you are using an standalone one. It doesn't matter, use yours but keep the version number.
Maven resolution
Also try to check which version of each package you are including in the final build. You may find useful this maven command to display the dependency tree:
https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html

Related

GraalVM native image not working with logs

What I try to do:
mvn package -Dpackaging=docker-native -Dmicronaut.runtime=lambda -Pgraalvm
what I get:
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException:
No instances of org.apache.logging.slf4j.SLF4JLogger
are allowed in the image heap as this class should be initialized at image runtime.
ok! Let me just trace the instantiation and find the issue:
[INFO] Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of org.apache.logging.slf4j.SLF4JLogger are allowed in the image heap as this class should be initialized at image runtime. Object has been initialized by the org.hibernate.internal.util.SerializationHelper class initializer with a trace:
at org.apache.logging.slf4j.SLF4JLogger.<init>(SLF4JLogger.java:41)
at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:36)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:666)
at org.jboss.logging.Log4j2Logger.<init>(Log4j2Logger.java:36)
at org.jboss.logging.Log4j2LoggerProvider.getLogger(Log4j2LoggerProvider.java:30)
at org.jboss.logging.Log4j2LoggerProvider.getLogger(Log4j2LoggerProvider.java:26)
at org.jboss.logging.Logger.getLogger(Logger.java:2465)
at org.jboss.logging.Logger.doGetMessageLogger(Logger.java:2573)
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2530)
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:28)
at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:24)
at org.hibernate.internal.util.SerializationHelper.<clinit>(SerializationHelper.java:47)
. To fix the issue mark org.apache.logging.slf4j.SLF4JLogger for build-time initialization with --initialize-at-build-time=org.apache.logging.slf4j.SLF4JLogger or use the the information from the trace to find the culprit and --initialize-at-run-time=<culprit> to prevent its instantiation.
Sounds promising!
Trying with --initialize-at-build-time=org.apache.logging.slf4j.SLF4JLogger:
[INFO] Error: Classes that should be initialized at run time got initialized during image building:
org.apache.logging.log4j.util.ProviderUtil was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.ProviderUtil got initialized use --trace-class-initialization=org.apache.logging.log4j.util.ProviderUtil
org.apache.logging.log4j.util.PropertySource$Util was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.PropertySource$Util got initialized use --trace-class-initialization=org.apache.logging.log4j.util.PropertySource$Util
org.apache.logging.log4j.LogManager was unintentionally initialized at build time. To see why org.apache.logging.log4j.LogManager got initialized use --trace-class-initialization=org.apache.logging.log4j.LogManager
org.apache.logging.log4j.spi.Provider was unintentionally initialized at build time. To see why org.apache.logging.log4j.spi.Provider got initialized use --trace-class-initialization=org.apache.logging.log4j.spi.Provider
org.apache.logging.log4j.Level was unintentionally initialized at build time. To see why org.apache.logging.log4j.Level got initialized use --trace-class-initialization=org.apache.logging.log4j.Level
org.apache.logging.slf4j.SLF4JLogger$1 was unintentionally initialized at build time. To see why org.apache.logging.slf4j.SLF4JLogger$1 got initialized use --trace-class-initialization=org.apache.logging.slf4j.SLF4JLogger$1
org.apache.logging.log4j.util.Constants was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.Constants got initialized use --trace-class-initialization=org.apache.logging.log4j.util.Constants
org.apache.logging.log4j.util.LoaderUtil was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.LoaderUtil got initialized use --trace-class-initialization=org.apache.logging.log4j.util.LoaderUtil
org.apache.logging.log4j.spi.StandardLevel was unintentionally initialized at build time. To see why org.apache.logging.log4j.spi.StandardLevel got initialized use --trace-class-initialization=org.apache.logging.log4j.spi.StandardLevel
org.apache.logging.log4j.util.Strings was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.Strings got initialized use --trace-class-initialization=org.apache.logging.log4j.util.Strings
org.apache.logging.log4j.util.PropertiesUtil was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.PropertiesUtil got initialized use --trace-class-initialization=org.apache.logging.log4j.util.PropertiesUtil
org.apache.logging.log4j.status.StatusLogger was unintentionally initialized at build time. To see why org.apache.logging.log4j.status.StatusLogger got initialized use --trace-class-initialization=org.apache.logging.log4j.status.StatusLogger
org.apache.logging.log4j.spi.LoggerRegistry was unintentionally initialized at build time. To see why org.apache.logging.log4j.spi.LoggerRegistry got initialized use --trace-class-initialization=org.apache.logging.log4j.spi.LoggerRegistry
okay.... but I can try the other option!
try with: --initialize-at-run-time=<culprit>. According to logs the culprit was org.hibernate.internal.util.SerializationHelper:
[INFO] Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of org.apache.logging.slf4j.SLF4JLogger are allowed in the image heap as this class should be initialized at image runtime. Object has been initialized by the org.hibernate.internal.log.DeprecationLogger class initializer with a trace:
at org.apache.logging.slf4j.SLF4JLogger.<init>(SLF4JLogger.java:41)
at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:36)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:666)
at org.jboss.logging.Log4j2Logger.<init>(Log4j2Logger.java:36)
at org.jboss.logging.Log4j2LoggerProvider.getLogger(Log4j2LoggerProvider.java:30)
at org.jboss.logging.Log4j2LoggerProvider.getLogger(Log4j2LoggerProvider.java:26)
at org.jboss.logging.Logger.getLogger(Logger.java:2465)
at org.jboss.logging.Logger.doGetMessageLogger(Logger.java:2573)
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2530)
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
at org.hibernate.internal.log.DeprecationLogger.<clinit>(DeprecationLogger.java:29)
. To fix the issue mark org.apache.logging.slf4j.SLF4JLogger for build-time initialization with --initialize-at-build-time=org.apache.logging.slf4j.SLF4JLogger or use the the information from the trace to find the culprit and --initialize-at-run-time=<culprit> to prevent its instantiation.
Looks like there wasn't only one culprit? okay this time for sure it will work!
including second cuplrit:
[INFO] Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException:
No instances of org.apache.logging.slf4j.SLF4JLogger are allowed in the image heap as this class should be initialized at image runtime.
Object has been initialized by the org.hibernate.internal.SessionFactoryRegistry class initializer with a trace:
There is no end to this!
Going for the whole package: --initialize-at-run-time=org.hibernate:
[INFO] Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of org.apache.logging.slf4j.SLF4JLogger are allowed in the image heap as this class should be initialized at image runtime. Object has been initialized by the org.hibernate.internal.util.SerializationHelper class initializer with a trace:
Let's try to go back to --initialize-at-build-time=org.apache.logging.slf4j.SLF4JLogger but instead specify the whole package: --initialize-at-build-time=org.apache.logging
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:08 min
[INFO] Finished at: 2022-10-14T16:33:04+03:00
[INFO] ------------------------------------------------------------------------
It's built! Now let's see if it runs!
...
Caused by: com.amazonaws.serverless.exceptions.ContainerInitializationException: Error starting Micronaut container: Bean definition [io.micronaut.configuration.hibernate.jpa.conf.SessionFactoryPerDataSourceFactory] could not be loaded: Error instantiating bean of type [io.micronaut.configuration.hibernate.jpa.conf.SessionFactoryPerDataSourceFactory]
...
Caused by: java.lang.NoSuchMethodException: org.apache.logging.log4j.message.ParameterizedMessageFactory.<init>()
...
At this point I'm out of options.
GRAALVM_VERSION: 22.2.0
GRAALVM_JVM_VERSION: java17
GRAALVM_ARCH: amd64
CLASS_NAME: io.micronaut.function.aws.runtime.MicronautLambdaRuntime
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>moe.sigeemu</groupId>
<artifactId>si-gameless</artifactId>
<version>0.1</version>
<packaging>${packaging}</packaging>
<parent>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-parent</artifactId>
<version>3.7.1</version>
</parent>
<properties>
<packaging>jar</packaging>
<jdk.version>17</jdk.version>
<release.version>17</release.version>
<micronaut.version>3.7.1</micronaut.version>
<exec.mainClass>io.micronaut.function.aws.runtime.MicronautLambdaRuntime</exec.mainClass>
<micronaut.test.resources.enabled>true</micronaut.test.resources.enabled>
<micronaut.runtime>lambda</micronaut.runtime>
<micronaut.data.version>3.8.0</micronaut.data.version>
<vavr.version>0.10.3</vavr.version>
</properties>
<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-validation</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut.aws</groupId>
<artifactId>micronaut-function-aws-api-proxy</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut.aws</groupId>
<artifactId>micronaut-function-aws-api-proxy-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.micronaut.aws</groupId>
<artifactId>micronaut-function-aws-custom-runtime</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-client</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-jackson-databind</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<version>${vavr.version}</version>
</dependency>
<dependency>
<groupId>io.micronaut.aws</groupId>
<artifactId>micronaut-aws-sdk-v2</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-hibernate-jpa</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut.flyway</groupId>
<artifactId>micronaut-flyway</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut.graphql</groupId>
<artifactId>micronaut-graphql</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut.sql</groupId>
<artifactId>micronaut-jdbc-hikari</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-mysql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.micronaut.test</groupId>
<artifactId>micronaut-test-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.graphql-java-generator</groupId>
<artifactId>graphql-java-runtime</artifactId>
<version>1.18</version>
<exclusions>
<exclusion>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-spring-boot-starter-webmvc</artifactId>
</exclusion>
<exclusion>
<groupId>com.graphql-java-generator</groupId>
<artifactId>graphql-java-spring-mvc</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.micronaut.build</groupId>
<artifactId>micronaut-maven-plugin</artifactId>
<configuration>
<nativeImageBuildArgs combine.children="append">
<nativeImageBuildArg>--trace-object-instantiation=org.apache.logging.slf4j.SLF4JLogger</nativeImageBuildArg>
<!-- <nativeImageBuildArg>--initialize-at-run-time=org.hibernate.internal.log.DeprecationLogger</nativeImageBuildArg>-->
<nativeImageBuildArg>--initialize-at-build-time=org.apache.logging</nativeImageBuildArg>
</nativeImageBuildArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- Uncomment to enable incremental compilation -->
<!-- <useIncrementalCompilation>false</useIncrementalCompilation> -->
<annotationProcessorPaths combine.self="override">
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject-java</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-processor</artifactId>
<version>${micronaut.data.version}</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-graal</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-validation</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-validation</artifactId>
<version>${micronaut.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-Amicronaut.processing.group=moe.sigeemu</arg>
<arg>-Amicronaut.processing.module=si-gameless</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>com.graphql-java-generator</groupId>
<artifactId>graphql-maven-plugin</artifactId>
<version>1.18</version>
<executions>
<execution>
<goals>
<goal>generateClientCode</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>moe.sigeemu.domain.model.graphql.generated</packageName>
<copyRuntimeSources>false</copyRuntimeSources>
<generateDeprecatedRequestResponse>false</generateDeprecatedRequestResponse>
<separateUtilityClasses>true</separateUtilityClasses>
<customScalars>
<customScalar>
<graphQLTypeName>CountryCode</graphQLTypeName>
<javaType>com.nimbusds.openid.connect.sdk.assurance.claims.ISO3166_1Alpha2CountryCode</javaType>
<graphQLScalarTypeStaticField>moe.sigeemu.domain.model.scalars.GraphQLScalarTypeCountryCode.CountryCode</graphQLScalarTypeStaticField>
</customScalar>
<customScalar>
<graphQLTypeName>FuzzyDateInt</graphQLTypeName>
<javaType>java.time.LocalDate</javaType>
<graphQLScalarTypeStaticField>moe.sigeemu.domain.model.scalars.GraphQLScalarTypeFuzzyDateInt.FuzzyDateInt</graphQLScalarTypeStaticField>
</customScalar>
<customScalar>
<graphQLTypeName>Json</graphQLTypeName>
<javaType>com.fasterxml.jackson.databind.JsonNode</javaType>
<graphQLScalarTypeStaticField>moe.sigeemu.domain.model.scalars.GraphQLScalarTypeJson.Json</graphQLScalarTypeStaticField>
</customScalar>
</customScalars>
</configuration>
</plugin>
</plugins>
</build>
</project>
A cry for help to anyone who was able to read through this post and knows a little bit more about Micronaut and GraalVM: what am doing wrong? I'm desperate and want to go back to Spring since there is little to no info on the internet about native images T_T
I had a similar issue:
First I had this error:
UnresolvedElementException: Discovered unresolved method during parsing: io.netty.util.internal.logging.Log4J2Logger
Then after adding the following dependency: implementation("org.jboss.logmanager:log4j2-jboss-logmanager") as documented here on Quarkus website I had this one:
Discovered unresolved type during parsing: org.apache.log4j.Logger
I finally added these two dependencies and I was passed that Logging related errors and on to other but its ok, its progress!!!
implementation("org.jboss.logging:commons-logging-jboss-logging")
implementation("org.jboss.logmanager:log4j-jboss-logmanager")
implementation("org.jboss.slf4j:slf4j-jboss-logmanager")

Package 'com.example' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base' -- how to solve?

I try to add some class of java RMI that works fine in separate project.
When i added the classes to my java fx project , i have got this error:
Package 'com.example' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base'
this is my pom.xml:enter image description here
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>FXtest</artifactId>
<version>1.0-SNAPSHOT</version>
<name>FXtest</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.8.1</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>17.0.1</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.1.0</version>
</dependency>
<dependency>
<groupId>com.dlsc.formsfx</groupId>
<artifactId>formsfx-core</artifactId>
<version>11.3.2</version>
<exclusions>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.synedra</groupId>
<artifactId>validatorfx</artifactId>
<version>0.1.13</version>
<exclusions>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
<version>12.2.0</version>
</dependency>
<dependency>
<groupId>org.kordamp.bootstrapfx</groupId>
<artifactId>bootstrapfx-core</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>eu.hansolo</groupId>
<artifactId>tilesfx</artifactId>
<version>11.48</version>
<exclusions>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.fxtest/com.example.fxtest.HelloApplication</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
this is the console error i get when i run my rmi-server:
Exception in thread "main" java.lang.reflect.InaccessibleObjectException: Unable to make public abstract void com.example.fxtest.shared.CardgameServer.toUpperCase(java.lang.String,com.example.fxtest.shared.CardgameClient) throws java.rmi.RemoteException accessible: module com.example.fxtest does not "exports com.example.fxtest.shared" to module java.rmi
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
at java.rmi/sun.rmi.server.UnicastServerRef$HashToMethod_Maps$1.run(UnicastServerRef.java:598)
at java.rmi/sun.rmi.server.UnicastServerRef$HashToMethod_Maps$1.run(UnicastServerRef.java:596)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at java.rmi/sun.rmi.server.UnicastServerRef$HashToMethod_Maps.computeValue(UnicastServerRef.java:595)
at java.rmi/sun.rmi.server.UnicastServerRef$HashToMethod_Maps.computeValue(UnicastServerRef.java:574)
at java.rmi/sun.rmi.server.WeakClassHashMap.get(WeakClassHashMap.java:74)
at java.rmi/sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:236)
at java.rmi/java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:475)
at java.rmi/java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:360)
at com.example.fxtest/com.example.fxtest.server.ServerImpl.<init>(ServerImpl.java:13)
at com.example.fxtest/com.example.fxtest.server.RunServer.main(RunServer.java:15)
i addad a photo of my module-info.java where the error is found.
any adivce will be appreciated!
thanks
To address the issue reported in the exception trace in the question body:
java.rmi.RemoteException accessible: module com.example.fxtest does not "exports com.example.fxtest.shared" to module java.rmi
you need to do what the message says.
Add to the module-info.java:
exports com.example.fxtest.shared to java.rmi;
Related question:
Unable to export a package from java.base module
For the question in the title:
Package 'com.example' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base'
There is not enough information in the question to do more than speculate on the reason for that. It is likely related to an error in your local development environment or in some aspect of your project setup. It could be that:
you are using a Java runtime that includes a different version of JavaFX
OR
have dependencies transitively on different versions of JavaFX
OR
you have some manual command-line switches to modules configured incorrectly
OR
you added a JavaFX SDK version that clashes with your dependencies
OR
you may have manually added incompatible versions of the JavaFX library manually in the IDE
OR
some 3rd party libraries you use are bundling JavaFX framework code inside them (which they should not do).
Which it is, I don’t know, but I offer the information in case it is needed.
Curious what sort of troubleshooting you attempted.
Have you tried removing the javafx-controls dependency? I think javafx-web contains javafx.controls as a transitive dependency so it may not be needed according to https://openjfx.io/javadoc/18/javafx.web/module-summary.html. Otherwise, https://openjfx.io/openjfx-docs/#maven may be a noteworthy guide.

JOOQ does not generating classes (JPADatabase)

I have a problem with JOOQ framework (3.13.5) along with Spring Boot and Java 8. I'm trying to generate domain classes following the instructions from the manual given on the author's page (link) using the GenerationTool from JOOQ, which is mentioned here. The project structure is presented below:
The domain package contains JPA entities. Then I've added run configuration, where as the main class I've marked the GenerationTool from JOOQ's library with argument: /jooq-config.xml (as mentioned in the author's manual linked above). The config file content is shown below:
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd">
<generator>
<database>
<name>org.jooq.meta.extensions.jpa.JPADatabase</name>
<properties>
<property>
<key>packages</key>
<value>com.ormtester.jpa.domain</value>
</property>
<property>
<key>useAttributeConverters</key>
<value>true</value>
</property>
<property>
<key>unqualifiedSchema</key>
<value>none</value>
</property>
<property>
<key>hibernate.physical_naming_strategy</key>
<value>org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy</value>
</property>
</properties>
</database>
</generator>
For the analyse issues I'm also adding the the fragment of pom.xml with lib's versions:
<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta-extensions</artifactId>
<version>3.13.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen</artifactId>
<version>3.13.5</version>
</dependency>
</dependencies>
And now when I'm trying to build the project, I'm getting the following error:
18:49:37.330 [main] WARN org.jooq.util.jaxb.tools.MiniJAXB - org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 72; cvc-elt.1: Cannot find the declaration of element 'configuration'.
18:49:42.215 [main] INFO org.jooq.codegen.GenerationTool - Initialising properties : /jooq-config.xml
18:49:43.134 [main] DEBUG org.jooq.codegen.GenerationTool - Input configuration : <onError>FAIL</onError><generator><name>org.jooq.codegen.DefaultGenerator</name><database><name>org.jooq.meta.extensions.jpa.JPADatabase</name><regexMatchesPartialQualification>true</regexMatchesPartialQualification><sqlMatchesPartialQualification>true</sqlMatchesPartialQualification><includes>.*</includes><excludes></excludes><includeExcludeColumns>false</includeExcludeColumns><includeTables>true</includeTables><includeEmbeddables>true</includeEmbeddables><includeRoutines>true</includeRoutines><includeTriggerRoutines>false</includeTriggerRoutines><includePackages>true</includePackages><includePackageRoutines>true</includePackageRoutines><includePackageUDTs>true</includePackageUDTs><includePackageConstants>true</includePackageConstants><includeUDTs>true</includeUDTs><includeSequences>true</includeSequences><includeIndexes>true</includeIndexes><includePrimaryKeys>true</includePrimaryKeys><includeUniqueKeys>true</includeUniqueKeys><includeForeignKeys>true</includeForeignKeys><includeCheckConstraints>true</includeCheckConstraints><includeInvisibleColumns>true</includeInvisibleColumns><recordVersionFields></recordVersionFields><recordTimestampFields></recordTimestampFields><syntheticIdentities></syntheticIdentities><syntheticPrimaryKeys></syntheticPrimaryKeys><overridePrimaryKeys></overridePrimaryKeys><dateAsTimestamp>false</dateAsTimestamp><ignoreProcedureReturnValues>false</ignoreProcedureReturnValues><unsignedTypes>true</unsignedTypes><integerDisplayWidths>true</integerDisplayWidths><inputCatalog></inputCatalog><outputCatalogToDefault>false</outputCatalogToDefault><inputSchema></inputSchema><outputSchemaToDefault>false</outputSchemaToDefault><schemaVersionProvider></schemaVersionProvider><catalogVersionProvider></catalogVersionProvider><orderProvider></orderProvider><forceIntegerTypesOnZeroScaleDecimals>true</forceIntegerTypesOnZeroScaleDecimals><logSlowQueriesAfterSeconds>5</logSlowQueriesAfterSeconds><logSlowResultsAfterSeconds>5</logSlowResultsAfterSeconds><properties><property><key>packages</key><value>com.ormtester.jpa.domain</value></property><property><key>useAttributeConverters</key><value>true</value></property><property><key>unqualifiedSchema</key><value>none</value></property><property><key>hibernate.physical_naming_strategy</key><value>org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy</value></property></properties></database></generator>
Exception in thread "main" java.lang.NoSuchMethodError: org.jooq.meta.jaxb.Configuration.getBasedir()Ljava/lang/String;
at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:272)
at org.jooq.codegen.GenerationTool.run(GenerationTool.java:225)
at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:220)
at org.jooq.codegen.GenerationTool.main(GenerationTool.java:192)
However when I will remove the jooq-config.xml file then the error is straigtly telling me that the configuration file cannot be found.
I tried to debug the GenerationTool methods but I cannot find the problematic place. I'm unable to designate the source of the problem, so I'll be grateful for every help from Yours side. Thanks in advance!
Spring boot pulls in a set of default jOOQ library versions, which you can verify using the instructions that you got in the comments (mostly mvn dependency:tree). The error you're getting hints at there being incompatible versions on your classpath.
If your own version differs from that pulled in by spring boot, you might need to tell spring boot not to pull in any jOOQ versions, and pull them all in yourself, e.g. using this approach documented in this blog post here
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jooq</artifactId>
<exclusions>
<exclusion>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
</exclusion>
</exclusions>
</dependency>
Ok, following the tips given by #Lukas and #Lesiak in this topic I have figured out the solution. As You can see in the initial pom's content I have added the jooq-codegen and jooq-meta-extensions keeping the versions 3.13.5 and I was sure that "under the hood" those depencies are holding the same versions of the jooq and jooq-meta libs but unfortunately there were 3.12.3 in both cases. So firstly I have checked the tips that came from #Lukas and then I had to exclude those libs from from the dependencies and add them as the separate dependencies using the right version numbers.
I'm also talking about the jooq (where the initial problem was only with jooq-meta) because after the problem with Configuration class has been resolved, I've faced similar problem with `org.jooq.SQLDialect, as following:
java.lang.NoSuchMethodError:
org.jooq.SQLDialect.supportedBy([Lorg/jooq/SQLDialect;)Ljava/util/Set;
at org.jooq.meta.AbstractDatabase.(AbstractDatabase.java:117)
at java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Class.java:264) at
org.jooq.codegen.GenerationTool.loadClass0(GenerationTool.java:983)
at org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:930)
at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:395) at
org.jooq.codegen.GenerationTool.run(GenerationTool.java:225) at
org.jooq.codegen.GenerationTool.generate(GenerationTool.java:220) at
org.jooq.codegen.GenerationTool.main(GenerationTool.java:192)
And as I said it also came with the version mismatch, in this case with jooq.
After all those changes my pom's content is:
<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.13.5</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta-extensions</artifactId>
<version>3.13.5</version>
<exclusions>
<exclusion>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
</exclusion>
<exclusion>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
<version>3.13.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen</artifactId>
<version>3.13.5</version>
<exclusions>
<exclusion>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
</exclusion>
<exclusion>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-tools</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
And here I can give You a small hint - if You have a tables named with pluralized form and You want fastly depluralize them to keep names of the generated classes singular, You have to add the last depencency from the pom's snippet, create Your own class that extends DefaultGeneratorStrategy and overvrite the getJavaClassName() method's body with the following fragment:
String javaClassName = super.getJavaClassName(definition, mode);
boolean hasRecordSuffix = javaClassName.contains("Record");
javaClassName = javaClassName.replace("Record", "");
String val = nameTools.depluralize(javaClassName);
if (hasRecordSuffix)
val += "Record";
return val;
Then simply add Your custom naming strategy to the xml config. Works like a charm, made using this project:
link
I'm really grateful to You, #Lukas and #Lesiak, thanks for this help!

Javax UriBuilder error [duplicate]

This question already has answers here:
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri
(8 answers)
Closed 3 years ago.
I am trying to build a REST webservice using an asynchronous response.
I have looked around this error on the web, however, none of the solutions have worked for me. I am not sure on how to go about it.
This is the code for the REST service, it has AsyncResponse, and #Suspended which are taken from jar file specified in the pom.xml, which I will provide below. The problem is, on deploying the war, I get an exception:
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:651)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.50 logs
My class is as follows:
package com.crudapp;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.annotation.Generated;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
//import javax.ws.rs.core.UriBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.google.gson.Gson;
import com.mysql.jdbc.StringUtils;
import dao.User;
import dao.UserDAO;
import dao.UserDAOImpl;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
#Path("/crudpath")
public class EntityResource {
private final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/spring.xml");
UserDAO userdao = null;
private final int numOfThreads = 10;
private final ExecutorService executorService = Executors.newFixedThreadPool(numOfThreads);
// userdao.getUsers("118");
//ctx.close();
#GET
#Produces("application/json")
public Response getTupleFromDBasJSON(#QueryParam("param1") String userid, #Suspended final AsyncResponse asyncresponse ){
if(StringUtils.isNullOrEmpty(userid))
throw new ServiceException("Userid passed to the REST service /crudpath is null or empty");
userdao = (userdao==null)?
ctx.getBean("userDAO", UserDAOImpl.class)
: userdao;
Gson gson = new Gson();
Future<List<User>> futures = executorService.submit(new DAOTaskHandlerThread(userid));
List <User> users = new ArrayList<User>();
if(futures.isDone())
{
try{
users = futures.get();
if(users!= null)
return Response.status(200).entity( gson.toJson(users).toString()).build();
}
catch(Exception ex)
{
throw new ServiceException(ex);
}
}
return Response.status(200).entity(new ArrayList<User>().toString()).build();
/*// crrate a new thread.. call the DAO .. returns the result from here.
JSONObject jsonObject = new JSONObject();
jsonObject.put("key", "value");
return Response.status(200).entity( jsonObject.toString()).build();*/
}
private class DAOTaskHandlerThread implements Callable<List<User>>{
//private UserDAO userDAO;
private String userid;
private DAOTaskHandlerThread(//UserDAO userDAO,
String useridpassed){
///this.userDAO= userDAO;
userid= useridpassed;
}
#Override
public List<User> call() throws Exception {
// TODO Auto-generated method stub
return userdao.getUsers(userid);
}
}
}
My pom.xml file for maven is as follow:
<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>RESTJerseyExample</groupId>
<artifactId>RESTJerseyExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- spring framework just added -->
<properties>
<java-version>1.7</java-version>
<org.springframework-version>4.0.3.RELEASE</org.springframework-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- spring framework just added ends here -->
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.0</version>
</dependency>
<!-- used for httpclient library -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.2</version>
</dependency>
<!-- for async response -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m12</version>
</dependency>
</dependencies>
</project>
AbstractMethodError are thrown when an application tries to call an abstract method.
uri is an abstract method in UriBuilder, so you need an implementation of this. This method (with String parameter) is from version 2.0 of JAX-RS specification.
You're trying to use JAX-RS 2.0 with Jersey 1.*. Instead, you need to use Jersey 2.* that implements JAX-RS 2.0 and contains an implementation to uri method.
In your pom.xml you may remove these dependencies:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m12</version>
</dependency>
And use these dependencies:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.17</version>
</dependency>
Using this, uri method is implemented in JerseyUriBuilder class from jersey-common.
EDIT:
You need to change, in your web.xml, servlet com.sun.jersey.spi.container.servlet.ServletContainer to org.glassfish.jersey.servlet.ServletContainer and init-param from com.sun.jersey.config.property.packages to jersey.config.server.provider.packages
I would like to add one answer to this post. I faced a similar problem today and found the root cause to be another dependent jar which was Internally using an older version of Jersey/JAX-RS.
My POM before fix was:
<jersey.version>2.17</jersey.version>
...
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.ci.wrapper</groupId>
<artifactId>client-wrapper</artifactId>
<version>${clients-wrapper.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.api.commons</groupId>
<artifactId>transferobjects</artifactId>
<version>3.0.2</version>
</dependency>
The problem was with "com.ci.wrapper" and "com.api.commons".
They inturn included 2 different JAR's of BraveJersey and org.apache.cxf.cxf-rt-frontend-jaxrs (2.5.1) which were using Jersey and JAX-RS 1.X versions.
After excluding the nested jar's and adding the newer version's of BraveJersey2/org.apache.cxf.cxf-rt-frontend-jaxrs(3.1.5) it got resolved.
<dependency>
<groupId>com.api.commons</groupId>
<artifactId>transferobjects</artifactId>
<version>3.0.2</version>
<exclusions>
<exclusion>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<groupId>org.apache.cxf</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>com.ci.wrapper</groupId>
<artifactId>client-wrapper</artifactId>
<version>${clients-wrapper.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<artifactId>brave-jersey</artifactId>
<groupId>com.github.kristofa</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.kristofa</groupId>
<artifactId>brave-jersey2</artifactId>
<version>2.4.2</version>
</dependency>
In case you're facing a similar issue, please check if the project's or jar's included could be using an incompatible version of Jersey/Jax-RS.
In my case it's combination of both cxf-rt-frontend-jaxrs and httpclint jar needed to be removed to resolve the issue. Both of these jars have the class javax.ws.rs.core.UriBuilder, the multiple version of this class caused the issue.
My pom had a transitive dependency on both these jars, after removing it worked.
enter code here
<exclusion>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
I have faced this problem when I was trying to use a library (custom built) in one of my project.
So the problem was happening due to mismatch in the com.sun.jersey dependencies. My project was using jersey version 2.15 whereas the custom library was giving me com.sun.jersey transitively of version 1.17.
So how to find such problems.
Use gradle dependencies task to find out the dependencies (it gives nested level results which means all the transitive dependencies will also be shown)
Once you identify the problem causing dependencies. Exclude them while adding the required dependencies in the project.
For e.g.
httpRestClient is name of my custom library which I wanted to use in my project.
So here is how I have added the dependency and at the same time excluded the conflicting dependencies of group 'com.sun.jersey'
compile(httpRestClient) {
exclude group: 'com.sun.jersey'
}
This way you can use whatever library and exclude the conflicting libraries.
Thanks.
In our case culprit was this dependency
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-common</artifactId>
<version>1.0-incubating</version>
</dependency>

log4j.properties being ignored

I have a Java EE 6 Wicket application deployed with maven using IntelliJ IDEA 9.0.3 on glassfish v3.0.1. I use slf4j-log4j12-1.5.6 with slf4j-api-1.5.8 and log4j-1.2.16 for logging.
It was previously working fine when I deployed through netbeans or eclipse, however when I deploy with IntelliJ IDEA my log4j.properties file is ignored and glassfish's logging handles my log messages. I do not think IDEA has anything to do with it, something else must have changed I just can't figure out what.
I have verified that my log4j.properties file is in my WEB-INF/classes directory and the slf4j/log4j jars are in the WEB-INF/lib directory of my war. Is there some sort of configuration I am missing to make this work?
thanks.
edit: Updated with more info, posted pom dependencies.
Here is the relevant section from my pom.xml:
<!-- Guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r05</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<!-- Java EE 6 -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>bean-validator</artifactId>
<version>3.0-JBoss-4.0.0.Beta3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<!-- Wicket -->
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-auth-roles</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-wicket</artifactId>
<version>1.0.1-Final</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.5.1-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.1-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.5.1-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>3.5.1-Final</version>
</dependency>
<!-- Database -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.4-701.jdbc4</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
Update: I tried to reproduce the issue. I created a simple Wicket project (same version as you):
mvn archetype:create \
-DarchetypeGroupId=org.apache.wicket \
-DarchetypeArtifactId=wicket-archetype-quickstart \
-DarchetypeVersion=1.4.9 \
-DgroupId=com.mycompany \
-DartifactId=my-wicketapp
Which has a simple log4j.properties logging to the standard output.
log4j.appender.Stdout=org.apache.log4j.ConsoleAppender
log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.Stdout.layout.conversionPattern=%-5p - %-26.26c{1} - %m\n
log4j.rootLogger=INFO,Stdout
log4j.logger.org.apache.wicket=INFO
log4j.logger.org.apache.wicket.protocol.http.HttpSessionStore=INFO
log4j.logger.org.apache.wicket.version=INFO
log4j.logger.org.apache.wicket.RequestCycle=INFO
Then:
I added all your dependencies (or modified the versions of existing one to match yours)
I just did some cleanup e.g. in the Hibernate dependencies, you don't need to declare them all, leverage the transitive dependencies mechanism
I added relevant repositories and pluginRepositories
I added glassfish's javax.servlet dependency to make the build pass
I added the embedded-glassfish plugin to test the whole thing
I made a few other unrelated changes
I changed the compiler settings to 1.6
I declared slf4j-api in the dependencyManagement element to control nicely the version in transitive dependencies.
The full pom.xml looks like this (so anybody can reproduce):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>my-wicketapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<!-- TODO project name -->
<name>quickstart</name>
<description/>
<!--
TODO <organization> <name>company name</name> <url>company url</url>
</organization>
-->
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<repositories>
<!-- For Hibernate Artifacts -->
<repository>
<id>repository.jboss.org-public</id>
<name>JBoss repository</name>
<url>https://repository.jboss.org/nexus/content/groups/public</url>
</repository>
<!-- repository for Java EE 6 Binaries -->
<repository>
<id>java.net2</id>
<name>Repository hosting the jee6 artifacts</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<pluginRepositories>
<!-- GlassFish repository for the embedded-glassfish plugin -->
<pluginRepository>
<id>glassfish</id>
<name>GlassFish Maven 2 Repository</name>
<url>http://download.java.net/maven/glassfish</url>
</pluginRepository>
</pluginRepositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.5.5-Final</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r05</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>bean-validator</artifactId>
<version>3.0-JBoss-4.0.0.Beta3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<!-- WICKET DEPENDENCIES -->
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-auth-roles</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-wicket</artifactId>
<version>1.0.1-Final</version>
</dependency>
<!--
OPTIONAL <dependency> <groupId>org.apache.wicket</groupId>
<artifactId>wicket-extensions</artifactId>
<version>${wicket.version}</version> </dependency>
-->
<!-- LOGGING DEPENDENCIES - LOG4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<!-- JUNIT DEPENDENCY FOR TESTING -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<!-- GLASSFISH EMBEDDED FOR TESTING -->
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
<!-- JETTY DEPENDENCIES FOR TESTING -->
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-management</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<filtering>false</filtering>
<directory>src/test/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<optimize>true</optimize>
<debug>true</debug>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
</configuration>
</plugin>
<plugin>
<groupId>org.glassfish</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<serverID>server</serverID>
<name>server</name>
<app>${project.build.directory}/${project.build.finalName}.war</app>
<port>8080</port>
<instanceRoot>${project.build.directory}/gfe-${maven.build.timestamp}</instanceRoot>
<!--contextRoot>${build.finalName}</contextRoot-->
<autoDelete>true</autoDelete>
<!--configFile>${basedir}/domain.xml</configFile-->
</configuration>
</plugin>
</plugins>
</build>
<properties>
<wicket.version>1.4.9</wicket.version>
<jetty.version>6.1.4</jetty.version>
<slf4j.version>1.5.6</slf4j.version>
</properties>
</project>
And when I run the project with the embedded-glassfish plugin:
$ mvn package
...
$ mvn embedded-glassfish:run
...
and access http://localhost:8080/server in a browser, I get my logs in the standard output as expected:
...
INFO: [WicketApplication] Started Wicket version 1.4.9 in development mode
********************************************************************
*** WARNING: Wicket is running in DEVELOPMENT mode. ***
*** ^^^^^^^^^^^ ***
*** Do NOT deploy to your live server(s) without changing this. ***
*** See Application#getConfigurationType() for more information. ***
********************************************************************
I wonder if this is representative or not.
I have checked the war, log4j.properties is indeed in WEB-INF/classes. I don't have a log4j.jar, i have slf4j-log4j12.jar.
slf4j-log4j12.jar is not a replacement for log4j.jar, slf4j-log4j12.jar is a binding for log4J version 1.2, you still need log4j.jar. From the SLF4J documentation:
Binding with a logging framework at deployment time
As mentioned previously, SLF4J
supports various logging frameworks.
The SLF4J distribution ships with
several jar files referred to as
"SLF4J bindings", with each binding
corresponding to a supported
framework.
slf4j-log4j12-1.6.1.jar: Binding for
log4j version 1.2, a widely used
logging framework. You also need to
place log4j.jar on your class path.
I wonder how you got this working under NetBeans and Eclipse.
I had the exact same problem.
Log4j alone works great:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
But if I try to use Slf4j over it, then my "src/resources/log4j.properties" file is not found anymore, even if Maven add it to a directory that is on the classpath.
So, this doesn't work out of the box:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
To make it work, you have to explicitly add the "log4j.properties" to the classpath or tell the server where to find it! A way to achieve this is (this example is on Windows):
-Dlog4j.configuration=file:C:\[pathToYourProject]\trunk\target\classes\log4j.properties
In Eclipse (if this is what you use), you can add the same line to your Run Configuration / VM arguments.
I suggest removing all the slf4j dependencies and change your logging code to use the Log4j API directly (if this is not too much work, don't know the size of your project). Once this works, consider if you really need the flexibility offered by slf4j. If you do, pick up the correct version of slf4j (slf4j-log4j12 might not be the correct one to use for log4j 1.2.16) and integrate it back in.
I encountered slf4j recently, and in the end removed it altogether because I ran into similar configuration problems.
I had the same problems. The solution is simple - all logging dependencies should be before the glassfish on the classpath.
Note that older Maven2 versions have some problems with the classpath consistency. I use 2.2.1 which have this issue fixed (it was fixed in 2.0.9, I think).
Have a look at the log4j manual. The section "Default Initialization Procedure" describes how log4j will try to find the initialization file. Maybe you can try some of this options to get things work.
The two most likely things that spring to mind are:
make sure the log4j.properties file is in WEB-INF/classes of the deployment. I assume you mean it is in your WEB-INF/classes in your codebase, but have you confirmed this is the case in the war that sent to glassfish
make sure your log4j.jar is in your deployed WEB-INF/lib
Since it's working in some deployment scenarios, I suspect your war packaging when running via Maven is the problem. The above points should help you confirm this.
I have the following logging dependencies :
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>runtime</scope>
</dependency>
under /src/main/resources/ i have a logback.xml defining the various aspects (appenders,..). This gets picked up by maven and copied to WEB-INF/classes
hope that helped
I would support Adriaan Koster's answer. If your pure log4j doesn't work however, try the following. Create simple class like this
import org.apache.log4j.Logger;
public class LogTest {
private static Logger log;
public static void main(String[] args) {
log = Logger.getLogger(LogTest.class);
}
}
...and put breakpoint in org.apache.log4j.helpers.Loader#getResource method. It tries to pull log4j.xml from classloader:
url = classLoader.getResource(resource);
So you can easily look inside the classloader and see what paths it uses (and why it can't find your log4j.xml).
It is also very important that log4j library was compiled after all modules of the libraries used in the project. If you will not set it as last object, the logs from later modules/libraries wouldn't be displayed in a standard way for log4j.properties.
For people using spring boot:
It appears to ignore -Dlog4j.configuration=file:... You can instead use -Dlogging.config=file:/etc/myconfig/log4j.xml. It must be xml format.
You can also edit the file logback-spring.xml in your java source dir eg src/main/resources/. This is the standard place for the default logging config.
A good source of further information: https://www.baeldung.com/spring-boot-logging
What worked for me: Adding log4j2.properties (or log4j2.xml) to my class path root (tomcat/webapps/ROOT/WEB-INF/classes/). Parameter-value logging is now enabled.
Background: I noticed log4j 1, 2 and slf4j jars in my build. We have slf4j imports in many java files. hibernate.properties was being used and hibernate.show_sql=true worked but I could not enable parameter-value logging. My log4j.properties in the classpath root was being ignored - when the mvn packaged war was run in tomcat. But when I ran it from eclipse, log4j.properties worked and I could enable parameter-value logging.
log4j2.properties used:
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = STDOUT
logger.hibernate.name=org.hibernate.SQL
logger.hibernate.level=debug
logger.hibernate-type.name=org.hibernate.type
logger.hibernate-type.level=trace
Based on: https://www.codejava.net/frameworks/hibernate/how-to-configure-hibernate-logging-with-log4j2
Search for log4j/slf4j: find /usr/local/tomcat/webapps/ROOT -name '*slf4j*' -o -name '*log4j*'

Categories

Resources