Saturday, September 8, 2018

PGP Encryption using Apache Camel

PGP (Pretty Good Privacy) Encryption is a widely used encryption mechanism which can be used to provide public key encryption.
There are many PGP encryption implementations using Java language which are quite complex. But Apache Camel Crypto component facilitates a very simple and convenient way of implementing PGP encryption.
Following code encrypts a given message using Apache Camel. org.apache.camel:camel-crypto is the only one library i have used here.
Most of the example in the internet shows the way which a file is used as the input for the encryption. But here i will show you how to directly encrypt a string (text message).
I'm using the public key in the public.gpg file to encrypt the message. The code is really straight foreword. Complete working project is available on GitHub and the URL is available at the bottom. All required key files are available there. You can clone the project and execute the program.

Following is the GitHub URL of complete project of this tutorial.
https://github.com/lakjcomspace/PGPEncryption

Monday, January 1, 2018

Docker MySQL Automatic Backups using Cron and Supervisor

mysqldump command allows you to create an SQL dump file of the database. By executing this command using a scheduler application like Windows Task Scheduler or Linux Cron you can create periodic backups automatically.
But when it comes to Docker MySQL image you cannot do this since base image does not contain any scheduler application. Even though we can install a scheduler utility like Cron on MySQL image, it does not do what we want since the MySQL container executes only the DB application at the container startup. It does not trigger the executable related to the scheduler application.
Here is my solution to the above problem. Using 'Supervisor' application to execute both MySQL and Cron. Supervisor is a process monitoring and controlling application for UNIX-like operating systems.

Following is the step by step guide to the solution. All these steps are instructions in the Dockerfile of the final output image. You don't want to do these things manually except copying the contents of the files. My Dockerfile will do the job. I'm listing these thing here just for your clarification.

1. Use MySQL docker image as the base image.
2. Install Cron on base image.
3. Install Supervisor on base image.
4. Prepare supervisord.conf Supervisor configuration file so that it starts MySQL DB and Contrab.
5. Add an entry to Crontab file so that it execute the dbdump.sh (Shell script which contains the mysqldump commands) everyday 11.45pm.

Following are the files which do all these things. Place all files inside a single folder and build image of the final container.

Every commands are straight forward where you can search and find more information. But touchrootcron in supervisord.conf file is something special. This is a trick to solve permission problem in Docker layered file system (Read for Docker layered file system and copy-on-write (CoW) strategy). root crontab file should be in the writable layer container layer.


Don't hesitate to put a comment if you have any problem.

Friday, April 28, 2017

Excluding Property Files from Jar File : Maven Shade Plugin

Recently, i wanted to create a single Jar file with all the dependencies while the property files are excluded which are coming from the project. But the property files which are coming from dependencies should be preserved. My idea was to externalize property file so that someone can edit them without going inside Jar.

I tried several options.

Resources plugin perfectly work for the need. But it excludes the property files even when i run the project from the IDE (Eclipse/NetBeans)

I tried jar-with-dependencies pre-defined assembly descriptor with few customization. I used exclusion in unpackOptions. But it excludes property files which are coming from all the dependent modules.

Finally i found the working solution. It was Maven Shade Plugin

Following is example pom.xml. There you can see how i have used Maven Shade Plugin with property file excluding configurations. Shade plugin can be use to filter any file file from any dependent module conveniently.
Since i wanted an executable Jar i have specially used ManifestResourceTransformer in the Shade configurations.



Tuesday, December 20, 2016

Getting Start with MySQL Community Server ZIP Archive on Windows

It's always easy to use a zip archive than installing a software on your machine. Recently I've got to use MySQL Community Server ZIP Archive (mysql-5.7.17) and faced some problem when setting up the server. I will give you few step by step guidelines for a successful set up so that you won't face the same problems.

Step 1: Extract the zip archive.
Lets say the base directory path is D:\mysql-server

