How to create and run a jar file

JAR (Java ARchive) is an archive file format typically used to aggregate many Java class files and associated metadata and resources (text, images and so on) into one file to distribute application software or libraries on the Java platform.

JAR files are built on the ZIP file format and have the .jar file extension. Computer users can create or extract JAR files using the jar command that comes with a JDK. They can also use zip tools to do so; however, the order of entries in the zip file headers is important when compressing, as the manifest often needs to be first.

How to create jar file
Into directory, there are at least java class files. It is important create the manifest file. Manifest file contains information about version, author, main class and other data about application created. Follow the TicTacToe example MANIFEST.MF file:
Manifest-Version: 1.0
Created-By: biliards
Main-Class: TicTacToe

Change directory where there are java class files and MANIFEST.MF file. To create jar file, edit this command line:
jar cfm TicTacToe.jar MANIFEST.MF TicTacToe*class

How to run jar file
The jar file created is runnable with follow command line:
java -jar TicTacToe.jar

JAR file manipulations
JAR file is a compress file and it is possible manipulate it in different ways:

  • view the contents of a JAR file
    jar tf TicTacToe.jar
  • extract the contents of a JAR file
    jar xf TicTacToe.jar
  • extract specific files from a JAR file
    jar xf TicTacToe.jar META-INF/MANIFEST.MF

Reference: Wikipedia, jar file and manifest file.

How to create and run a java file

Java files are source code edited by programmers from where to create executable files. An example about code structure is a sample TicTacToe game:

  1. create java file with main class (ie: TicTacToe class) and assign it the name
  2. if application is simple and uses few and simple classes, insert these class auxiliary into TicTacToe class
  3. else create one file for each class and declare each class into TicTacToe class

It is not possible run directly file. It needs to compile java file:
javac -g
and then it is possible run application recall name of main class:
java TicTacToe

This method is same if there are created one file for each class.

Reference: Wikipedia

How to set MySQL permissions read-only with exceptions

The infrastructure about MySQL Master Slave replication involves:

  1. MySQL custom configuration
  2. MySQL custom recall
  3. Optimization and performance about point 1 and 2

Often there are open source that customizes MySQL recall, and it is not simple to adapt a MySQL Master Slave infrastructure. So that any simple idea is considered.

More open source uses user session, and table about session could be unique problem about a system of Master Slave replication with more slave.

Each slave could permit a read-only permission for each table excluding table session with these MySQL commands:

grant select on database_name.* to 'mysql_user'@'localhost';
grant all on database_name.table_session to 'mysql_user'@'localhost';


How to change default editor

Each works well with your favorite text editor. It is important that there is a default editor known. In debian and in other linux distro, default editor is vi.

You could change default editor:

  1. during distro installation
  2. custom each user into .bashrc or .profile file with line:
    export EDITOR=/usr/bin/emacs
  3. custom locally in a shell session and/or particular program:
    env EDITOR=nano crontab -e


crontab – maintain crontab files for individual users (V3)
crontab [ -u user ] file
crontab [ -u user ] { -l | -r [ -i ] | -e }

Stamp output about crontab file:
crontab -l

Modify crontab with default editor:
crontab -e

yum segmentation fault in centos

After an upgrading with yum program, yum will end with segmentation fault.

Last link about libz is the cause:
-rwxr-xr-x 1 root root  75028  9 gen  2007
-rwxr-xr-x 1 root bin   96572  8 nov  2010
-rw-r--r-- 1 root bin  101462  8 nov  2010 libz.a
lrwxrwxrwx 1 root root     13  8 apr  2011 ->
lrwxrwxrwx 1 root root     13  8 apr  2011 -> need a different link:
lrwxrwxrwx 1 root root     13  8 apr  2011 ->

Reference: yum fails with segfault after source zlib upgrade

How to create Master Master replication between two MySQL instances

MySQL Master Master replication is a double MySQL Master Slave replication between two MySQL instances: one MySQL instance (Mi1) is Master and the other MySQL instance (Mi2) is Slave and vice versa.

Minimal configuration file (/etc/my.cnf) of each mysql instance is similar:


There is few difference.
server-id = 1
server-id = 2

If the servers are not alternative, and both writes into database, then it is important to be alert to the schema of the tables and it could be important add different auto increment configuration.
auto_increment_increment = 2
auto_increment_offset = 1

auto_increment_increment = 2
auto_increment_offset = 2

The initializing and starting replication is even to MySQL Master Slave replication between two MySQL instances.

It is important to assess the risks of a desynchronization between two MySQL instances. The errors can arise in the retrieval of information from the slave. If both instance writes into database, the reasons can be many:

  1. MySQL instances create a record considered as identical to the schema of a table (error 1062, duplicate entry)
  2. MySQL instances can not communicate due to lack of network for a time sufficient to change log file
  3. SQL syntax could be contain an error (error 1064, sql syntax)
  4. and the list is endless

