Sunday, September 25, 2016

Apache Ant

Apache Ant is a Java based build tool from Apache Software Foundation. Apache Ant's build files are written in XML and they take advantage of being open standard, portable and easy to understand.

On an average, a developer spends a substantial amount of time doing mundane tasks like build and deployment that include:
  • Compiling the code
  • Packaging the binaries
  • Deploying the binaries to the test server
  • Testing the changes
  • Copying the code from one location to another
To automate and simplify the above tasks, Apache Ant is useful. It is an Operating System build and deployment tool that can be executed from the command line.

Features of Apache Ant

  • Ant is the most complete Java build and deployment tool available.
  • Ant is platform neutral and can handle platform specific properties such as file separators.
  • Ant can be used to perform platform specific tasks such as modifying the modified time of a file using 'touch' command.
  •  Ant scripts are written using plain XML. If you are already familiar with XML, you can learn Ant pretty quickly.
  •  Ant is good at automating complicated repetitive tasks.
  •  Ant comes with a big list of predefined tasks.
  •  Ant provides an interface to develop custom tasks.
  •  Ant can be easily invoked from the command line and it can integrate with free and commercial IDEs.

Maven

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.

In case of multiple development teams environment, Maven can set-up the way to work as per standards in a very short time. As most of the project setups are simple and reusable, Maven makes life of developer easy while creating reports, checks, build and testing automation setups.

Maven supports developers to manage following activities:


  • Builds
  • Documentation
  • Reporting
  • Dependencies
  • SCMs
  • Releases
  • Distribution
  • mailing list


Convention over Configuration

Maven uses Convention over Configuration which means developers are not required to create build process themselves.
Developers do not have to mention each and every configuration detail. Maven provides sensible default behavior for projects. When a Maven project is created, Maven creates default project structure. Developer is only required to place files accordingly and he/she need not to define any configuration in pom.xml.

In order to build the project, Maven provides developers options to mention life-cycle goals and project dependencies (that rely on Maven pluging capabilities and on its default conventions). Much of the project management and build related tasks are maintained by Maven plugins.

POM.XML:

POM stands for Project Object Model. It is fundamental Unit of Work in Maven. It is an XML file. It always resides in the base directory of the project as pom.xml.

POM also contains the goals and plugins. While executing a task or goal, Maven looks for the POM in the current directory. It reads the POM, gets the needed configuration information, then executes the goal. Some of the configuration that can be specified in the POM are following:

  • project dependencies
  • plugins
  • goals
  • build profiles
  • project version
  • developers
  • mailing lists


What is a Maven Repository?

In Maven terminology, a repository is a place i.e. directory where all the project jars, library jar, plugins or any other project specific artifacts are stored and can be used by Maven easily.
Maven repository are of three types
  • local
  • central
  • remote
Maven local repository is a folder location on your machine. It gets created when you run any maven command for the first time.
Maven local repository keeps your project's all dependencies (library jars, plugin jars etc). When you run a Maven build, then Maven automatically downloads all the dependency jars into the local repository.It helps to avoid references to dependencies stored on remote machine every time a project is build.

Maven central repository is repository provided by Maven community. It contains a large number of commonly used libraries.
When Maven does not find any dependency in local repository, it starts searching in central repository using following URL: http://repo1.maven.org/maven2/

Sometime, Maven does not find a mentioned dependency in central repository as well then it stopped build process and output error message to console. To prevent such situation, Maven provides concept of Remote Repository which is developer's own custom repository containing required libraries or other project jars.

What are Maven Plugins?

Maven is actually a plugin execution framework where every task is actually done by plugins. Maven Plugins are generally used to :
  • create jar file
  • create war file
  • compile code files
  • unit testing of code
  • create project documentation
  • create project reports

Following is the list of few common plugins:

clean - Clean up target after the build. Deletes the target directory.
compiler - Compiles Java source files.
surefire - Run the JUnit unit tests. Creates test reports.
jar - Builds a JAR file from the current project.
war - Builds a WAR file from the current project.
javadoc - Generates Javadoc for the project.
antrun - Runs a set of ant tasks from any phase mentioned of the build.

Creating Project

Maven uses archetype plugins to create projects. To create a simple java application, we'll use maven-archetype-quickstart plugin.

