Maven – List all the project’s plugins

In Maven, you can use mvn help:effective-pom to list all the current project’s plugins and its version. D:\maven-examples\java-web-project> mvn help:effective-pom [INFO] Scanning for projects… [INFO] [INFO] ——————< com.mkyong.web:java-web-project >——————- [INFO] Building java-web-project Maven Webapp 1.0-SNAPSHOT [INFO] ——————————–[ war ]——————————— [INFO] [INFO] — maven-help-plugin:3.1.0:effective-pom (default-cli) @ java-web-project — [INFO] Effective POMs, after inheritance, interpolation, and profiles …

Read more

Java – How to join List String with commas

In Java, we can use String.join(“,”, list) to join a List String with commas. 1. Java 8 1.1 String.join JavaStringExample1.java package com.mkyong; import java.util.Arrays; import java.util.List; public class JavaStringExample1 { public static void main(String[] args) { List<String> list = Arrays.asList("a","b","c"); String result = String.join(",", list); System.out.println(result); } } Output a,b,c 1.2 Stream Collectors.joining JavaStringExample2.java package …

Read more

Python – Check if a String contains another String?

In Python, we can use in operator or str.find() to check if a String contains another String. 1. in operator name = "mkyong is learning python 123" if "python" in name: print("found python!") else: print("nothing") Output found python! 2. str.find() name = "mkyong is learning python 123" if name.find("python") != -1: print("found python!") else: print("nothing") …

Read more

Python – How to check if a file exists

In Python, we can use os.path.isfile() or pathlib.Path.is_file() (Python 3.4) to check if a file exists. 1. pathlib New in Python 3.4 from pathlib import Path fname = Path("c:\\test\\abc.txt") print(fname.exists()) # true print(fname.is_file()) # true print(fname.is_dir()) # false dir = Path("c:\\test\\") print(dir.exists()) # true print(dir.is_file()) # false print(dir.is_dir()) # true If check from pathlib import …

Read more

Java – How to convert System.nanoTime to Seconds