It may need to add the slave skip errors configuration into /etc/my.cnf:
slave_skip_errors = 1062,1064

It may need to delete error on the fly with MySQL commands:
stop slave; set global SQL_SLAVE_SKIP_COUNTER=1; start slave;


Thread Safety in php

Thread safety is a computer programming concept applicable in the context of multi-threaded programs. A piece of code is thread-safe if it only manipulates shared data structures in a manner that guarantees safe execution by multiple threads at the same time.

There have been a few options available for a while to get PHP performing well on linux or IIS.
One solution is to configure web service to use PHP in FastCGI mode which allows PHP processes to be recycled rather than killed off after each PHP request and also allows you to run several PHP processes at once, making PHP much much faster with the added bonus that as it is using the CGI interface there is little or no incompatibility issues with PHP extensions.

The utilization of non thread safe binaries does not allow to use FastCGI mode!

On debian/ubuntu
Thread Safety enable.
# aptitude install apache2-mpm-worker libapache2-mod-fcgid php5-cgi && a2enmod fcgid && /etc/init.d/apache2 restartThread Safety disable.
# aptitude install apache2-mpm-prefork libapache2-mod-php5 && a2dismod fcgid && /etc/init.d/apache2 restart

If your non thread safe binaries software not works, it was because installing apache2-dev package on my system automatically installs apache2-thread-dev whose apxs2 tells the PHP build system to build with thread-safety on. Therefore, the solution was to directly install apache2-prefork-dev package.

Reference: Wikipedia, Tnread Safety dis/able, Install/Purge package

PHPmotion installation

PHPmotion is a free video sharing software that also has support for other types of media such as audio/mp3 sharing. The Content Managent System or (media cms application) will allow you to create and run your very own Video Sharing website, Music Sharing Site, Picture Sharing Site.

Servers – Linux/Unix server
- PHP 4.3 and above (including support of CLI)
- MySQL database server
- LAME MP3 Encoder
- Libogg + Libvorbis
- Mencoder and also Mplayer
- FFMpeg-PHP
- GD Library 2 or higher
- Be able to run background processes

PHP Settings
- open_basedir = (no value)
- upload_max_filesize = 100M
- post_max_size = 100M
- max_execution_time = 1500
- session.gc_maxlifetime = 14000
- safe_mode = off
- Thread saftery = disabled
- enable_dl = On

Libraries installation
Follow the steps on this page.

phpSHIELD loader
With this error:
PHP script /var/www/*/classes/config.php is protected by phpSHIELD and requires the phpSHIELD loader phpshield.5.3.lin. The phpSHIELD loader has not been installed, or is not installed correctly. Please visit the phpSHIELD php encoder site to download required loader.
Follow the steps on this page.

With this error:
PHP Fatal error: SourceGuardian Loader - This protected script does not support version 5.3.2-1ubu of PHP. Please contact the script author about this problem. Error code [07] in /var/www/*/classes/config.php on line 2
Assuming you have old revision installed, you need to update / upload 4 files from the php5.3 release (or download here)

Other error infamous
White screen

  • The following files MUST be uploaded in Binary mode
    /phpshiled/all files in this folder
  • Set error_reporting to E_ALL or into apache configuration
    LogLevel debug
  • Set Thread Safety to disable (follow the steps on this page)
  • Your revision is too old that you must install last revision:
    • Backup your database and /upload and your /themes/*/templates directories
    • Install new release
    • Use old database during new intallation
    • Copy old /upload and your /themes/*/templates directories

Reference: PHPmotion System Requirements, PHPmotion Forum

qmail and simple configuration

qmail is a modern SMTP server and the second most popular MTA on the Internet. A number of large Internet sites are using qmail, Plesk is one. If you are on Plesk control panel, and need to change email account password then changing password from Plesk is a lengthy process.

qmail is installed into /var/qmail or similar. There are more directories, but four are important: bin, control, mailnames and users. bin directory contains all binary programs about manage qmail service. mailnames directory contains all mail divided by domain and user.

If you type this command:
man qmail-controlYou obtain info about files into /var/qmail/control directory.
We analize rejectnonexist, rcpthosts and virtualdomains.

File is the list of domains, one per line. qmail-smtpd will reject any envelope recipient address with a domain not listed in rejectnoexist.

File is the list of domains, one per line. Allowed RCPT domains. If rcpthosts is supplied, qmail-smtpd will reject any envelope recipient address with a domain not listed in rcpthosts. Any details with command line:
man qmail-smptdvirtualdomains
List of virtual users or domains, one per line. A virtual user has the form user@domain:prepend, without any extra spaces. When qmail-send sees the recipient address user@domain, it converts it to prepend-user@domain and treats it as local. Any details with command line:
man qmail-send