Project Templates

Maven provides users,a very large list of different types of project templates (614 in numbers) using concept of Archetype. Maven helps users to quickly start a new java project using following command:
mvn archetype:generate

Archetype is a Maven plugin whose task is to create a project structure as per its template. 

Sunday, September 18, 2016

Install Mysql, MongoDB and JAVA

Install Mysql

1. Extracting the binaries. This is where we are going to extract the binaries. When we extract the binaries, the following steps need to be taken into consideration.

# Default location available in the config files are
/usr/local/mysql.

# If you plan to install these in a different location, you have
to set the installation location in each configuration script.

# It is assumed here that the setup is done at the location
/usr/apps/mysql5.7 and the data files are being installed into
/usr/local/mysql/data

a. Navigate to the location. (your desired installation location)
shell> cd /usr/apps/mysql5.7

b. Extract the tar file.
shell> tar -zxvf /path/to/mysql-VERSION-OS.tar.gz

c. Create a symlink to the installation directory.
shell> ln -s full-path-to-mysql-VERSION-OS mysql

d. Change directory to mysql
shell> cd mysql

e. Create a new directory "mysql-files" and set permissions for that.
shell> mkdir mysql-files
shell> chmod 750 mysql-files


2. Once the directory structure is created and the permissions & ownerships are set, we are ready to configure the databases. Here, before proceeding with command execution, we need to change the scripts that are executed to do the configurations.

a. Open the file /usr/apps/mysql5.7/bin/mysqld_safe in a text editor with elevated privileges.

b. Modify the file as given in the picture below.

c. Open the file /usr/apps/mysql5.7/bin/mysql.server in a text editor with elevated privileges.

d. Modify the file as given in the pictures below.

# What actually happens here is you are pointing out your MySQL installation's data directory and the binaries directory to these scripts for them to properly run.


4. Once you are done with these, you are now ready to roll. This is how the database server daemon should be configured.

a. Initializing the database. Run either one of the following commands based on your version.
In your case it should be the second command.
shell> bin/mysql_install_db --user=mysql    # Before MySQL 5.7.6
shell> bin/mysqld --initialize --user=mysql  # MySQL 5.7.6 and up

b. Run the following and setup ssl for MySQL server with RSA. This is only required is it is MySQL 5.7.6 & up.
shell> bin/mysql_ssl_rsa_setup  # MySQL 5.7.6 and up



5. That's it. If everything is exactly done, the following should launch the mysqld in the safe mode.

shell> bin/mysqld_safe --user=mysql &

# After executing above, if you get no error, that implies your
configuration is successful. This could further be confirmed with the
following command.

ps -A | grep mysql

That should populate some result as follows.

PID  TTY   TIME CMD

1 ?          00:00:01 --CODINGGROUND-
25  pts/0 00:00:00 mysqld_safe
31  pts/0 00:00:00 mysql


6. Add the /usr/apps/mysql5.7/bin to your PATH , so that you could access the daemon and other binaries from any location.


7. After setting the path, restart your PC, open a terminal, type mysql -u root -p and press enter. It should prompt you for a password and once the correct password is given, you should get the
mysql> prompt.


Install MongoDB

1. Download the binaries from https://www.mongodb.org/downloads.

2. Extract the files from the downloaded archive to the installation directory

tar -zxvf mongodb-linux-x86_64-3.2.9.tgz   /home/softwares

3. Ensure the location of the binaries is in the PATH variable.

<mongodb-install-directory>/bin

4. Create the data directory

Before you start MongoDB for the first time, create the directory to which the mongod process will write data. By default, the mongod process uses the /data/db directory. If you create a directory other than this one, you must specify that directory in the dbpath option when starting the mongod process later in this procedure.

The following example command creates the default /data/db directory:

mkdir -p /data/db

5. Set permissions for the data directory

Before running mongod for the first time, ensure that the user account running mongod has read and write permissions for the directory.

6. Run MongoDB

  • Run without specifying paths
If your system PATH variable includes the location of the mongod binary and if you use the default data directory (i.e., /data/db), simply enter mongod at the system prompt:

mongod

  • Specify the path of the mongod
