Sunday, April 14, 2024

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

 

>PROBLEM

Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below:


package Test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Test {

    private static final Logger LOGGER = LoggerFactory.getLogger(Test.class);

    public static void main(String[] args) {

        LOGGER.info("done");

    }

}


Unfortunately, it fails to return the following message:

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.

or:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder



>SOLUTION


1. Check your slf4j jars.

First, make sure that you have the correct dependency jars.

For instance:

  slf4j-api-2.0.13.jar
  slf4j-simple-2.0.13.jar


More information:

https://www.slf4j.org/codes.html#StaticLoggerBinder

https://www.slf4j.org/faq.html#changesInVersion200


2. Check the Eclipse's ".classpath" file.

Edit it to find if there is some inconsistency with your lib, like references that differ in content.
It is rare but it may happen.

Make a copy of it (backup).
Edit it, and try to find old references to other conflicting jars.
Example of old entry not automatically removed by Eclipse:

    <classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>

You also may get the ".classpath" from another and similar project that works well, remove the unnecessary entries and insert the missing ones.

On Eclipse, close the project that you are fixing, replace it with the new ".classpath" file, and reopen the project.

Test it again.


3. Check the project libs searching for one that already provides the slf4j.

If a lib already contains the slf4j, its version may conflict with the slf4j's jars.

A simple way to check if the project has a lib that already contains slf4j is to remove the explicit slf4j jars from the project.

If the "import" to slf4j still works, not alarming that it misses the slf4j lib, then one of your jars is offering it.


For instance, the "apacheds-all" lib (apacheds-all-1.5.5.jar, apacheds-all-2.0.0.AM27.jar).

By the way...

"ApacheDS is an embeddable directory server entirely written in Java, which has been certified LDAPv3 compatible by the Open Group. Besides LDAP it supports Kerberos 5 and the Change Password Protocol. It has been designed to introduce triggers, stored procedures, queues and views to the world of LDAP which has lacked these rich constructs."

To discover which lib already contains the slf4j lib, you may create another project without lib (empty). The project will have just one class that uses slf4j like the example above (Test class).

Delete the jar files, all of them.
Update the project and check if the import is not working.
OK, if not, the test is successful.

Now add some jars and update the project.
Check again if the import is not resolving.
If it is, good! It means that there isn't a lib offering the slf4j.
Repeat this cycle adding other libs until the import is resolved.
There you go! Isolate the jar file that resolves the slf4j import and you have discovered the conflict.


>ENV

java
eclipse


Monday, April 1, 2024

java: spring boot/spring/mongodb: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class



>PROBLEM


Attempt to save an instance on MongoDB database fails returning:

  org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class ...

  

  or for this example:

  org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.drillback.ws5.model.mongodb.MongoTest.


- other possible error messages:

custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.] with root cause 
org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is DOCUMENT.


or yet:

Failed to decode 'MongoInfo'. Decoding 'references' errored with: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is DOCUMENT.
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.] with root cause
org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is DOCUMENT.


>SOLUTION


Follow the example below, check:

1. The java class has the @Document annotaion.

2. Just one constructor must have @BsonCreator annotation, with all fields.


>Java class example

@Document

//@Document(collection = "test")

public class MongoTest {


// @Id, or @BsonId

@BsonId

@BsonProperty("_id") public BsonObjectId id = null;

@BsonProperty("title") public String title = "";

@BsonProperty("regdate") public Date regdate = new Date();


@BsonCreator

public MongoTest(

@BsonProperty("_id") BsonObjectId id,

@BsonProperty("title") String title,

@BsonProperty("regdate") Date regdate

) {

this.id = id;

this.title = title;

this.regdate = regdate;

}



>ENV

Spring Boot (spring)

MongoDB

Java 17




Tuesday, January 16, 2024

virtualbox6: debian: netbeans install issues: "dpkg: warning: 'ldconfig' not found in PATH or not executable" and "pkg-deb: error: archive 'apache-netbeans_....deb' uses unknown compression for member 'control.tar.zst', giving up"

 

>PROBLEMS/SOLUTIONS


You desire to install Netbeans on a Debian O.S. using the VirtualBox v.6 because the VirtualBox v.7 fails on your current Windows 10 installation.

The first task is to download the Netbeans, and we usually do this using the last version, trying the following commands to install:

sudo apt install openjdk-17-jdk curl wget unzip
cd /home/USERNAME/Downloads
chmod 777 apache-netbeans_20-1_all.deb
dpkg -i apache-netbeans_20-1_all.deb

>PROBLEM #1

Then, the "dpkg" command throws the following error message:

dpkg: warning: 'ldconfig' not found in PATH or not executable
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable
dpkg: error: 2 expected programs not found in PATH or not executable


>SOLUTION #1

scite /etc/profile &
export PATH=$PATH:/sbin

or

scite ~/.profile
export PATH=$PATH:/sbin

- Reboot and run dpkg command again, and you may get the problem #2.

>PROBLEM #2

Running the install command again:

dpkg -i apache-netbeans_20-1_all.deb


Returns:

pkg-deb: error: archive 'apache-netbeans_20-1_all.deb' uses unknown compression for member 'control.tar.zst', giving up
dpkg: error processing archive apache-netbeans_20-1_all.deb (--install):
 dpkg-deb --control subprocess returned error exit status 2



>SOLUTION #2

Remembering that VirtualBox v.6 is no longer maintained, we need to consider a possible downgrade.
If the last Netbeans version fails with the following procedure, download a previous version, until you get compatibility. In this procedure the attempt with the v.19 was enough.

Download the Netbeans , first apply alien command to make it compatible, then run dpkg as follow:

alien apache-netbeans_19-1_all.deb
dpkg -i apache-netbeans_19-1_all.deb

And... voilĂ !

Now, read to run Netbeans, and  on prompt do:

netbeans &

Note: if everything goes well, the installation set the netbeans command at:

/usr/bin/netbeans &


>ENV

Windows 10
VirtualBox 6
debian 10..12
netbeans 19..20

Tuesday, January 2, 2024

oracle: SQL Error: ORA-01861: literal does not match format string , 01861. 00000 - "literal does not match format string"