We can just divide the nanoTime by 1_000_000_000, or use the TimeUnit.SECONDS.convert to convert it. Note 1 second = 1_000_000_000 nanosecond JavaExample.java package com.mkyong; import java.util.concurrent.TimeUnit; public class JavaExample { public static void main(String[] args) throws InterruptedException { long start = System.nanoTime(); Thread.sleep(5000); long end = System.nanoTime(); long elapsedTime = end – start; System.out.println(elapsedTime); // …

Read more

Python – How to convert String to float

In Python, we can use float() to convert String to float. num = "3.1415" print(num) print(type(num)) # str pi = float(num) # convert str to float print(pi) print(type(pi)) # float Output 3.1415 <class ‘str’> 3.1415 <class ‘float’> References Python docs – float()

Python – How to convert int to String

In Python, we can use str() to convert a int to String. num1 = 100 print(type(num1)) # <class ‘int’> num2 = str(num1) print(type(num2)) # <class ‘str’> Output <class ‘int’> <class ‘str’> References Python docs – str() Python – How to convert String to int

Python – How to convert String to int

In Python, we can use int() to convert a String to int. # String num1 = "88" # <class ‘str’> print(type(num1)) # int num2 = int(num1) # <class ‘int’> print(type(num2)) 1. Example A Python example to add two numbers. 1.1 Add two String directly. num1 = "1" num2 = "2" num3 = num1 + num2 …

Read more

Java – Count the number of items in a List

In Java, we can use List.size() to count the number of items in a List package com.mkyong.example; import java.util.Arrays; import java.util.List; public class JavaExample { public static void main(String[] args) { List<String> list = Arrays.asList("a", "b", "c"); System.out.println(list.size()); } } Output 3 References Java doc – List

Python – How to convert float to String

In Python, we can use str() to convert float to String. pi = 3.1415 print(type(pi)) # float piInString = str(pi) # float -> str print(type(piInString)) # str Output <class ‘float’> <class ‘str’> References Python docs – str() Python – How to convert int to String Python – How to convert String to float

How to check MySQL version

In the terminal, we can type mysql -V (uppercase V) to display the current MySQL version installed on the server. Terminal $ mysql -V mysql Ver 8.0.18 for Linux on x86_64 (MySQL Community Server – GPL) The above output show MySQL version 8.0.18 is installed on the server. Server System Variables Alternatively, we can connect …

Read more

Java Selection sort example

Selection sort is an in-place comparison sort. It loops and find the first smallest value, swaps it with the first element; loop and find the second smallest value again, swaps it with the second element, repeats third, fourth, fifth smallest values and swaps it, until everything is in correct order. P.S Selection sort is inefficient …

Read more

Java Bubble sort example

Bubble sort is the simplest sorting algorithm, it compares the first two elements, if the first is greater than the second, swaps them, continues doing (compares and swaps) for the next pair of adjacent elements. It then starts again with the first two elements, compares, swaps until no more swaps are required. 1. Explanation #unsorted …

Read more

ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

Try to log into the MySQL server, but it prompts the following error message: Terminal $ mysql ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO) 1. Solution – (using password: NO) The user ‘root’ need a password to log into the MySQL server. To solve it, please provide a password with -p …

Read more

Nginx + WordPress ERR_TOO_MANY_REDIRECTS

Fresh installs a WordPress on Windows for development, and hits the ERR_TOO_MANY_REDIRECTS error message? Tested URL : http://localhost/index.php/wp-admin/install.php Tested : PHP 7.1.10 WordPress 4.8.3 Nginx 1.12.1 MySQL 5.7.17 Windows 10 your-nginx\conf\nginx.conf upstream php { server 127.0.0.1:9999; } server { listen 80; server_name localhost; root www/wordpress; location / { try_files $uri $uri/ /index.php?$args; } location ~ …

Read more

PHP + Windows – Call to undefined function mysql_connect()

Install WordPress and hits the following error message : Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\nginx-1.12.1\www\wordpress\wp-includes\wp-db.php… Tested PHP 7.1.10 WordPress 4.8.3 Nginx 1.12.1 MySQL 5.7.17 Windows 10 Solution To install WordPress, PHP needs Mysql extension, to fix this, loads php_mysqli.dll in php.ini file. php.ini ; Directory in which the loadable extensions …

Read more

Nginx + PHP on Windows

This article shows you how to install and integrate Nginx and PHP on Windows. Tested Nginx 1.12.1 PHP 7.1.10 Windows 10 1. Install Nginx + PHP Basically, just download zip file and extracts it, no installation. To install Nginx Visit http://nginx.org/en/download.html Download nginx/Windows-1.12.2 Extract to C:\nginx-1.12.1 To Install PHP Visit http://windows.php.net/download/ Download PHP7.1 download VC14 …

Read more

php-cgi.exe – The application was unable to start correctly

Run php-cgi.exe and hits a pop up dialog showing the following error message : Application Error : The application was unable to start correctly (0xc000007b) Terminal c:\php7.1>php-cgi.exe -b 127.0.0.1:9123 Tested with PHP 7.1.10 on Windows 10 Solution To run PHP on Windows, you need to install Redistributable for Visual Studio, refer to the official PHP …

Read more

Nginx + PHP – No input file specified

A common Nginx + PHP error message “No input file specified.” nginx.conf http { include mime.types; default_type application/octet-stream; server { listen 80; server_name localhost; location / { root www; index index.html index.htm; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9999; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } Tested with Nginx 1.12.1 + PHP …

Read more

PrimeFaces – Open Window By Dropdown Selection

Technology: Primefaces it’s java based web framework to develop web applications using java. It’s one of the compliance frameworks for JSF, there are many other frameworks like omnifaces, richfaces. Primefaces has rich UI components. In this tutorial primefaces, maven, java8, glasifish servers are used. Use case: If you want to open a new page by …

Read more

Spring Boot + Hibernate Search example

Here we will create a Spring Boot web application example with Hibernate Search + Thymeleaf template engine, and deploy it as a WAR to Wildfly 10.1. Technologies used: Spring Boot 1.5.6.RELEASE Java 8 Hibernate Search 5.6.1.Final Embedded Tomcat, Wildfly 8.1 Final & 10.1 Final 1. Project Structure A standard Maven project structure 1. Project Dependencies …

Read more

Mac OSX – Redirect .htaccess is not working ?

Here is the .htaccess file. /Library/WebServer/Documents/.htaccess # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /mkyong/ RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /mkyong/index.php [L] </IfModule> # END WordPress Solution Find the Apache config file in /etc/apache2/httpd.conf, make sure the following settings are configured properly : 1. The mod_rewrite.so is loaded. …

Read more

Mac OSX – where is default localhost folder?

On Mac OSX, the default localhost folder is located at /Library/WebServer/Documents P.S Tested with MacOS Sierra, 10.12.6 Find httpd.conf By default, Apache is enabled and installed in /etc/apache2/, inside httpd.conf file, find DocumentRoot to tell where is the default localhost folder. sudo vim /etc/apache2/httpd.conf # DocumentRoot: The directory out of which you will serve your …

Read more

Oracle PL/SQL – BITAND function example

The BITAND function treats its inputs and its output as vectors of bits, the output is the bitwise AND of the inputs. Basically it performs below steps. Converts the inputs into binary. Performs a standard bitwise AND operation on these two strings. Converts the binary result back into decimal and returns the value. 1. BITAND …

Read more

Gradle – Could not find method compileOnly

Git clone a new project, Gradle build and hits the following error message : Terminal $ gradle clean build FAILURE: Build failed with an exception. * Where: Build file ‘/Users/mkyong/Documents/workspace/hc2/web/build.gradle’ line: 25 * What went wrong: A problem occurred evaluating project ‘:web’. > Could not find method compileOnly() for arguments [org.springframework.boot:spring-boot-starter-tomcat] on project ‘:web’. * …

Read more

MongoDB – Where is the log file?

Default, MongoDB creates the log file at this path /var/log/mongodb/mongodb.log, if the log file is not found, please check with the MongoDB config file. logpath Check the MongoDB config file at /etc/mongod.conf or /yourMongoDBpath/mongod.conf, the logpath defined where to log. /etc/mongod.conf $ cat /etc/mongod.conf # mongod.conf # Where to store the data. # Note: if …

Read more

How to edit hosts file on Mac OSX

Edit this file /private/etc/hosts. Terminal $ sudo nano /private/etc/hosts ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost 127.0.0.1 mkyong-mac 198.x.x.x linode-bot1 1.2.3.4 www.google.com References What is the difference between …

Read more

MongoDB – bind() failed errno:99 Cannot assign requested address for socket

Review the server environment, we need to allow Server B to access the Server A MongoDB database. Server A – MongoDB server Private IP – 192.168.162.129 / 17 Server B – Application Server Private IP – 192.168.204.205 / 17 Update the bind_ip, but unable to start mongod process anymore. /etc/mongod.conf #$ vim /etc/mongod.conf # Listen …

Read more

MongoDB – Failed to unlink socket file /tmp/mongodb-27017

Upgraded MongoDB and unable to start the mongod process, review the /var/log/mongodb/mongod.log file, and found the following error messages : Terminal 2017-08-24T03:57:21.289-0400 I CONTROL [initandlisten] MongoDB starting : pid=31927 port=27017 dbpath=/var/lib/mongodb3 64-bit host=hcompass 2017-08-24T03:57:21.289-0400 I CONTROL [initandlisten] db version v3.2.16 2017-08-24T03:57:21.289-0400 I CONTROL [initandlisten] git version: 056bf45128114e44c5358c7a8776fb582363e094 2017-08-24T03:57:21.289-0400 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t …

Read more

Oracle PL/SQL – ALTER function example

The ALTER FUNCTION statement explicitly recompile a standalone function. Sometimes, ALTER TABLE on the table being used in function will cause the function becomes INVALID, we need to recompile (alter function) it to make it VALID again. 1. ALTER function example First, we will create table test_alter, function get_max_amount. In this function, we are using …

Read more