Suddenly the git push via SSH failed, and the remote server returned something like invalid format for the public key id_rsa.pub? Terminal git push Load key "/Users/username/.ssh/id_rsa.pub": invalid format [email protected]: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Last week, […]

Read more SSH – Load key “/Users/username/.ssh/id_rsa.pub”: invalid format

git clone one of my existing repo (with SSH key added in the Github), modified some files and tried to git push, and it keeps asking for username and password for git push operation? Terminal git push Username for ‘https://github.com’: Password for ‘https://github.com’: GitHub authentication is successful. Terminal ssh -T [email protected] Hi mkyong! You’ve successfully […]

Read more GitHub keep asking for username password when git push

In JAX-RS, we can use response.readEntity(String.class) to read the response body from a post request. import jakarta.ws.rs.core.Response; Response response = //… // read response body String body = response.readEntity(String.class); P.S Tested with Jersey 3.x 1. Problem Below is a JAX-RS POST request endpoint to accept a JSON input and return a JSON response. // POST, […]

Read more JAX-RS – How to read response body from a post request?

This article shows how to fix VirtualBox 6.1.* running slow on macOS, MacBook Pro with retina display. Tested with VirtualBox 6.1.22 macOS Big Sur 11.1 MacBook Pro (16-inch, 2019) Kali Linux, Ubuntu, Debian 1. VirtualBox with more memory, CPU, etc In VirtualBox, clicks on the Settings icon. 1.1 Increase based memory. 1.2 Increase CPU processors. […]

Read more VirtualBox running slow and lag on macOS, MacBook Pro

A git pull and hits the below "reference broken" error message? Terminal $ git pull error: cannot lock ref ‘refs/remotes/origin/master’: unable to resolve reference ‘refs/remotes/origin/master’: reference broken From bitbucket.org:xx/mkyong-tutorials ! [new branch] master -> origin/master (unable to update local ref) Solution Unsure the root cause of the "reference broken". To fix it, delete this file […]

Read more Git – Unable to resolve reference ‘refs/remotes/origin/master’: reference broken

This tutorial shows logging in Java application using the tinylog lightweight logging framework. Table of contents 1. tinylog Dependency 2. tinylog Hello World 3. tinylog Logging Levels 4. Logs with the arguments 5. tinylog.properties 6. tinylog.configuration 7. Send logs to a file 8. Send logs to Console and file 9. Rolling File 10. Tags 11. […]

Read more tinylog Tutorial

This tutorial shows logging using the Java built-in logging APIs in the java.util.logging package. Table of contents 1. Java Logging APIs Hello World 2. Logging Levels 3. logging.properties 4. java.util.logging.config.file 5. Why choose java.util.logging 6. Download Source Code 7. References P.S The java.util.logging is bundled with the Java since JDK 1.4. 1. Java Logging APIs […]

Read more Java Logging APIs Tutorial

Starts a Java project and hits the below "class not found for com.sun.xml.bind.v2.ContextFactory"? Terminal Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at jakarta.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92) at jakarta.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125) at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:230) … 43 more Solution The com.sun.xml.bind.v2.ContextFactory is under the JAXB APIs; Java 9 deprecated the JAXB, and Java 11 deleted the JAXB completely. To fix […]

Read more java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory

Migrate a Java project to Java 11 and hits the below "class not found error for JAXBException" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException A short history of JAXB on Java The Jakarta XML Binding (JAXB; formerly Java Architecture for XML Binding) is an XML binding framework to convert Java classes to and from XML. The JAXB is part of […]

Read more java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

The Java logging APIs (java.util.logging) default loads logging.properties in the $JAVA_HOME/jre/lib/ (Java 8 and before); for Java 9 and above, the logging.properties file moved to $JAVA_HOME/conf. Note Java Logging APIs Tutorial logging.properties Here is the logging.properties file from Java 11. C:\opt\jdk-11.0.1\conf ############################################################ # Default Logging Configuration File # # You can use a different file […]

Read more logging.properties example

This article shows how to use HK2 dependency injection framework in Jersey and enable auto-scanning auto-discovery of the declared @Contract and @Service components. Table of contents 1. Jersey and HK2 dependency injection 2. @Contract, @Service, and @Inject 3. HK2 manual register @Contract and @Service 4. HK2 auto scanning @Contract and @Service 4.1 HK2 inhabitant files […]