Step 2: Open the command prompt in Administrator Mode and navigate to MySQL base directory.
This is the most important step. MySQL needs access to your registry at the initial execution. If you execute the initial MySQL commands without administrator mode you will get an error message like follows.
Could not create or access the registry key needed for the MySQL application
to log to the Windows EventLog. Run the application with sufficient
privileges once to create the key, add the key manually, or turn off
logging for that application.

Step 3: Enter following commands.
D:\mysql-server> mysqld --initialize
or
D:\mysql-server>mysqld --initialize-insecure

Above first command will create a random password for root user account while second won't.

Setp 4: Enter mysqld in the command prompt.
D:\mysql-server> mysqld
Now your MySQL server is up and running!

Using command prompt in administrator mode is only for the setting up. You don't want administrator mode in the later sever startups.

A Note for MySQL Workbench Users:
I use MySQL Workbench as the IDE. My OS is a 64bit OS and I downloaded 64bit non-install zip version of MySQL Workbench. But it got crashed when i started it. Then i browsed internet and found that 32bit version is the solution. I downloaded MySQL Workbench 32 bit non-install zip and it worked fine.


Thursday, January 28, 2016

Find Eclipse IDE Information - Eclipse Plugin Development

This simple Eclipse plugin program shows you how to retrieve following information regarding the Eclipse IDE.
  • IDE name
  • IDE version (.., Kepler, Luna, Mars,..etc with version number) 
  • Plugin version
  • Platform user name




You can test the program by running it your RCP environment. When you ran it, click on the LakJ Comspace icon in the tool bar of Eclipse sandbox window. Then you will see the information.
Following is the java code related to the program. You can download the complete project from the github links given at the end of the tutorial.

Here the InfoUtil.java does the information retrieving. Rest of the two classes (Activator and InfoAction) help the program to behave as a Eclipse plugin.

Following are the GitHub URL's for complete plugin project. You can clone the project or downolad the project as a zip file. To run the project open an Eclipse RCP environment and import the project as a maven project.

GitHub repository URL - https://github.com/lakjcomspace/Eclipse-Find-IDE-Info
GitHub HTTPS clone URL - https://github.com/lakjcomspace/Eclipse-Find-IDE-Info.git
Download Project as a Zip - https://github.com/lakjcomspace/Eclipse-Find-IDE-Info/archive/master.zip

Tuesday, November 24, 2015

OrientDB - Using plocal Embedded Storage from Two Processes

OrientDB has this nice feature of creating and using database in embedded mode. We can programatically create and accesses OrientDB database for CRUD operations without the server. We can create a plocal storage (Paginated Local Storage) with this. plocal is a disk based storage which works with data using page model. This storage is very fast because of we can assess the database directly with local mode.

But, plocal storage has a limitation; it can only be accessed by one process at a time. When a process accesses the database, it locks the database so that no other program or process can access that. This lock will not be released until the program terminates. It avoids updating the database from several processes.
If you are going to accesses the plocal db while another process has acquired the lock, you will have the following error message.

com.orientechnologies.orient.core.exception.OStorageException: Cannot open local storage 'C:/MyOrientDb/dbs/myPlocal' with mode=rw
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:217)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:243)
at com.lakj.comspace.orientdb.PlocalTest.readDb(PlocalTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)...
Caused by: com.orientechnologies.orient.core.exception.OSerializationException: Cannot load database's configuration. The database seems to be corrupted.
at com.orientechnologies.orient.core.storage.impl.local.OStorageConfigurationSegment.load(OStorageConfigurationSegment.java:86)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:164)
... 28 more
Caused by: java.io.IOException: The process cannot access the file because another process has locked a portion of the file
at java.io.RandomAccessFile.read0(Native Method)
at java.io.RandomAccessFile.read(Unknown Source)
at com.orientechnologies.orient.core.storage.fs.OAbstractFile.openChannel(OAbstractFile.java:641)
at com.orientechnologies.orient.core.storage.fs.OAbstractFile.open(OAbstractFile.java:144)
at com.orientechnologies.orient.core.storage.impl.local.OSingleFileSegment.open(OSingleFileSegment.java:57)
at com.orientechnologies.orient.core.storage.impl.local.OStorageConfigurationSegment.load(OStorageConfigurationSegment.java:65)
... 29 more

 I found a solution to this problem!

