Unable to configure logging in dropwizard. Could not resolve type id 'console' - gradle

I am trying to configure console appender in my project. It works fine when I launch my app in debug locally. However, when I build it my jar in Gradle and launch it as a standalone app I get following error:
[0]; Could not resolve type id 'console' into a subtype of [simple type, class io.dropwizard.logging.AppenderFactory]: known type ids = [AppenderFactory]
Here is the snippet of my .yml file:
logging:
appenders:
- type: console
timeZone: UTC
logFormat: '%-5level [%date{ISO8601}] [%X{requestId}] %c: %msg%n%rootException'
I was able to find posts about similar issues. For instance, this thread here suggests to check if file META-INF/services/io.dropwizard.logging.AppenderFactory is in the application jar and if it contents is as following:
io.dropwizard.logging.ConsoleAppenderFactory
io.dropwizard.logging.FileAppenderFactory
io.dropwizard.logging.SyslogAppenderFactory
I have verified it. In my case file is where it supposed to be and it has exactly the same contents.
Any help will be greatly appreciated.
Dropwizard version 0.9.2

Does the Gradle produce a Uber/Fat Jar (A jar with all it's dependencies inside itself) or a simple jar with only your Dropwizard app?
It's advisable to build an Fat-jar for Dropwizard deployments, so do switch over to this style if you're not doing so.
Now while building a Fat-Jar, you need to do the following to solve your problem (this was mentioned in the discussion you linked)
If you use maven-shade plugin for building a fat jar, don't forget about SPI resource transformer for collecting SPI resources into the jar.
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
To do the same in Gradle, check this discussion.
HTH.

Related

Quarkus xml Parser DocumentBuilderFactory cannot be found, but only when using quarkus-run.jar

When packaging our app with mvn package everything works fine. Then when we start our app with java -jar target\quarkus-app\quarkus-run.jar the app silently crashes. While debugging we found that it crashes while parsing an xml InputStream. It happens while initialising some classes.
This is the stacktrace that we had to dig out ourselves:
Exception occurred in target VM: Provider for javax.xml.parsers.DocumentBuilderFactory cannot be found
javax.xml.parsers.FactoryConfigurationError: Provider for javax.xml.parsers.DocumentBuilderFactory cannot be found
at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
at org.optaplanner.core.impl.io.jaxb.GenericJaxbIO.parseXml(GenericJaxbIO.java:209)
at org.optaplanner.core.impl.io.jaxb.SolverConfigIO.read(SolverConfigIO.java:15)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlReader(SolverConfig.java:199)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlInputStream(SolverConfig.java:173)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlInputStream(SolverConfig.java:160)
When packaging the app in an uberjar this problem does not occur. Same when using dev.
We use graalvm-ce-java17-22.2.0, together with the 2.11.2.Final version of quarkus and the 8.29.0.Final version of optaplanner.
We tried to verify that there aren't any xml exclusion in the dependencies. Also we checked if quarkus and the quarkus maven-compiler-plugin are of the same version. Also we looked into the compiled jarfiles, if the xml we want to read is present. If it wouldn't be present, the code would crash even earlier. The class javax.xml.parsers.DocumentBuilderFactory is not listed in the quarkus-app-dependencies.txt
Adding the quarkus-optaplanner extension helped to identify the logger issue. So the problem with the silent crash is resolved. Adding quarkus-jaxp to the dependencies gets rid of the FactoryConfigurationError and everything works as expected.

Spring Application won't start: jaxb-impl-2.2.3-1.jar referenced one or more files that do not exist:

I'm stuck behind this error in IDEA. I was working as usual debugging some classes and everything was working just fine. But at a given moment my spring application stopped initializing and this line appear on the console every time now, and the application remains in a infinite loop, trying to initialize:
The Class-Path manifest attribute in /home/user/maven/repository/com/sun/xml/bind/jaxb-impl/2.2.3-1/jaxb-impl-2.2.3-1.jar referenced one or more files that do not exist: file:/home/user/maven/repository/com/sun/xml/bind/jaxb-impl/2.2.3-1/jaxb-api.jar,file:/home/user/maven/repository/com/sun/xml/bind/jaxb-impl/2.2.3-1/activation.jar,file:/home/user/maven/repository/com/sun/xml/bind/jaxb-impl/2.2.3/jsr173_1.0_api.jar,file:/home/user/maven/repository/com/sun/xml/bind/jaxb-impl/2.2.3-1/jaxb1-impl.jar
And these lines :
project: 1.1.0-iron-man-SNAPSHOT
Spring Boot version: (v1.5.10.RELEASE)
Java Version: 1.8.0_141
Source Encoding: UTF-8
turned out to this:
project: #project.version#
Spring Boot version: (v1.5.10.RELEASE)
Java Version: #java.version#
Source Encoding: #project.build.sourceEncoding#
I'm didn't change any config files in the project.
I have tried mvn clean install.
I have tried to force IDEA to read the maven dependecies again.
None of them have worked.
Maybe File -> Invalidate Caches / Restart helps
First Picture MANIFEST.MF defines the classpath
But they are stored in different maven repository forlders

Springboot Strange Resource Loading Behavior

I'm working on a springboot 1.5.1 application that I'm trying to load a WSDL included in my resources directory in the wsdl directory. Depending on where my application executes I'm getting different results (command line, intellij, cloud foundry) and I can't seem to get all three to work at the same time.
I've tried several ways of locating the resource:
From prior to the migration to springboot we had this (worked in IntelliJ but not java -jar myboot.jar):
this.getClass().getResource("/wsdl/my.wsdl");
I switched it to the typically more correct version and got it to work in IntelliJ and java -jar but not Cloud Foundry:
this.getClass().getClassLoader().getResource("/wsdl/my.wsdl");
I switched it to use the Spring Resource Loader version and it worked in IntelliJ and CloudFoundry but not java -jar:
#Value("classpath:/wsdl/my.wsdl")
private Resource wsdlResource;
wsdlResource.getURL();
On the command line what I've noticed is that it seems to be thinking that BOOT-INF/classes is a JAR file (Note the ! after classes):
Caused by: javax.xml.ws.WebServiceException: Failed to access the WSDL at: jar:file:/C:/dev/redacted/build/libs/redacted.jar!/BOOT-INF/classes!/wsdl/my.wsdl. It failed with:
JAR entry BOOT-INF/classes!/wsdl/my.wsdl not found in C:\dev\redacted\build\libs\redacted.jar.
From looking at IntelliJ's URL, it's referring to the actual source folder which explains why it seems to always work.
What is causing this and how might I universally load these class path resources successfully with springboot?

core nlp truecaseannotator not found

I just got started with CoreNLP version 3.6.0. I've downloaded this version from this website. Using the commandline pipeline, I've been able to perform the standard pipeline annotators but ran into a problem with the truecase annotator:
Here's a copy of the terminal output:
loadClassifier=edu/stanford/nlp/models/truecase/truecasing.fast.caseless.qn.ser.gz
mixedCaseMapFile=edu/stanford/nlp/models/truecase/MixDisambiguation.list
classBias=INIT_UPPER:-0.7,UPPER:-0.7,O:0
Exception in thread "main" edu.stanford.nlp.io.RuntimeIOException: java.io.IOException: Unable to open "edu/stanford/nlp/models/truecase/truecasing.fast.caseless.qn.ser.gz" as class path, filename or URL
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifierNoExceptions(AbstractSequenceClassifier.java:1499)
at edu.stanford.nlp.pipeline.TrueCaseAnnotator.(TrueCaseAnnotator.java:58)
at edu.stanford.nlp.pipeline.AnnotatorImplementations.trueCase(AnnotatorImplementations.java:199)
at edu.stanford.nlp.pipeline.AnnotatorFactories$10.create(AnnotatorFactories.java:435)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:85)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:375)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.(StanfordCoreNLP.java:139)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.(StanfordCoreNLP.java:135)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.main(StanfordCoreNLP.java:1222)
Any ideas?
We tried to make the default models jar a bit smaller and decided to not include this model by default. But it is still contained in the English models jar which you can download from release history page.
After you downloaded the jar, make sure to put it in your classpath before you run CoreNLP. The English models jar should also contain everything in stanford-corenlp-3.6.0-models.jar, so you won't need both of them in your classpath.