Read more Jersey and HK2 dependency injection (auto scanning)

Using Jersey 3x + Jetty to develop endpoints, but hits the jakarta.activation.DataSource warning during application startup? Terminal SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details. May 27, 2021 10:09:48 AM org.glassfish.jersey.message.internal.MessagingBinders$EnabledProvidersBinder bindToBinder WARNING: A class jakarta.activation.DataSource for a default provider MessageBodyWriter<jakarta.activation.DataSource> was not found. […]

Read more jakarta.activation.DataSource was not found

Using Jersey 3x + Jetty to develop endpoints, but hits the following error during application startup. Terminal Exception in thread "main" java.lang.NoClassDefFoundError: jakarta/servlet/ServletInputStream at org.glassfish.jersey.jetty.JettyHttpContainerProvider.createContainer(JettyHttpContainerProvider.java:43) at org.glassfish.jersey.server.ContainerFactory.createContainer(ContainerFactory.java:58) at org.glassfish.jersey.jetty.JettyHttpContainerFactory.createServer(JettyHttpContainerFactory.java:110) at com.mkyong.MainApp.startServer(MainApp.java:22) at com.mkyong.MainApp.main(MainApp.java:32) Caused by: java.lang.ClassNotFoundException: jakarta.servlet.ServletInputStream at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) … 5 more 1. jakarta/servlet/* and Servlet API 5.0 Since Servlet API […]

Read more NoClassDefFoundError: jakarta/servlet/ServletInputStream

This article shows how to convert a Java project to a Maven project in IntelliJ IDEA. Table of contents 1. A Non-Maven Project 2. Add Framework Support – Maven 3. Update the default pom.xml 4. Reload the Maven project 5. References P.S Tested with IntelliJ IDEA 2021.1.1 1. A Non-Maven Project A non-Maven project (without […]

Read more Convert a Java project to Maven project in IntelliJ IDEA

In Java, if we remove items from a List while iterating it, it will throw java.util.ConcurrentModificationException. This article shows a few ways to solve it. Table of contents 1. java.util.ConcurrentModificationException 2. Java 8 Collection#removeIf 2.1 removeIf examples 2.2 removeIf uses Iterator 3. ListIterator example 4. Filter and Collect example 5. References P.S Tested with Java […]

Read more Java – How to remove items from a List while iterating?

In Java Logging APIs or java.util.logging, we use system property java.util.logging.config.file to define the location of the logging.properties file. Table of contents 1. Loads logging.properties at runtime 2. Loads logging.properties from the classpath 2.1 LogManager 2.2 System.setProperty("java.util.logging.config.file") 3. Download Source Code 4. References Note Java Logging APIs Tutorial 1. Loads logging.properties at runtime In the […]

Read more How to load logging.properties for java.util.logging

This article shows how to solve the popular JAXB exception Implementation of JAXB-API has not been found on module path or classpath. Table of contents 1. JAXBException: Implementation of JAXB-API has not been found 2. We need a JAXB Implementation 3. JAXB Implementation – Jakarta XML Binding 4. JAXB Implementation – EclipseLink MOXy 4.1 Implementation […]

Read more JAXBException: Implementation of JAXB-API has not been found on module path or classpath

Java 16 reached General Availability on 16 March 2021, download Java 16 here. Java 16 has 17 JEP items. 1. JEP 338: Vector API (Incubator) 2. JEP 347: Enable C++14 Language Features 3. JEP 357: Migrate from Mercurial to Git 4. JEP 369: Migrate to GitHub 5. JEP 376: ZGC: Concurrent Thread-Stack Processing 6. JEP […]

Read more What is new in Java 16

The below program launch a Java Swing application; It configures a JFrame and attach a JLabel to display a hello world and center the JLabel component. Read the comment for self-explanatory. SwingHelloWorld.java package com.mkyong.swing import javax.swing.*; import java.awt.*; public class SwingHelloWorld { public static void main(String[] args) { JFrame frame = new JFrame("Hello World Java […]

Read more Java Swing Hello World example

In Gradle, we can pass an –tests option to run a single unit test class. Read this Gradle Test Filtering. Terminal gradle test –test TestClass P.S Tested with Gradle 6.7.1 1. Run a single test class Review a simple unit test. DummyTest.java package com.mkyong.security.db; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; public class DummyTest { @Test void […]

Read more Gradle – How to run a single unit test class