If your PATH does not include the location of the mongod binary, enter the full path to the mongod binary at the system prompt:

<path to binary>/mongod

  • Specify the path of the data directory
If you do not use the default data directory (i.e., /data/db), specify the path to the data directory using the --dbpath option:

mongod --dbpath <path to data directory>

7. Begin using MongoDB.

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. See Getting Started for the available editions.

Before deploying MongoDB in a production environment, consider the Production Notes document.

Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.


Install JAVA 

1. Downloading Oracle Java JDK

go to the oracle java SE website and download tar.gz file. Remember to choose the right tar file(64 or 32 bits)

2. Extract java into the installation directory:

tar -zxf jdk-8u5-linux-x64.tar.gz -C /home/softwares

3. Set path varables

add path of bin directory of jdk in /etc/environment file
eg: /home/softwares/jdk1.8.0_05/bin

also add JAVA_HOME variable
 JAVA_HOME : "/home/softwares/jdk1.8.0_05"

4. Setting Oracle JDK as the default JVM

In our case, the java executable is located under /home/softwares/jdk1.8.0_05/bin/java . To set it as the default JVM in your machine run:

update-alternatives --install /usr/bin/java java /home/softwares/jdk1.8.0_05/bin/java 100

and

update-alternatives --install /usr/bin/javac javac /home/softwares/jdk1.8.0_05/bin/javac 100

5. Verify your installation

java -version

Sunday, September 11, 2016

VI and Vim


  • Functionally, vim is almost a proper superset of vi. Therefore, everything that is in vi is available in vim.
  • Vim tries to resemble the syntax and semantic of Vi command as much as possible. But being an "improved version", Vim adds new commands and features. It also changes the semantic of some Vi commands to better match the current expectations of its programmers.
  • Vim can edit files inside a compressed archive (gzip, zip, tar, etc). 
  • Vim's Enhancements :
completion, comparison and merging of files (known as vimdiff), a comprehensive integrated help system, extended regular expressions, scripting languages (both native and through alternative scripting interpreters such as Perl, Python, Ruby, Tcl, etc.) including support for plugins, a graphical user interface (known as gvim), limited integrated development environment-like features, mouse interaction (both with and without the GUI), folding, editing of compressed or archived files in gzip, bzip2, zip, and tar format and files over network protocols such as SSH, FTP, and HTTP, session state preservation, spell checking, split (horizontal and vertical) and tabbed windows, Unicode and other multi-language support, syntax highlighting, trans-session command, search and cursor positionhistories, multiple level and branching undo/redo history which can persist across editing
sessions, and visual mode.

Week 1 - Assignment1 - Linux Commands


1.. Create a new user

login as root : sudo su
enter root’s pwd
command : adduser sahan
command user pwd: passwd sahan
to switch to new user : su sahan
to logout : exit
to see current user : whoami


2.. Reset password of user

*.to change current user’s password
cmd : passwd sahan
then enter current one and new one
*.to change another user’s password
login as root
cmd : passwd <username>


3.. Create a directory

login as root
change directory to home : cd /home
create directory : mkdir my_group

Give permissions

chmod ug+rwx my_group

To see permissions

ls -l


4.. Create a directory called my_user at home and give permissions to user only

method 1-
create directory : mkdir my_group

give permissiosn : chmod 700 my_group

method 2-
create directory : mkdir my_group

give permissiosn : chmod og+rwx my_group


5.. How many network interfaces your computer has..?

*.. Finding network interfaces

terminal : ip addr
or
ip link show

to get count :
*..ip link show | wc -l

wc - print newline, word, and byte counts for each file
to get help:
type = man wc

-l – print the count of new lines

*.. ip -o link show | wc -l

-o = to get exact number of network interfaces.

output each record on a single line, replacing line feeds wit the '\' character. This is convenient when you want to count
records with wc(1) or to grep(1) the output.


6.. Install xmind on your desktop without using yum..?

first installed java

url to refer = https://www.digitalocean.com/community/tutorials/how to-manually-install-oracle-java-on-a-debian-or- ubuntu-vps

set path variables for both jdk and jre in /etc/environment
file

**..when installing java to enter PATHS

