Configure the Java web development environment in Linux

Source: Internet
Author: User
Tags localhost mysql
1. to build an environment, you must use JAVA to develop Web applications. you must use a JAVA runtime environment and a development environment. Of course, databases are indispensable for Web development. Web programs must run without Web servers. Here we use the JAVA Runtime Environment: J2SDk1.4 database: Mysql4.0.15Web server: atat4.1.181.1java runtime environment first we need to build 1 environment
To develop Web applications using JAVA, you must have a JAVA runtime environment and a development environment. Of course, databases are indispensable for Web development. Web programs must run without Web servers.
Here we use the JAVA Runtime Environment: J2SDk1.4
Database: Mysql 4.0.15
Web server: Tomcat 4.1.18
1.1 JAVA Runtime Environment
The first step is to build a JAVA Runtime Environment. To Sun
Run the binary file to decompress the file:
[Root @ localhost jdk] #./j2sdk-1_4_2_05-linux-i586.bin
After decompression, you can find the j2sdk1.4.2 _ 05 directory under the current directory.
For convenience, you can make a simple connection to this directory.
[Root @ localhost jdk] # ln? S j2sdk1.4.2 _ 05 jdk
Then add the environment variable
Export JVAV_HOME =/var/jdk/jdk1.4
Export CLASSPATH = $ JAVA_HOME/lib: $ JAVA_HOME/jre/lib :.
Export PATH = $ PATH: $ JAVA_HOME/bin: $ JAVA_HOME/jre/bin
Now the JAVA Runtime Environment has been set up. you can try to write a java program for verification.
[Root @ localhost jdk] # vi HelloWorld. java
Enter the following content:
Public class HelloWorld {
Public static void main (String args []) {
System. out. println ("Hello, Wrold ");
}
}
: Wq
Write disk and exit editor
[Root @ localhost jdk] # javac HelloWorld. java
No errors
[Root @ localhost jdk] # java HelloWorld
Hello, World
Congratulations, your JAVA runtime environment has been set up. Now proceed to the next step.
1.2 Mysql database installation
1. download the database installation file Mysql-4.0.15a.tar.gz
2. create MySLQL users and groups
[Root @ localhost var] # groupadd mysql
[Root @ localhost var] # useradd? G mysql
3. modify the. bash_profile file under the root directory to add the PATH environment variable.
[Root @ localhost root] # vi. bash_profile
PATH = $ PATH: $ HOME/bin:/usr/local/mysql/bin
Save and exit
The following figure shows how to install MySql.
4. decompress the file
[Root @ localhost jdk] # tar xzvf mysql-4.0.15a.tar.gz
Enter the decompressed directory.
[Root @ localhost var] # cd mysql-4.0.15a
5. configure the release version and compile
[Root @ localhost mysql-4.0.15a] #./configure -- prefix =/usr/local/mysql
[Root @ localhost mysql-4.0.15a] # make
When you run configure, you may want to specify some options. the -- prefix option indicates that the directory for installing mysql is/usr/local/mysql.
6. install everything
[Root @ localhost mysql-4.0.15a] # make install
You may need the root user to run this command.
OK. Now the mysql database server is installed. Next, we need to perform the following important steps:
7. create a MySQL authorization table (only you have not installed MySQL before ):
[Root @ localhost mysql-4.0.15a] # scripts/mysql_install_db
8. after completing the above steps, we can start mysql.
[Root @ localhost mysql-4.0.15a] # cd/usr/local/mysql/bin
[Root @ localhost bin] #./mysqld_safe &
If no error message is displayed, check the mysql process.
[Root @ localhost bin] # ps aux | grep mysql
Root 1205 0.0 0.0 5388 168? S Apr22 0: 00/bin/sh/usr/loca
L/mysql/bin/mysqld_safe
Mysql 1227 0.0 1.3 10031613756? S Apr22 0: 36 [mysqld]
Root 22956 0.0 0.0 4816 640 pts/1 S grep mysql
The process in bold is mysql.
Now you can use mysql and use root to log on to the MySQL server.
[Root @ localhost bin] # mysql? U root? P
The system prompts that the default root user password is empty. Just press enter.
Enter password:
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 95 to server version: 4.0.15a-log
Type 'help; 'or' \ H' for help. Type '\ C' to clear thebuffer.
Mysql>
In this way, the MySQL server is successfully logged on.
Mysql> show databases;
+ ---------- +
| Database |
+ ---------- +
| Cumt |
| Mysql |
| Test |
+ ---------- +
3 rows in set (0.01 sec)
Now you can create a database. Here we will not describe how to create a database and a table.
It is insecure if the Root user does not have a password. Therefore, you need to modify the root user password.
[Root @ localhost bin] # mysqladmin-u root password 'new-password'
Replace 'new-password' with your own password.
Note: After completing the above steps, we can use mysql in the bin directory of mysql to manage the database. However, the database cannot be used in the program. When I connect to the database in jsp, the following error occurs:
Java. SQL. SQLException: Data source rejected establishment ofconnection, message from server: "Host 'localhost. localdomain 'is not allowed to connect to this MySQLserver"
This is a MySQL permission issue. for details, refer to the access permission system in the MySQL Reference Manual.
What we need to do is to allow the root user to connect to the database from localhost. you can also establish a new user to connect to the database.
Log on to the mysql server
Mysql> grant all privileges on *. * TO cumt @ localhost
Identified by 'cumt' with grant option;
Mysql> grant all privileges on *. * TO cumt @ "%"
Identified by 'cumt' with grant option;
In the past two days, the user cumt is added to the sentence so that it can connect to a full Super user on the server from anywhere, but a password cumt must be used for this. Now we can use cumt in the program to connect to the database.
However, you still do not have the write permission for the table in the program. This is because our database user is root rather than the mysql user in the mysql group we created. Therefore, you only have the read permission but not the write permission. We need to change the directory and file owner under the var directory under the mysql directory to the myql user in the mysql group:
[Root @ localhost bin] # chown-R mysql/usr/local/mysql/var
[Root @ localhost bin] # cp support-files/my-medium.cnf/etc/my. cnf
After completing the above steps, we can use cumt in the program to connect to the database and operate the database.
1.3 Web server tomcat installation configuration
Download tomcat,jakarta-tomcat-4.1.18.tar.gz
Extract
Root @ localhost var] # tar xzvf jakarta-tomcat-4.1.18.tar.gz
For easy operation:
Ln-s jakarta-tomcat-4.0.1 tomcat
Ln-s j2sdk1.4.0 jdk
Modify Tomcat/bin/startup. sh:
Export JAVA_HOME =/usr/local/jdk
Export CLASSPATH = $ JAVA_HOME/lib: $ JAVA_HOME/jre/lib :.
Export PATH = $ PATH: $ JAVA_HOME/bin: $ JAVA_HOME/jre/bin
/Usr/local/tomcat/bin/catalina. sh start
Start Tomcat/bin/startup. sh
1. Use ps-ax | grep tomcat to query the existence of tomcat programs in the memory.
Use http: // your server domain name or IP address or localhost: 8080/accessible
2. if the system is required to boot automatically, add tomcat to/etc/rc. d/rc. local:
/Usr/local/tomcat/bin/startup. sh
3. for the linux7.1 system, tomcat does not seem to be able to start normally and needs to be installed:
Compat-libstdc ++-6.2-2.9.0.14.i386.rpm
Rpm-I compat-libstdc +++-6.2-2.9.0.14.i386.rpm
4. if you want to access your jsp program with http://www.xxx.com: 8080/myweb, follow these steps:
(1) create a directory in any place, for example,/home/bqlr/myweb.
(2). create a WEB-INF and WEB-INF/classes directory under myweb
(3) modify server. xml in the conf directory of tomcat:




(4) create a directory to connect to myweb under the webapps directory of tomcat
Ln-s/home/bqlr/myweb/usr/local/tomcat/webapps/myweb
(5) restart Tomcat. class file put in/home/bqlr/myweb/WEB-INF/classes directory jsp file put in/home/bqlr/myweb
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.