Monday, March 30, 2015

Solution for "Initialized java loader error" in mysql Migration toolkit



















Step 1: Open the command prompt. Change to the mysql tools installation path (path will be vary based on the installed Mysql version)

         C:\Documents and Settings\System14>cd C:\Program Files\MySQL\MySQL Tools for 5.0

Step 2: And then type the following command(jvm.dll path will be vary based on the installed java version)

           C:\Program Files\MySQL\MySQL Tools for 5.0>MySQLMigrationTool -verbose 
           -jvm    "C:\Program Files\Java\jre7\bin\client\jvm.dll"

The java loader initialized successfully..

Saturday, March 14, 2015

How to Create Dynamic Web Project using Maven in Eclipse?

Apache Maven Tips
Today I want to talk about Maven. It’s very powerful instrument and if you know how to use it you will make minimum effort to achieve maximum result. In general Maven helps you to manage a project including library dependencies, building process and etc…apacheMaven - Crunchifiy
Here is a simple tutorial which you can go through to create Dynamic Web Project having Maven enabled in Eclipse. This project can be used as base project and can be easily converted to most kind of advanced Java project like Spring MVC based etc. How to create a Web Application Project with Maven?

Tools I’m using:

  • Eclipse EE
  • Maven
  • JSK 1.7
  • M2Eclipse Plugin

Assumption:

You have setup Maven and Apache Tomcat Server successfully in your Eclipse Environment.

Step-1

Create a simple maven Project in Eclipse.
Create Simple Maven Project in Eclipse

Step-2

Select default Workspace location
Use Default Workspace Location

Step-3

Select the maven archetype as: maven-archetype-webapp and click on next.
Select maven-archetype-webapp

Step-4

Fill out below details and click Finish. This step created Maven Project in your Eclipse Environment.
Create Crunchify Maven Project in Eclipse

Step-5

If you see error “The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path index.jsp /CrunchifyMavenTutorial/src/main/webapp” then add Apache Tomcat to your Targeted Runtimes.
HTTPServlet Error? Add Target Runtime
Targeted Runtime - Apache Tomcat

Step-6

Your Maven Project should look like this.
CrunchifyMavenTutorial Eclipse Structure

Step-7

Now build project with “Maven Clean Install” to check there isn’t any dependency issue with project. Crunchify - Maven-RunAs-MavenBuild...
Maven Clean Install in Eclipse
Maven Build Successmessage in Eclipse Console

Step-8

Deploy Application on Apache Tomcat Server.
Steps:
  • Right click on Server -> Add and Remove -> Select CrunchifyMavenTutorial -> Click Finish.
  • Start tomcat server.

Step-9

Visit http://localhost:8080/CrunchifyMavenTutorial/index.jsp to see your result.
CrunchifyMavenTutorial Web Result
And you are all set.
Have anything to add to this article? Please chime in and join the conversion.

Friday, March 13, 2015

INSTALLING M2ECLIPSE – MAVEN PLUGIN FOR ECLIPSE

In this tutorial, we will see how to install m2eclipse plugin which provides Maven integration in Eclipse IDE. m2eclipse provides first-class Apache Maven support in the Eclipse IDE, making it easier to edit Maven’s pom.xml, run a build from the IDE and much more.

Environment Used

  • Java SE 6
  • Eclipse Juno for Java EE Developers (4.2) IDE
  • Maven Eclipse Plugin – m2eclipse version 1.2

Installing JDK

JDK should be installed with proper environment set up. Read this page for installing the JDK and setting up the environment.

Installing Eclipse IDE

Make sure you have Eclipse IDE installed. If you need to install Eclipse, you can read this page.

Online Installation (From Update Site) of Maven Plugin m2eclipse

You can install Maven plugin for Eclipse via update site, simply copy the above update site link address and paste it into Eclipse’s “Update” or “Install New Software” manager as explained below.

Step 1:

Installing m2eclipse is fairly simple. Start Eclipse then go to:
Help -> Install New Software…
Copy this link http://download.eclipse.org/technology/m2e/releases for the latest Stable Release into Eclipse and hit Enter.
When the site loads, select the features to install, or click the Select All button. For our requirement select “Maven Integration for Eclipse” as shown above.
Checking [x] Contact all update sites during install to find required software might take sometime and this is optional.

Step 2:

  • Click Next to view Installation Details.
  • Click Next to agree the license terms, and click Finish.

Step 3:

If you get any warning message when installing, click OK to continue.
This will take few minutes to install the Maven plugin and once done restart the Eclipse.

Creating New Maven Project in Eclipse

After installing the Maven plugin for Eclipse, you can check if the installation is successful by creating a new Maven project.
You should see a Maven folder in the New project wizard as shown below.
Now you have successfully installed “Maven plugin – m2eclipse” in Eclipse IDE.

Thursday, March 12, 2015

How to automatically deploy maven project from eclipse to tomcat

There are two plugins that combined together in Eclipse work quite well together to perform what you want:
  1. M2E: M2Eclipse which handles everything related to Maven.
  2. Eclipse Web Tool Platform (WTP): which handles everything Java EE related (Tomcat, JBoss, etc...)
For M2E to work properly with WTP, you need to add m2e-wtp. You may find several useful information as well as some good links here.
I would start from the Eclipse Java EE distribution (it includes already Eclipse-WTP) and then add M2E (either with their update site or through eclipse market place: look for M2E and M2E-WTP).
From there, you create a Web Project and you can run it on a Tomcat server. The first time you try to run you project on a server, you will install Tomcat and it will appear in view named "Server". Double click on the server to configure ports, automatic deployment etc...

Monday, February 23, 2015

How to create a maven project

mvn -X  archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=com.hordine  -DartifactId=hordineCmdTwitter
 
 
mvn eclipse:eclipse
 
 
mvn package
 
mvn clean install  


Thursday, February 12, 2015

Parsing JSON string in Java

Here is the fully working and tested corrected code:
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class ShowActivity {


  private final static String JSON_DATA =
     "{" 
   + "  \"geodata\": [" 
   + "    {" 
   + "      \"id\": \"1\"," 
   + "      \"name\": \"Julie Sherman\","                  
   + "      \"gender\" : \"female\"," 
   + "      \"latitude\" : \"37.33774833333334\"," 
   + "      \"longitude\" : \"-121.88670166666667\""
   + "    }," 
   + "    {" 
   + "      \"id\": \"2\"," 
   + "      \"name\": \"Johnny Depp\","          
   + "      \"gender\" : \"male\"," 
   + "      \"latitude\" : \"37.336453\"," 
   + "      \"longitude\" : \"-121.884985\""
   + "    }" 
   + "  ]" 
   + "}"; 

  public static void main(final String[] argv) throws JSONException {
    final JSONObject obj = new JSONObject(JSON_DATA);
    final JSONArray geodata = obj.getJSONArray("geodata");
    final int n = geodata.length();
    for (int i = 0; i < n; ++i) {
      final JSONObject person = geodata.getJSONObject(i);
      System.out.println(person.getInt("id"));
      System.out.println(person.getString("name"));
      System.out.println(person.getString("gender"));
      System.out.println(person.getDouble("latitude"));
      System.out.println(person.getDouble("longitude"));
    }
  }
}
 
 
 
 
Here's the output:
C:\dev\scrap>java -cp json.jar;. ShowActivity 1 Julie Sherman female 37.33774833333334 -121.88670166666667 2 Johnny Depp male 37.336453 -121.884985
 

Wednesday, February 11, 2015

Parse JavaScript with jsoup

Document doc = Jsoup.parse(html);

Element script = doc.select("script").first();