 >PROBLEM


The attempt to insert data from a migrated code from PostgreSQL to on a Oracle database using automatic generator resulted a generic message error.


- The insert command:

INSERT INTO loc_users( loc_users_id, nome, login, email, senha, nascimento, celular, idioma, ativo ) VALUES ( 1, 'Yuzefo', 'Abibeh', 'william@copel.com.br', 'Apukoyal', '1951-08-31', '05292770147', 'english', 1);



- Oracle returns a generic message not providing a tip to a specific field:


SQL Error: ORA-01861: literal does not match format string

01861. 00000 -  "literal does not match format string"

*Cause:    Literals in the input must be the same length as literals in

           the format string (with the exception of leading whitespace).  If the

           "FX" modifier has been toggled on, the literal must match exactly,

           with no extra whitespace.

*Action:   Correct the format string to match the literal.


>SOLUTION


Check your DDL comparing with the insert statement.

Usually operations involving date, time and timestamp cause issues during migration.

In this example, the field "nascimento" (born date in portuguese) has an incompatible format for date as concerns Oracle's usage.


Set TO_DATE() function:

TO_DATE('1951-08-31', 'YYYY-MM-DD')


INSERT INTO loc_users( loc_users_id, nome, login, email, senha, nascimento, celular, idioma, ativo ) VALUES ( 1, 'Yuzefo', 'Abibeh', 'william@copel.com.br', 'Apukoyal', TO_DATE('1951-08-31', 'YYYY-MM-DD'), '05292770147', 'english', 1);



>ENV

oracle 11g


Monday, January 1, 2024

oracle: timestamp ORA-01882: timezone region not found

 

>PROBLEM


Attempt to insert data using sqlplus (command console) into a table having TIMESTAMP type fails, returning error message.

SQL>INSERT INTO card( id, title, content, cardsz, colors, created_at, updated_at ) VALUES ( 1, 'test1 modified', 'hello world!\n', '', 'yellow', TIMESTAMP '2021-11-27 02:41:25 PM', TIMESTAMP '2022-06-01 09:56:56 PM');

- Output:
ERROR at line 1:
ORA-01882: timezone region not found


The target table configuration:

desc card;

ID NUMBER(10,0) No 1
TITLE VARCHAR2(255 BYTE) Yes 2
CONTENT CLOB Yes 3
CARDSZ VARCHAR2(16 BYTE) Yes 4
COLORS VARCHAR2(32 BYTE) Yes 5
CREATED_AT TIMESTAMP(6) No CURRENT_TIMESTAMP 6
UPDATED_AT TIMESTAMP(6) Yes "CURRENT_TIMESTAMP " 7


>SOLUTION


The issue was caused due a notation difference between the timestamp format migrated from a PostgreSQL dump, that uses the "AM|PM" and no reference to timezone (i.e. -03:00) values.

In the example given, the issue was solved just replacing the "PM" with the timezone value (-03:00) string from the timestamp, as follows:

INSERT INTO card( id, title, content, cardsz, colors, created_at, updated_at ) VALUES ( 1, 'test1 modified', 'hello world!\n', '', 'yellow', TIMESTAMP '2021-11-27 02:41:25 -03:00', TIMESTAMP '2022-06-01 09:56:56 -03:00');


>ENV


oracle 11g
sqlplus


eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...