Category Archives: Java

Install Oracle Java 8 on Ubuntu Linux

To install Oracle JDK 8 on Ubuntu you can choose one of two methods:
A. Automatic installation:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

sudo apt-get install oracle-java8-installer

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws

B. Manual installation:

Download oracle jdk at

Extract archive into /usr/local/jdk1.8.0_65

sudo update-alternatives --install  /usr/bin/java java /usr/local/jdk1.8.0_65/bin/java 1
sudo update-alternatives --install  /usr/bin/javac javac /usr/local/jdk1.8.0_65/bin/javac 1
sudo update-alternatives --install  /usr/bin/javaws javaws /usr/local/jdk1.8.0_65/bin/javaws 1

sudo update-alternatives --set  java /usr/local/jdk1.8.0_65/bin/java
sudo update-alternatives --set  javac /usr/local/jdk1.8.0_65/bin/javac
sudo update-alternatives --set  javaws /usr/local/jdk1.8.0_65/bin/javaws

Thanx to

Exclude beans from tests in Spring Boot

Running unit tests bootstraps, for example, scheduling tasks (EnableScheduling, Scheduled).
To exclude automatic start up auto-configuration beans with annotation you can follow next instruction:

1. Create annotation:

public @interface ExcludeFromTests {

2. Annotate with it Application and Scheduled beans (or what you want to be skipper during tests):

public class BackendApplication {

    public static void main(String[] args) {, args);
public class AppScheduler {

    @Scheduled(fixedRateString = "1000000")
    public void do() {

3. Create TestApplication class for tests and add ComponentScan.Filter:

@ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, value = ExcludeFromTests.class))
public class TestBackendApplication {

    public static void main(String[] args) {, args);

4. Say Spring boot to use TestApplication class in tests:

@SpringBootTest(classes = TestBackendApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SomeTest {
  public void test1() throws Exception {

5. Profit! -)

See also:

Adding manifest attributes to existing JAR file

To modify manifest in external existing JAR file in JAVA do:

                            <jar update="true" 
                                    <attribute name="Class-Path" 

Thanx to


The bad idea is to compress JAR file with ZIP:

Using keystore in JAVA for Self-Signed SSL certificates

You may observe the next error when working with domains with self-signed certificate: 
unable to find valid certification path to requested target

In this case you have to do next steps to allow java program trust to the given domain:

1. Get SSL certiicate for domain:

openssl s_client -connect > cert1.cert

2. Generate java keystore:

D:\runtime\jdk8u45x64\bin\keytool -import -v -trustcacerts 
-file cert1.cert -keystore cacerts1.jks 
-alias somealias -keypass "changeit" -storepass "changeit"

Type “yes” when promts to accept certificate.

3. Add JVM arguments to your program:"D:\projects\my\cacerts3.jks""changeit"

4. (Optional) debug arguments:

Also available java arguments (in case of self signed certificates not useful):"D:\projects\my\cacerts3.jks""changeit"

Thanx to:

Get ContentType for URL in java

To determine content type for certain URL you can use next:

package org.test;


public class ContentType {

    public static void main(String[] args) throws IOException {

    private static void getContentType(String uri) throws IOException {
        URL url = new URL(uri);
        HttpURLConnection connection = (HttpURLConnection)  url.openConnection();

        System.out.println(connection.getContentType() + ": " 
          + connection.getResponseCode() + " -> " + uri);

The result:

text/html; charset=windows-1251: 200 ->
application/pdf: 200 ->

So, as you see to get content type it is need to send small HEAD request!
Thanx to

JRebel and JBoss integration with WAR file

You may know about JRebel project. It’s very helpful for development in java world.
The following steps describe how to use JRebel for Web application:

1. Install JRebel plugin for your IDE.

2. Create file descriptor rebel.xml with JRebel plugin in your IDE in WEB-INF\classes folder like:

<?xml version="1.0" encoding="UTF-8"?>

   <dir name="D:/project/idea/out/production/projectUI">

   <link target="/">
   <dir name="D:/project/src/projectUI/src/main/webapp">


3. Add the argument to JBoss AS start script:


Here is the path to jrebel.jar file placed after installation.

4. Deploy your application on JBoss.

5. Change some code and make (recompile) the project.

6. See the changes! Profit!

Thanx, zeroturnaround!

Insert Javascript code in JSF page

Usually you may need to insert a couple of JavaScript in your JSF page markup.
The following advice helps you do it right:

 <ui:composition ...>
    <ui:define name="body">
        <!-- your code -->
        <h:outputScript target="body">
                alert("It works!");
        <!-- your code -->

So, as you see in JSF we use h:outputScript tag with CDATA inside to workaround issues like “The content of elements must consist of well-formed character data or markup” for valid XHTML.

Thanx to