When you want to share a plocal database among two (or more) processes, you can follow the following procedure.

Let's take a sample scenario. Two processes called Process-A and Process-B are going to access the same plocal storage named 'myPlocal'. Process-A reads the database. Then Process-B update the database and terminates. Then again Process-A reads the database.

Step 1:
Create the db connection from Process-A read the relevant data.
When the Process-A creates the db connection, it locks the db so that any other process cannot read or update the db.
ODatabaseDocumentTx dbProsA = new ODatabaseDocumentTx("plocal:/db/myPlocal");
dbProsA .open("admin", "admin");
Step 2:
Freeze the db from the Process-A.

Freeze method is used to create 'live' database backups. It flushes all cached content to the disk storage and allows to perform only read commands for current process. Here when the Process-A calls freeze method, no any thread from Process-A can write on db. But any thread from Process-A can read from db. More importantly, another process can acquire the db lock and update it. Here the Process-B will do it.
dbProsA .freeze();
Step 3:
Create the db connection from Process-B and read or update data. Then the Process-B terminates.
Because of Process-A has freezed it's connection Process-B can create a new connection and update the db. Here the Process-B should terminate and release the db so that the Process-A can get it back.
ODatabaseDocumentTx dbProsB = new ODatabaseDocumentTx("plocal:/db/myPlocal");
dbProsB.open("admin", "admin");
// Do whatever you want here 
dbProsB.close();
Step 4:
Process-A release the db.
If you freeze the db connection, you should call release method to enable it for write operations.
dbProsA .release();
Step 5:
Process-A restarts the db engine.

This is the most important step. Though you have release the db connection from Process-A, it won't be able to read the updates which has been done by Process-B. You may still read the data which you had at the point you freeze it.
To read the updated values from the Process-B you should re-start the db engine from Process-A. It's just two method calls; shutdown() and start().
OOrient instance = Orient.instance();
instance.shutdown();
instance.startup();
You are done..!
Now you have shared your plocal db between Process-A and Process-B.

Sunday, June 28, 2015

Why Circular Dependencies Between Java Packages are Bad?

No doubt, Circular dependencies between "Modules" (projects, jars, etc..) is BAD.
It has all the consequences which lead to problem in the areas like,

  • Maintainability
  • Re-usability
  • Testability
  • Compilation problems
  • Release and build problems
  • Domino defect
  • Memory leaks

But does it really matter when there are a circular dependencies between packages?


I was searching and reading about this, but i could not find an exact reasonable answer.
So the my opinion is, it's a design concern.

In the OO design principles (SOLID[1] principle) dependency is a major concern[2]. So when we design according to the OO model we should avoid circular dependencies.

Just imagine we are going to apart some packages form the program and maintain the program as a two different modules. Then the circular dependencies would make all the problem i mentioned for module dependencies. Therefore we can say circular dependencies reduces the extensibility of the program.

Packages are used to organize classes belonging to the same category or providing similar functionality[3]. When there is a circular dependency, according to my experience what i can say is, there should be components which represent a certain functionality or a category which can be re-organized to single package. Therefore if we are really following Java OO design guidelines, the circular dependencies should not be present.

Some programming languages (Eg: Go) don't allow circular dependencies (circular imports). But Java allows it. But we should pay the attention on proper OO design and avoid circles.


References:
[1] https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
[2] https://en.wikipedia.org/wiki/Dependency_inversion_principle
[3] https://en.wikipedia.org/wiki/Java_package

Monday, June 8, 2015

OrientDB - com.orientechnologies.common.exception.OException: Error on creation of shared resource

You got the following error...???
I got this error when i tried to connect a local (plocal / embedded) document OrientDB.

Solution: I had added both orientdb-core-*.jar and orientdb-client-*.jar libraries to the class path. I just removed  orientdb-client-*.jar. Then the error solved.