If you type this command:
man qmail-usersYou obtain info about files into /var/qmail/users directory: assign and cdb.

List of users addresses. File is a series of assignments, one per line. It ends with a line containing a single dot. Lines must not contain NUL.

It is a constant database (CDB). CDB is a binary format that can be accessed quickly by qmail-lspawn, even when there are thousands of assignments.

.qmail files
.qmail files contain a list of delivery instructions, one instruction per line. Delivery of a user’s mail is usually controlled by one or more “.qmail” (pronounced dot kyoo mail) files. The pseudo-user on all qmail systems whose home directory is usually /var/qmail/alias. About each user, home directory is usually /var/qmail/mailnames/domain/user/.qmail. Any details with command line:
man dot-qmail

You could use any programs to manage qmail service. Most popular is vpopmail. vpopmail is a set of API that manages virtual user accounts on a qmail system, and handles delivery for these virtual users. The command-line utilities, and Qmailadmin all use the vpopmail API, provided by the vpopmail library to manage the system. vpopmail does not work with Plesk. So that, you could run the Plesk or qmail commands. Options about Plesk commands line may differ from version to version: we are using v10.3. Any details, you could run each command with –help.

create a domain
If you want configure only domain mail into Plesk,
/usr/local/psa/bin/domain --create -dns false -mail_service true -notify false -ip
else if you have Plesk panel, you could add new domain out to Plesk and you could add mail into qmail service.
This configuration is available only user with forward because it is disable change password without Plesk or vpopmail.
You must modify five files (assign, cdb, rejectnonexist, rcpthosts and virtualdomains) and create new directory into /var/qmail/mailnames.
If the domain is, add domain into files:
echo "" >> /var/qmail/control/rejectnonexist
echo "" >> /var/qmail/control/rcpthosts
To add domain into virtualdomains, and you are using prefix, you must use new prefix. Plesk uses progressive number like id domain. Show last prefix:
tail -n 1 /var/qmail/control/virtualdomains | awk -F ':' '{print $2}'
If last prefix number is 35, you could use 100 so that you could use again Plesk:
echo "" >> /var/qmail/control/virtualdomains
mkdir /var/qmail/mailnames/
echo "|bouncesaying This\ address\ no\ longer\ accepts\ mail." > /var/qmail/mailnames/
chown -R popuser.popuser /var/qmail/mailnames/
chmod -R 700 /var/qmail/mailnames/

Show values about qmail user: popuser
grep popuser /etc/passwd
Output could be:
popuser:x:110:31:POP3 service user:/var/qmail/popuser:/bin/false
Add on the top domain line into /var/qmail/users/assign:
nano /var/qmail/users/assign

Now run qmail-newu: it processes the assign file and generates a new cdb:

create an user
If domain and mail are configured into Plesk and you must create new user,
/usr/local/psa/bin/mail --create -passwd mypassword -mailbox true
else if domain and mail are configured into Plesk and you must update only password,
/usr/local/psa/bin/mail -u -passwd mypassword
else if domain and mail are not configured into Plesk, commands are more than one. You must modify two files (assign and cdb) and create new directory into /var/qmail/mailnames/ If the user name is biliards, add on the top user line into /var/qmail/users/assign:
nano /var/qmail/users/assign

Now run qmail-newu: it processes the assign file and generates a new cdb:
Make the user home directory:
mkdir /var/qmail/mailnames/
mkdir /var/qmail/mailnames/\@attachments
mkdir /var/qmail/mailnames/
mkdir /var/qmail/mailnames/
mkdir /var/qmail/mailnames/
mkdir /var/qmail/mailnames/

Make two files:
cat /var/qmail/mailnames/
| true
| /usr/bin/deliverquota ./Maildir

cat /var/qmail/mailnames/
0 0

Modify the owner and permissions:
chown -R popuser.popuser /var/qmail/mailnames/
chmod -R 700 /var/qmail/mailnames/
chmod 600 /var/qmail/mailnames/
chmod 644 /var/qmail/mailnames/

User password is configurable only Plesk or vpopmail programs. So that, if you have other domains configured into Plesk, you must use Plesk commands or you add line to user .qmail file to forward mailing:
cat /var/qmail/mailnames/
| true
| /usr/bin/deliverquota ./Maildir

create an alias
If domain and mail are configured into Plesk and you must create new user alias,
for example, user biliards and alias bilardi and webmaster,
/usr/local/psa/bin/mail -u -aliases add:bilardi,webmaster
else if you want create only alias about mail already configured,
nano /var/qmail/users/assign

Now run qmail-newu: it processes the assign file and generates a new cdb:

To test mail that you created, follow the steps on this page.

Reference:, FAQ, vpopmail, pop account