Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Thursday 24 October 2013

Installing the Java Plugin for Firefox on CentOS

The OpenJDK bundled with CentOS is missing a java plugin for Firefox. A simple method of getting Java to run inside the webbrowser and to run java applications is to install icedtea-web

Open a terminal and type the below command

yum install icedtea-web

Then restart your browser
Click Tools- >Add-ons
The Add-ons Manager tab will open.
In the Add-ons Manager tab, select Plugins
Click icedtea-web plugin to select it and click on the Enable button

The java verification applet (http://www.javatester.org/version.html) works fine.

Installing and configuring Java in cent OS

Most of the Linux operating systems comes with pre-installed OpenJDK package to run java-based applications and plugins.But in certain cases we need Sun/Oracle Java program to compile and run
particular development applications.

1. Download java from  
http://www.oracle.com/technetwork/java/javase/downloads/index.html

2. install java using rpm -uvh
   ## Install Java on 32-Bit OS ##
   # rpm -Uvh jdk-7u45-linux-i586.rpm
   # rpm -Uvh jdk-7u45-linux-i586.rpm

   ## Install Java on 64-Bit OS ##
   # rpm -Uvh jdk-7u45-linux-x64.rpm
   # rpm -Uvh jdk-7u45-linux-x64.rpm

3. check java installed
   # java -version

   output should be
   java version "1.7.0_45"

4. Setting up java environment variables
The easiest way to set an environment variable in CentOS is to use export as in

$> export JAVA_HOME=/usr/java/jdk.1.7.0_45

$> export PATH=$PATH:$JAVA_HOME

However, variables will disappear the moment you exit the shell. Obviously this is not helpful when setting environment variables that need to persist even when the system reboots.In such cases, you need to set the variables within the system wide profile. In CentOS , the folder /etc/profile.d/ is the recommended place to add  customizations to the system profile.

5. Create a new file called java.sh
vim /etc/profile.d/java.sh

6. Copy paste the below content in java.sh

export JRE_HOME=/usr/java/jdk.1.7.0_45/jre
export PATH=$PATH:$JRE_HOME/bin
export JAVA_HOME=/usr/java/jdk.1.7.0_45
export JAVA_PATH=$JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin

7.  If you want to load the environment variables within java.sh without having  to restart the machine, you can use the source command as in:
   $> source java.sh

Wednesday 12 June 2013

The import javax.servlet can't be resolved

Error : The import javax.servlet can't be resolved in eclipse

Soultion

You need to add the Servlet API to your classpath. In Tomcat 7.0, this is in a JAR called servlet-api.jar in Tomcat's lib folder.
steps to add the JAR into your project class path.

Right-click the project, click Properties.
Choose Java Build Path.
Click Add External JARs
Browse to find servlet-api.jar and select it.
Click OK to update the build path.
Clean and build the project

Thursday 16 May 2013

java.lang.classnotfoundexception com.mysql.jdbc.driver in jsp

Issue


When i try to have simple jdbc connection to mysql  in my jsp file, i get following console output in eclipse:
console output in eclipse:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

When i tried to have the same kind of connection from a simple java file it was working.

Solution

You should put the mysql connector JAR file in WEB-INF/lib directory of your project. Clean Build the project and restart the server.


Add Mysql connector in eclipse classpath

Add Mysql connector in eclipse classpath

1. Download mysql connector jar from
http://dev.mysql.com/downloads/connector/j/
2. Open eclipse in java EE perspective (top right corner)
3. Right click the project go to Properties.
4. Choose Java Build Path and then Select Libraries tab
5. Click Add External JARs  and add the path of the mysql connector jar
6. Click Ok button and clean and build the project














Properties window for my java project

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver error

Issue

When I try connect my java program to mysql database using eclipse,i am getting the run time error
 "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver"

Solution

The reason for the error is you don't have mysql-connector.jar in your Classpath. This jar
contains "com.mysql.jdbc.Driver" class and it must be present in java classpath in order to successful connection to mysql database.
you can downlad mysql-connector.jar from
http://dev.mysql.com/downloads/connector/j/

Click here for adding mysql connector jar to eclipseclass path




Friday 15 March 2013

Setting java path in linux

After installing JDK or JRE on Linux/Unix platform, you have to set PATH environment variable so that you can run the executables (javac.exe, java.exe, javadoc.exe, and so on) from any directory without having to type the full path of the command.
 
 Steps to set up java path in linux

1. Create a java.sh file in /etc/profile.d directory with content as follows: 
 
#!/bin/bash
           
JAVA_HOME=/usr/java/jdk1.7.0_17
                    
PATH=$JAVA_HOME/bin:$PATH
                                       
export PATH JAVA_HOME
 
The file contains various shell commands which set and export necessary environment variables for Java. Shell settings from configuration files in the /etc/profile.d directory are gathered by/etc/profile during login, setting up user environment information for every user.  
 
2.  Assign execute permissions:
 
# chmod 755 java.sh

3. You can verify the path  by typing the below command in the terminal

# java -version