gedit /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/jdk/jdk1.8.0_102/bin:/opt/jdk/jdk1.8.0_102/jre/bin/java"
JAVA_HOME="/opt/jdk/jdk1.8.0_102"


installed xmind using terminal (debian packge – not using tar)


7.. How you get first 5 entries of /var/log/messages..?

Linux logs a large amount of events to the disk, where they’re mostly stored in the /var/log directory in plain text. Most log entries go through the system logging daemon, syslogd, and are written to the system log.

To get last five entries=
terminal : tail -5 /var/log/syslog


to enable /var/log/messeges file:
edited /etc/rsyslog.d/50-default.conf file (removed # symbols related to messeges)
then restarted the computer


8.. How you get first 5 entries of /var/log/messages..?

terminal : head -5 /var/log/syslog

*. error occurred – desktop deactivted… try to fix using terminal



9.. How you get log entries of /var/log/messages which printed within today..?

‘find’ command :

find cmd can be used to find directories or files
eg :
Find files older than 31 days and delete them
terminal : find /path/to/search -mtime +31 -delete

*..get log entries of /var/log/messages
cmd - journalctl --since "2 days ago"


10.. How many lines in /var/log/messages?

wc -l /var/log/messages


11.. How many unique lines in /var/log/messages?

sort /var/log/messages | uniq -c | wc -l


12.. Sort directory/file list based on time inside your home directory?

ls -ltr –group-directories-first

group-directories-first = to show first directories by modification date and then files by modification date


13.. Access you friends machine using ssh and copy a file to there.?

SSH, which is an acronym for Secure SHell, was designed and created to provide the best security when accessing another computer remotely. Not only does it encrypt the session, it also provides better authentication facilities, as well as features like secure file transfer, X session forwarding, port forwarding and more so that you can increase the security of other protocols.

An SSH server is a software program which uses the secure shell protocol to accept connections from remote computers. SFTP/SCP file transfers and remote terminal connections are popular use cases for an SSH server. This article compares a selection of popular servers.

To check ssh status : sudo service ssh status
installed ssh : sudo apt-get install openssh-server

first intalled ssh server
apt-get install openssh-server

if needed install ssh client
apt-get install openssh-client
then create new user except hsenid in the server machine
then type : ssh vidushka@10.0.0.18


14.. Copy file which reside on your machine to your one using shell at you machine.?


What is "the shell"?

Simply put, the shell is a program that takes your commands from the keyboard and gives them to the operating system to perform. In the old days, it was the only user interface available on a Unix computer. Nowadays, we have graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) such as the shell.

On most Linux systems a program called bash (which stands for Bourne Again SHell, an enhanced version of the original Bourne shell program, sh, written by Steve Bourne) acts as the shell program. There are several additional shell programs available on a typical Linux system. These include: ksh, tcsh and zsh.

To copy : cp /to/source /to/destination
To move : mv /Source_Path /Destination_Path

man cp


15.. Rename your directory my_group to my_group1..?

cp : mv /home/my_group /home/my_group1

mv can also be used for moving.


16.. How you view partition information..?

We're talking about four main file systems: Ext2/Ext3/Ext4 and Btrfs (see B-Trees) as Ubuntu natives, and FAT32 and NTFS on Windows.

1.cmd : sudo lsblk -f

lsblk -f cmd displays=
NAME FSTYPE LABEL UUID MOUNTPOINT
sda1 vfat ESP F27D-78FF /boot/efi


17.. How you get total sizes of sub directories inside /var using single command?

Cmd : du -h /var

output eg : 4.0K /var/opt
4.0K /var/log/upstart


18.. Change system date to yesterday using command line..?

cmd : date 


19.. Remove directory my_group..?

cmd : rm
rm removes each specified file. By default, it does not remove directories.
cmd : rm -f
can be used to remove directories and contents

cmd : rmdir
remove only empty directories


20.. What are the following utilizations of your desktop.?

cmd : top 

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.

cmd : ps  
report a snapshot of the current processes.

1..CPU utilizations –

install systat - apt-get install sysstat
type cmd - mpstat

to get cpu usage in percentage -
cmd - echo $[100-$(vmstat|tail -1|awk '{print $15}')]

2..Memory utilizations -

cmd - cat /proc/meminfo

3..Disk utilization -

cmd – df