Install and configure jython in Linux

Source: Internet
Author: User

1. Install jdk:

(The method here is used for ubuntu or debian, And the downloaded jdk is built into a deb package. I think it is to facilitate package management. Otherwise, I do not know which files to delete when I delete them, very troublesome .)

1. Obtain JDK

You can choose to download from Java official: URL: http://java.sun.com or from another website. My version is: jdk-1_5_0-linux-i586.bin

2. Build a Packaging Environment
 
Debian provides the SDK's DEB package build tool: java-package, while Ubuntu is based on Debian, so

# Apt-get install-u java-package fakeroot

Update before apt-get.

3. Create. Deb Software Package

This step must be run as a normal user. If it is run as Root, it is not allowed. The following message is displayed:

You are real root -- unfortunately, some Java distributions have
Install scripts that directly manipulate/etc, and may cause some
Inconsistencies on your system. Instead, you shoshould become
Non-root user and run:
FAK eroot make-jpkg jdk-1_5_0-linux-i586.bin
Which will allow no damage to be done to your system files and
Still permit the Java distribution to successfully extract.
Aborting.

Run as a common user:

$ Fakeroot make-jpkg jdk-1_5_0_06-linux-i586.bin

Next, make some necessary choices. After a few minutes, the prompt that the software package is successfully created appears. You will find something similar in the current directory:
 
Software Package for sun-j2sdk1.5_1.5.0 + update00_i386.deb

4. Installation

Switch back to root and execute the following command:

# Dpkg-I sun-j2sdk1.5_1.5.0 + update06_i386.deb

5. Configure the environment

In ~ /. Add the following content to the bashrc script file:

PATH = $ PATH:/usr/lib/j2sdk1.5-sun/bin:/usr/lib/j2sdk1.5-sun/jre/bin
JAVA_HOME =/usr/lib/j2sdk1.5-sun
JRE_HOME =/usr/lib/j2sdk1.5-sun/jre
CLASSPATH =.:/usr/lib/j2sdk1.5-sun/lib/tools. jar:/usr/lib/j2sdk1.5-sun/lib/dt. jar
Export PATH
Export JRE_HOME
Export JAVA_HOME
Export CLASSPATH

6. Test

Create a simple java program (Hello. java)

Public class Hello
{
Public Hello ()
{
}
Public static void main (String [] args)
{
System. out. println ("Hello World! ";
}
}

Then

$ Javac Hello. java

Check that the current directory will generate a Hello. class file, and then run

$ Java Hello
Hello World!
OK. The test is successful!

7. Chinese font installation in Chinese culture:

Create a fallback directory under the $ JAVA_HOME/jre/lib/fonts/directory.

Copy the Chinese font (for example, simsun. ttf to this directory.

8. Install the plug-in

For the Java environment installed in this method, the location of the browser plug-in file should be:

/Usr/lib/j2sdk1.5-sun/jre/plugin/i386/ns7/libjavaplugin_oji.so
 
Taking firefox1.5.0.1 as an example:

# Cd/usr/lib/mozilla-firefox/plugins
# Ln-s
/Usr/lib/j2sdk1.5-sun/jre/plugin/i386/ns7/libjavaplugin_oji.so

Uninstall JDK:

# Apt-get remove -- purge sun-j2sdk1.5

Uninstall the plug-in and directly Delete the symbolic link:

# Rm/usr/lib/mozilla-firefox/plugins/libjavaplugin_oji.so

Ii. Install jython:

1. http://www.jython.org/project/installation.htmldownload the jythoninstallation file, run the command to install Java-jar jython_installer-2.2rc2.jar ", jython is installed successfully. For example, install it in the/home/justin/java/jython2.2 directory.

2. add the jython package to classpath, that is, change the classpath above to: CLASSPATH =. :/usr/lib/j2sdk1.5-sun/lib/tools. jar:/usr/lib/j2sdk1.5-sun/lib/dt. jar:/home/justin/java/jython2.2/jython. jar

Then you can add the python Library to the java file, for example:

Import org. python. util. PythonInterpreter;
Import org. python. core .*;
Public class SimpleEmbedded {
Public static void main (String [] args)
Throws PyException
{
PythonInterpreter interp =
New PythonInterpreter ();
System. out. println ("Hello, brave new world ");
Interp.exe c ("import sys ");
Interp.exe c ("print sys ");
Interp. set ("a", new PyInteger (42 ));
Interp.exe c ("print ");
Interp.exe c ("x = 2 + 2 ");
PyObject x = interp. get ("x ");
System. out. println ("x:" + x );
System. out. println ("Goodbye, cruel world ");

}
}

3. Add the selected/home/justin/java/jython2.2/jython installation PATH to the PATH environment variable. Now you only need to enter "jython" to run the interactive PATH:

$ Jython
Jython 2.1 on java1.4.0 _ 01 (JIT: null)
Type "copyright", "credits" or "license" for more information.

>>># Access the standard Java library through Jython

>>> From java. util import Random
>>> Rng = Random ()
>>> I = rng. nextBoolean ()
>>> Print I

The jython interpreter is convenient for quick checks and prompts, but you do not have to do all the work here-Jython allows you to write code in the source file and then run the code

From java. util import Random
Rng = Random ()
# This is a comment in Jython
Print "Flipping a coin ...... "
If rng. nextBoolean ():
Print "Came up heads"
Else:
Print "Came up tails"

Run the file in jython.

Source: it

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.