Custom Mediator ClassNotFoundException TransactionSynchronization

I make a custom mediator class that used spring jdbc to access data from database. I make a jar from that class and deploy it in WSO2_HOME/repository/components/lib. After that I add the following jar to the same folder : spring-jdbc.jar, spring-tx.jar. But when I tried the custom mediator there is an error "ClassNotFoundException org\springframework\transaction\support\TransactionSynchronization". The problem is I'm pretty sure that "TransactionSynchronization" class is available in the spring-tx.jar. Can anyone help me to solve this problem? :)
One reason may be there are two packages in your class path which has the same 'TransactionSynchronization' class. Can you try the below.
What do you have in your WSO2_HOME/repository/components/dropins directory? Delete all jars inside dropins and restart the server and recheck for the issue.
If the error is still there try deleting spring-tx.jar from WSO2_HOME/repository/components/lib & WSO2_HOME/repository/components/dropins. Then restat the server. Then check whether you are getting the same error or different error?
I am experiencing the same behavior. I have a custom spring mediator that calls out to a database for role based authNZ. I am running esb v 4.7.0.
I downloaded spring-tx-3.1.0.RELEASE.jar from the maven repository and copied it to /usr/local/wso2/wso2esb-4.7.0/repository/components/lib in my environment, then restarted the ESB. When I issue requests to my proxy service, the same class not found exception occurs.
I was examining jar contents today and when I checked the spring-tx jar in /usr/local/wso2/wso2esb-4.7.0/repository/components/lib, the class in present:
jar tf spring-tx-3.1.0.RELEASE.jar | grep TransactionSynchronization
org/springframework/transaction/support/TransactionSynchronization.class
When I do the same in /usr/local/wso2/wso2esb-4.7.0/repository/components/dropins after restart of the esb, the class is not present:
jar tf ../dropins/spring_tx_3.1.0.RELEASE_1.0.0.jar
spring-tx-3.1.0.RELEASE.jar
META-INF/
META-INF/p2.inf
META-INF/MANIFEST.MF
Notice that the spring-tx jar is not included in the OSGi bundle after restart of Synapse.
I will investigate further tomorrow, including building an OSGi bundle that contains the Spring dependencies I need via Eclipse

Resources