Deploy and run Java projects on Linux

Source: Internet
Author: User

Address: http://www.svn8.com/linux/accidence/20091015/10740.html

I. Environment Introduction:

Securecrt5.1 + WINXP + wmware + RedHat

NOTE: If securecrt cannot connect to Linux on the virtual machine, you should pay attention to two places. One is whether the NIC on the virtual machine is bridging or directly connected to the physical Nic, whether the IP address is in the same network segment as the IP address of the XP Server. if Linux on a virtual machine can access the Internet, but it cannot be connected, enter services iptables stop on the Linux terminal.

 

2. Install JDK on Linux

Go to the Java official website next suitable for Linux JDK, we next jdk-6u4-linux-i586.bin here, use securecrt to connect to Linux, enter the directory we will put JDK, enter RZ, in the pop-up dialog box, select JDK next to us to upload it to Linux. use the LS command to check whether the file is uploaded, and then add executable permissions to the file: chmod + x jdk-6u4-linux-i586.bin, and then execute the file :. jdk-6u4-linux-i586.bin then you will see the JDK installation information. if you want to enter yes or no, enter yes. after the installation is complete, configure the Java environment variable, modify the/etc/profile file: VI/etc/proifle, press the letter A to enter the insertion mode, and add the following lines at the end:

Path = $ path:/usr/Java/jdk1.6/bin
Export path
Java_home =/usr/Java/jdk1.6
Export java_home

Press ESC and enter WQ to press enter to save the file. Enter Java-version on the terminal and press Enter. If the following information appears, it indicates that JDK has been installed successfully.

Java version "1.6.0 _ 04"
Java (TM) se Runtime Environment (build 1.6.0 _ 04-b12)
Java hotspot (TM) Client VM (build 10.0-b19, mixed mode, sharing)

 

3. Write a Java program and identify the recorded log: svn8.com

Create a project using Eclipse: The linuxtest package structure is as follows:

-- Linuxtest/src/COM/Dao/appdao. Java
-- Linuxtest/src/COM/main/Main. Java
-- Linuxtest/src/log4j. Properties

The content of these three files is as follows:

Appdao:
Java: Package com. Dao;

Import org. Apache. log4j. Logger;

Public class appdao {
Private Static final logger = logger. getlogger (appdao. Class );

Public void show (){
Logger.info ("this is info message ");
Logger. debug ("this is debug message ");
Logger. Error ("this is error message ");
Logger. Fatal ("this is fatal message ");

}

}

Main. Java:
Package com. Main;

Import com. Dao. appdao;

Public class main {

Public static void main (string [] ARGs ){
Appdao Dao = new appdao ();
Dao. Show ();
}

}

Log4j. Properties

Log4j. rootlogger = debug, console
Log4j.addivity.org. Apache = true
Log4j. appender. Console = org. Apache. log4j. leleappender
Log4j. appender. Threshold = debug
Log4j. appender. Console. Target = system. Out
Log4j. appender. Console. layout = org. Apache. log4j. patternlayout
Log4j. appender. Console. layout. conversionpattern = [framework] % d
-% C-%-4r [% T] %-5 p % C % x-% m % N
# Log4j. appender. Console. layout. conversionpattern = [start] % d {date}
[Date] % N % P [Priority] % N % x [NDC] % N % T [thread] n % C [category] % N % m [Message] % N % n

Add required jar package: commons-logging-1.1.1.jar log4j-1.2.8.jar

4. Package the program into a jar package

Use Java jar commands or other packaging commands to compress the program into a jar package and test whether Java-jar can be successfully executed in WINXP dos, after the execution is successful, upload it to Linux. How to package and view my other article. package the program and obtain the following file: linuxtest. jar and a lib folder, which contains the jar package required for running the program. for transmission convenience, I compress all the files into a zip package: app.zip uses the RZ command to upload it to svn8.com under the/webapps/directory on Linux.

5. Compile the script for executing the program

CD/webapps directory

Rz uploads the app.zip file to this directory.

Unzip app.zip decompress the file

Rm app.zip

Ls you can see the following content:

BBS. svn8.com

Lib linuxtest. Jar

Cat> Start. sh: Create a script file and enter the following content:

Java-jar linuxtest. Jar

CTRL + d save the file

Add executable permissions to chmod + x start. Sh

 

. Start. Sh run the script to run the program. If you see the following content, it indicates that you have succeeded:

 
[Framework] 19:44:19, 181-Com. Dao. appdao-0
[Main] info com. Dao. appdao-this is info message
[Framework] 19:44:19, 187-Com. Dao. appdao-6
[Main] error com. Dao. appdao-this is error message
[Framework] 19:44:19, 188-Com. Dao. appdao-7
[Main] fatal com. Dao. appdao-this is fatal message

 

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.