Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Thursday, October 24, 2019

LOG4J on Windows Complaining about Console Code Page

I was running the Windows JVM with LOG4J 2.8.1 with SLF4J 2.7.5 on the Windows Subsystem for Linux and encountered an error as follows,

2019-10-24 16:03:19,902 main ERROR Unable to inject fields into builder class 
for plugin type class org.apache.logging.log4j.core.appender.ConsoleAppender, 
element Console. java.nio.charset.UnsupportedCharsetException: cp0

In the Windows Subsystem for Linux terminal, the code page returned was 0, which was the source of the code page cp0.

user@WSL:/mnt/c/Windows/System32$ chcp.com
Active code page: 0
user@WSL:/mnt/c/Windows/System32$

Interestingly, the returned code page is on Windows Command Prompt,

C:\Windows\System32>chcp
Active code page: 437

C:\Windows\System32>

To get rid of the problem, we need to inform Java the encoding scheme, e.g.,

java -Dsun.stdout.encoding=UTF-8 -Dsun.err.encoding=UTF-8 FooClass

where we assume we run the FooClass class.

Monday, September 23, 2019

Gradle Complaining about JDK not Found

I was attempting to compile a Kotlin project, and encountered the following error:


* What went wrong:

Execution failed for task ':compileKotlin'.

> Kotlin could not find the required JDK tools in the Java installation 'C:\Program Files\Java\jre1.8.0_211' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
The answer to the problem is straightforward is to inform Gradle where the JDK is. Since I am on a Windows host, and the host has had these installed:

C:\>dir "C:\Program Files\Java\"
....

05/14/2019  09:58 AM    <DIR>          .
05/14/2019  09:58 AM    <DIR>          ..
03/04/2019  09:39 PM    <DIR>          jdk-11.0.2
03/04/2019  09:29 PM    <DIR>          jdk1.8.0_201
05/12/2019  08:32 PM    <DIR>          jre1.8.0_211
.....

C:\>

I added the following line to the gradle.properties file, and the problem went away,

org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_201

Wednesday, July 31, 2019

Adding Github Repository as a Dependecy to Java Project

I just learned that we could easily add a Github repository as a dependency to a Java project using JitPack. Below is an example to a Maven project to which we wish to add JGraphX as a dependency to the Maven project. Since JGraphX "don't properly support Maven or publish to Maven Central", this comes very handy. I view this as a two step approach:

  1. Add JitPack to the pom.xml. I added the following just above the dependencies tag:
    
    <repositories>
     <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
     </repository>
    </repositories>
    
  2. Add a Git commit or release of a Git repository as a dependency. In the following, we use the JGraphX project as an example. The project's Git repository is the JGraphX repository whose url is https://github.com/jgraph/jgraphx.git, from which we read that the Github username is jgraph, and the repository name is jgraphx. Browsing the project repository, we can select a commit by using its commit id (i.e., commit hash), or a tag, or a release. The JGraphX has a number releases as seen at https://github.com/jgraph/jgraphx/releases, among which is v4.0.3. Having gathered the Github username, the repository name, and the release number, we add the following as a child tag to the dependencies tag,
    
     <dependency>
      <groupId>com.github.jgraph</groupId>
      <artifactId>jgraphx</artifactId>
      <version>v4.0.3</version>
     </dependency>
    
After these two steps, we do a Maven update.

Friday, October 6, 2017

Get Rid Of Eclipse Warning Messages on JavaFX API

When I was writing a Java program with JavaFX API, Eclipse complained loudly although the application runs smoothly since JavaFX is part of Java 8. The warning messages are very annoying. An example message is as follows,

Access restriction: The type 'Application' is not API (restriction on required 
library 'C:\Applications\Java\jdk1.8.0_144\jre\lib\ext\jfxrt.jar')

Since a picture is worth 1000 words, below is a screen shot showing the messages,




To get rid of the messages, the easiest way, perhaps, is to install the e(fx)clipse plugin for Eclipse.  To install it, one may follow the steps below,

  1. Start Eclipse. The rest of steps are operations on Eclipse.
  2. Select "Help" from the menu
  3. Select "Install New Software"
  4. On the "Available Software" pop-up window, select "All available sites" for the "Work with:" field.
  5. Type "e(fx)clipse" as the filter text or/and check "e(fx)clipse" under "General Purpose Tools" 
  6. Select "Next" or "Finish" to install it.  Following the instruction to accept the license term and restart Eclipse


After Eclipse restarts, the warning messages should go away.



Tuesday, August 29, 2017

Running Out-dated JNLP Program

When attempted to launch the remote control JNLP Web Start program from a computer server, I encountered an error:

Unsigned application requesting unrestricted access to system
The following resource is signed with a weak signature algorithm MD5withRSA and is treated
as unsigned: http://192.168.1.5:80/Java/release/Win64.jar

The screen shot is also included,


The error is the result that Java has updated and the MD5withRSA should not be used any more. One work around is to temporary enable the MD5withRSA. One may change the Java security configuration by editing the java.security file. In my case, the file is C:\Program Files\Java\jre1.8.0_141\lib\security\java.security. You will find a line that disables a few algorithms, such as,

jdk.jar.disabledAlgorithms=MD2, MD5, RSA keySize < 1024

We can now simply comment out the line by adding a # at the beginning the line. The line should become,

#jdk.jar.disabledAlgorithms=MD2, MD5, RSA keySize < 1024
In addition, you may need to launch the Java Console, and add the site, in my case, http://192.168.1.5 in the "Exception Site List".