I don't know the exact reason for this problem. But in the OrientDB Document API document, it has been mentioned that  orientdb-client-*.jar is for connecting to a remote server. Therefore, orientdb-client-*.jar is not required to creating connections to plocal DB instances.


com.orientechnologies.common.exception.OException: Error on creation of shared resource
at com.orientechnologies.common.concur.resource.OSharedContainerImpl.getResource(OSharedContainerImpl.java:55)
at com.orientechnologies.orient.core.metadata.OMetadataDefault.init(OMetadataDefault.java:175)
at com.orientechnologies.orient.core.metadata.OMetadataDefault.load(OMetadataDefault.java:77)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.initAtFirstOpen(ODatabaseDocumentTx.java:2633)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:254)
at com.lakj.comspace.orient.db.data.DBHandler.getData(DBHandler.java:51)
at com.lakj.comspace.orient.db.data.DBHandlerTest.testDBHandler(DBHandlerTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: com.orientechnologies.orient.core.exception.ORecordNotFoundException: The record with id '#0:1' not found
at com.orientechnologies.orient.core.record.ORecordAbstract.reload(ORecordAbstract.java:266)
at com.orientechnologies.orient.core.record.impl.ODocument.reload(ODocument.java:665)
at com.orientechnologies.orient.core.type.ODocumentWrapper.reload(ODocumentWrapper.java:91)
at com.orientechnologies.orient.core.type.ODocumentWrapperNoClass.reload(ODocumentWrapperNoClass.java:73)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.load(OSchemaShared.java:786)
at com.orientechnologies.orient.core.metadata.OMetadataDefault$1.call(OMetadataDefault.java:180)
at com.orientechnologies.orient.core.metadata.OMetadataDefault$1.call(OMetadataDefault.java:175)
at com.orientechnologies.common.concur.resource.OSharedContainerImpl.getResource(OSharedContainerImpl.java:53)
... 30 more
Caused by: com.orientechnologies.orient.core.exception.ODatabaseException: Error on retrieving record #0:1 (cluster: internal)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.executeReadRecord(ODatabaseDocumentTx.java:1605)
at com.orientechnologies.orient.core.tx.OTransactionNoTx.loadRecord(OTransactionNoTx.java:80)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.reload(ODatabaseDocumentTx.java:1453)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.reload(ODatabaseDocumentTx.java:117)
at com.orientechnologies.orient.core.record.ORecordAbstract.reload(ORecordAbstract.java:260)
... 37 more
Caused by: java.lang.NoSuchMethodError: com.orientechnologies.common.concur.lock.ONewLockManager.tryAcquireSharedLock(Ljava/lang/Object;J)Z
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.acquireReadLock(OAbstractPaginatedStorage.java:1301)
at com.orientechnologies.orient.core.tx.OTransactionAbstract.lockRecord(OTransactionAbstract.java:120)
at com.orientechnologies.orient.core.id.ORecordId.lock(ORecordId.java:282)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.lockRecord(OAbstractPaginatedStorage.java:1779)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.readRecord(OAbstractPaginatedStorage.java:1425)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.readRecord(OAbstractPaginatedStorage.java:697)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.executeReadRecord(ODatabaseDocumentTx.java:1572)
... 41 more

Thursday, March 5, 2015

IntelliJ Plugin Development Tutorial - Get All Packages of a Module

This tutorial shows you how to get all the packages of a selected module in the IntelliJ IDE. When you run this plugin you will have an action button in project viewer. When you right click on a module and click the  "Lak J Show All Packages Action", a message window will show the all package names.

Following are the two files you want work with to create this plugin.

Following are the GitHub URL's for complete plugin project. You can clone the project or downolad the project as a zip file. To run the project open IntelliJ IDEA and import the project.

GitHub repository URL - https://github.com/lakjcomspace/IntelliJGetModulePackages
GitHub HTTPS clone URL - https://github.com/lakjcomspace/IntelliJGetModulePackages.git
Download Project as a Zip - https://github.com/lakjcomspace/IntelliJGetModulePackages/archive/master.zip


Sunday, January 25, 2015

IntelliJ Plugin Development Tutorial - Project View Popup Menu Action Item

This simple tutorial shows you how to create an Action Item in the Project View Popup Menu.
When  you right click on the project view you will have this action item in the popup menu. You can extend or use this to execute any action.

 Following are the two files you should work with.

Following are the GitHub URL's for complete plugin project. You can clone the project or downolad the project as a zip file. To run the project open IntelliJ IDEA and import the project.

GitHub repository URL - https://github.com/lakjcomspace/IntelliJProjectViewMenuAction
GitHub HTTPS clone URL - https://github.com/lakjcomspace/IntelliJProjectViewMenuAction.git
Download Project as a Zip - https://github.com/lakjcomspace/IntelliJProjectViewMenuAction/archive/master.zip



Wednesday, January 7, 2015

Android Client-Server Chat Application

This is a simple Android chat application which communicate with a Java server program. This tutorial will help you to understand socket programming in Android which sends information both ways.
To run this application, first execute the server program. You can run this application in your PC.

Then execute the client program. You can use your Android emulator or your Android device. If you are using Android emulator you can use IP address 10.0.2.2 to connect your sever which is running in the same computer. But if you are using an Android device you may have to change the IP address in the client app code according to your network configuration.
Once you execute the client app, the chat window will be opened in the server program. Type the message on the chat box and press "Send" button. The message will be appeared in the other end.

      
Android Chat App
 
Server Program





                                                         









                                                                                   
Following are the source codes of the main components of both programs.

Android Chat Application


Server Program


Following are the both Android client and Java server complete projects. You can clone or download them as zips from Git-Hub.

Git-Hub HTTPS clone URL: https://github.com/lakjcomspace/AndroidChatClientServer.git
Git-Hub Repository URL: https://github.com/lakjcomspace/AndroidChatClientServer
Download as a Zip: https://github.com/lakjcomspace/AndroidChatClientServer/archive/master.zip

You can run the projects by importing them to the IDE. Or just create you own project and copy and paste above source files.

Saturday, December 20, 2014

IntelliJ Plugin Development Tutorial - Hello World Plugin

This is a very simple example plugin for IntelliJ IDEA plugin development. You can create this plugin in less than 10 minuets.
This plugin creates a menu bar item called "Hello World". Under that there is an option called "Say Hello". When you click on that option you will see a message window.

Following are the two files you should work with.

When you click on the action item "Say Hello" the method called actionPerformed is executed and the message will be displayed.

Following are the GitHub URL's for complete plugin project. You can clone the project or downolad the project as a zip file. To run the project open IntelliJ IDEA and import the project.

GitHub repository URL - https://github.com/lakjcomspace/IntelliJHelloWorld
GitHub HTTPS clone URL - https://github.com/lakjcomspace/IntelliJHelloWorld.git
Download Project as a Zip - https://github.com/lakjcomspace/IntelliJHelloWorld/archive/master.zip



Sunday, October 5, 2014

Android USB Debugging in Huawei Tab

If you are writing android applications you may definitely do USB debugging. In case you don't know the the term, USB debugging (On-device Developer Option) is using a real android device to debug your android application by connecting it through USB port.
In this blog post i am going to explain you how to use your Huawei android tab for USB debugging. I have tested this with a  "Huawei Mediapad 7 Lite".


On Android developer guide it has been mentioned that we have to install USB driver software for this, but you may not able to find the relevant driver software for Huawei.
In our case, more interesting thing is you don't want to bother for finding driver software. Lets do this step by step.

1. Declare your application as "debuggable" in your Android Manifest.
If you are using Eclipse, this may have been automatically declared. Otherwise go to AndroidManifest.xml and add android:debuggable="true" to the <application> element.

2. Enable USB debugging on your device.
Go to Settings > Developer options. (For  Android 3.2 or older Settings > Applications > Development)
Developer options is hidden by default on Android 4.2 and newer. To un-hide it, go to Settings > About phone and tap Build number seven times. Then go back to the previous screen to find Developer options.

3. Plug your device to your PC using the USB cable.
The device will notice you that you have connected the dive to the PC.

4. Click on the notification bar of the device (Where are time/battery/signal information are). On the pop-up menu you may see the USB connection type. Probably it would be "Connected as a media device".
If you have properly activated the USB debugging mode, it may also be shown as "USB debugging connected".

5. Click the "Connected as a media device" option (Or any other "Touch for other USB option" menu item). You may be navigated to a "Connect As" menu in the Settings > Storage menu.
There select the "HiSuite" option. You will be notified the action. Your device UI will change to HiSuite UI.

6. Now move to your PC. Navigate to the device from the PC file browser (If you are using Windows OS go to Computer > HiSuite in removable storage category).

7. There you may find the HiSuiteSetup.exe file and double click and install the software.

8. Once it is installed, you are done!

9. Remove the device and plug the device again. Make sure you have connected the device as "Connected to HiSuite". The HiSuite software will automatically start-up on your PC.

You can verify that your device is properly connected  by executing adb devices from your Android SDK platform-tools/ directory.

Following is the UI of the HiSuite PC software. Using this software you can do many things related to your Huawei Android device (Not only USB debugging).


Saturday, August 23, 2014

Share Laptop Internet Connection With Android Device


Without using any software you can simply crate a wifi hotspot in Windows.

1. Open command prompt with administrator privileges. (Right click -> Run as administrator).

2. Enter following command to create the connection.
netsh wlan set hostednetwork mode=allow ssid=MyWifiName key=myPassword

Here you can give any values for 'ssid' and 'key'. ssid will be you wifi connection name and key will be the password.

3. Enter following command to start the network.
netsh wlan start hostednetwork

Make sure you have turn on wifi on your laptop. Otherwise you will be getting a message like following.
The hosted network couldn't be started.
A device attached to the system is not functioning.

When everything is properly configured, your command prompt would look like following.



4. Now open the "Network and Sharing Center" (Click internet connectivity icon on the task bar and open Network and Sharing Center or Go to control panel and click network and internet related options).
Click the "Change adapter setting" option in right hand-side of the window.
There you will see all your network connections also with our newly created network connection "MyWifiName".

5. This step is very impotent. Right click on you current internet connection icon (not on your MyWifiName icon). Click on the "Sharing" tab in the window you are getting. There tick the option "Allow other network users to connect through this computer's internet connection".
Then select your newly created MyWifiName connection as the "Home networking connection" in the drop down. There you won't have the name MyWifiName but the title name related to that connection. You can get that title name from Change adapter setting window. Click ok button.

6. Now you are done!

Turn on your Android or any device and connect to MyWifiName wifi hotspot using the password myPassword.

To turn off the network you created, enter the following command

netsh wlan stop hostednetwork


Monday, May 5, 2014

Simple Android Client-Server Application

This is an android application which sends a text message to a server. When you press the send button, the application sends the message in the text field to the server program. Here the program been written so that the client runs on the Android emulator and the server runs on the local host. IP address 10.0.2.2  can be used to connect to the local host with Android. Server program is continuously listening to the port 4444. When an incoming message arrived, server read it and show it on the standard output.
This tutorial is based on Android 4.4 (API Level 19 - KITKAT) version.



Following are the source codes of main components.

Android Text Client Application




Java Sever Program



Following are the both Android client and Java server complete projects. You can clone or download them as zips from Git-Hub.

Git-Hub HTTPS clone URL: https://github.com/lakjcomspace/AndroidTextClientServer.git
Git-Hub Repository URL: https://github.com/lakjcomspace/AndroidTextClientServer
Download as a Zip: https://github.com/lakjcomspace/AndroidTextClientServer/archive/master.zip
You can run the projects by importing them to the IDE. Or just create you own project and copy and paste above source files.

Tuesday, April 22, 2014

Start-Up, Shutdown or Restart the Tomcat Server Using an Ant build.xml


Following Ant build script can be used to start, stop or restart your Tomcat server. First you should set the property "tomcat.home" to your Tomcat home directory. Then when you just execute the "ant" command, it will restart your running server.
Here are all the commands you can use with this script.

Start Up:    "ant tomcat-start"
Shutdown:  "ant tomcat-stop"
Restart:      "ant" or "ant tomcat-restart"

Depending on the web application you are running, you may be getting an Out of Memory PermGen space error. If so, remove the comment marks and enable jvm argument <jvmarg value="-XX:MaxPermSize=256m"/> in the script (line 16).


Sunday, August 11, 2013

Erase Some Characters from Each Line of a Text File - Java Program

Following Java program erase user given fixed number of characters from each line of a text file. Here the number of characters to be erased is 3. For the convenience input and output files are given as two separate file.  Output file may contain the result you want.



Wednesday, February 20, 2013

How to Create a Local SVN Repository



Apache Subversion (SVN) is a software versioning and revision control system which is widely used in software industry. SVN is very useful when we create important and huge code over a time period. Because,    whatever change happened, we can go back to  our previous versions of the code. And other important feature is we can mange our huge source code with a huge development team. Normally, we install SVN in a server machine.

But we can create an SVN repository in our own computer and we can mange our code locally. It is very simple and there are only few steps to complete.

First You have to install SVN in your computer. Here you can find the way to install. After installing, type the following command in the command line consecutively. This example is based on Linux OS.

mkdir /home/user/svndir  - This will create a directory called 'svndir'.

cd /home/user/svndir -  Go inside that directory.

svnadmin create mylocalrepo - 'mylocalrepo' is the name of your repository.

svn mkdir file:///home/user/svndir/mylocalrepo/myproject  - You create a directory called 'myproject' inside your repository.

svn import /home/user/HelloWorld file:///home/user/svndir/mylocalrepo/myproject - You enter your 'HelloWorld' porject in to the local repository 'myproject' directory.

Now you are done..!

You can check your local repository content by executing following command. 
svn list --verbose file:///home/user/svndir/mylocalrepo

You can use all the SVN command which has been listed here
As an example, when you want to check out your project to your workspace type following command.
svn co file:///home/user/svndir/mylocalrepo/myproject /home/user/workspace

Friday, June 29, 2012

How to Install Apache Ant


Its really simple.
1. Make sure you have java environment installed in your system.
2. Download Ant binary distribution form here.
3. Uncompress the file downloaded.
4. Set the environment variables.
         Click new button to add new environment variable. Type "ANT_HOME" as the variable name and give the path of the directory where you uncompress Ant as the value. Then edit the path variable. For Windows add %ANT_HOME%/bin and for Linux add ${ANT_HOME}/bin to the value value of the path variable. At the end the value of the path variable should be shown like this. C:\Program Files\Java\jdk1.6.0_22\bin ; %ANT_HOME%/bin.
5. Click OK and save all the changes.

Now your are ready to use Apache Ant.
You can make sure that Ant is installed correctly by executing the command 
ant -version in command prompt. If it is installed correctly it should show the version information of Ant distribution. 

Friday, June 22, 2012

Apache Ant - Java-Based Build Tool

                 

                  Apache Ant is a powerful Java-based build tool which automates the building process of a project. Mainly Ant is used to build Java applications. But It supports many program application like C, C++, Python etc. Ant can be used to many purposes. If we want to get the results of several programs which is written and executed in different languages we can use ant to do that.
                 We can configure Ant project by using "build.xml". "build.xml" is normal xml file. There we can define all the tasks, properties and variable which are used in the build process. Ant has lost of free defined tasks. Also We can define our own task.
                  After preparing the build.xml file we can simply execute "ant" command in command prompt of terminal. Then it builds the project.
                  Ant support both Windows and Linux platforms. You cant download the binary distribution of Ant form here. For more information you can refer the Apache Ant Project Site.
I hope to bring you series of post about Apache Ant.