All articles, tagged with “java”


Setting up Java and installing Tomcat on RHEL 4 with jpackage+up2date

Java seems to be installed and maintained on Red Hat by using jpackage-utils. JPackage provides a repository of Java packages that can be installed using the package management tool of your choice. At the request of our administrator, here we’ll use the anemic up2date. The jpackage-utils rpm creates the filesystem structure that the jpackage packages depend on.

  1. Remove GCJ RPMS:

    Removing these packages are optional, but it prevents being confused about which Java binaries are being used.

    
    $ sudo rpm -evh java-1.4.2-gcj-compat gcc-java libgcj libgcj-devel
    
  2. Setup up2date to use the jpackage packages:

    Most of the packages are platform independent (it’s Java, after all), so you need to include the “generic” repository. The JPackage examples have a trailing slash, which I removed because yum was adding one too. You don’t need to include the non-free repositories as the nosrc RPMs from there must be downloaded by hand.

    You’ll want to use the mirror closest to you.

    
    $ sudo vim /etc/sysconfig/rhn/sources
    

    Add these lines:

    
    # Repository for Java Packages using jpackage
    yum jpackage16-rhes-4 ftp://jpackage.hmdc.harvard.edu/JPackage/1.6/redhat-el-4.0/ free
    yum jpackage16-generic ftp://jpackage.hmdc.harvard.edu/JPackage/1.6/generic/free
    
  3. Add the jpackage GPG key to RPM:
    
    $ sudo rpm --import http://www.jpackage.org/jpackage.asc
    
  4. Update or install jpackage-utils:
    
    $ sudo up2date -i jpackage-utils
    
  5. Create a directory tree for building RPMS in your home directory:
    
    $ mkdir rpm
    $ mkdir rpm/BUILD
    $ mkdir rpm/RPMS
    $ mkdir rpm/RPMS/i386
    $ mkdir rpm/RPMS/i586
    $ mkdir rpm/RPMS/noarch
    $ mkdir rpm/SOURCES
    $ mkdir rpm/SPECS
    $ mkdir rpm/SRPMS
    $ mkdir rpm/tmp
    
    
    
  6. Configure RPM to use the build environment in your home directory:
    
    $ vim ~/.rpmmacros
    
    Add these lines:
    
    %_topdir %(echo ${HOME}/rpm)  
    %_tmppath
    %{_topdir}/tmp
    %packager Your Name 
    # Uncomment to have built RPMs land in RPMS/ instead of RPMS//
    #%_rpmfilename %%{NAME}-%%{VERSION}- %%{RELEASE}.%%{ARCH}.rpm
    

    I forgot the "r" on "packager" and got a cryptic "Package does not exist:" error on an unrelated line. Maybe documenting it here will help some confused person.

  7. Build and install RPMs for Sun's SDK:
    1. Download Sun's JDK 1.5.0 Update 2:

      JDK is the new name for the SDK. Once you agree to the licensing terms, copy the link to download the "Linux self- extracting file" (not the RPM). Paste the link into a wget command to download the file onto your server. The -O flag to wget saves the file with the specified name. This avoids having all the garbage of the URL in the filename.

      
      $ cd rpm/SOURCES/
      $ wget <link to Linux self-extracting file> -O jdk-1_5_0_02-linux-i586.bin
      
    2. Download and install jpackage's java-1.5.0-sun nosrc RPM. When they say that it is the Java Runtime Environment, they really mean JDK:
      
      $ cd
      $ wget ftp://jpackage.hmdc.harvard.edu/JPackage/1.6/generic/non-free/SRPMS/java-1.5.0-sun-1.5.0.02-1jpp.nosrc.rpm
      $ rpm -ivh java-1.5.0-sun-1.5.0.02-1jpp.nosrc.rpm
      
    3. Build the RPMs from the NOSRC RPM:
      
      $ rpmbuild -bb rpm/SPECS/java-1.5.0-sun.spec
      
    4. Install the RPMS:
      
      $ sudo up2date -i unixODBC-devel
      $ sudo rpm -ivh rpm/RPMS/i586/java-1.5.0-sun rpm/RPMS/i586/java-1.5.0-sun- alsa
      $ sudo rpm -ivh rpm/RPMS/i586/java-1.5.0-sun-demo rpm/RPMS/i586/java-1.5.0-sun-devel
      $ sudo rpm -ivh rpm/RPMS/i586/java-1.5.0-sun-fonts rpm/RPMS/i586/java-1.5.0-sun-jdbc
      $ sudo rpm -ivh rpm/RPMS/i586/java-1.5.0-sun-plugin rpm/RPMS/i586/java-1.5.0-sun-src
      
  8. Build and install RPMs for Sun's JTA
    1. Download Sun's JTA Class Files 1.0.1B and the JavaDocs.

      Once you agree to the licensing terms, copy the link to download the zip file. Paste the link into a wget command just like you did for the JDK.

      
      $ cd rpm/SOURCES/
      $ wget <link to JTA classes.zip>
      $ wget <link to JTA JavaDocs.zip>
      
    2. Download and install jpackage's jta-1.0.1-0.b.4jpp NOSRC RPM:
      
      $ cd
      $ wget ftp://jpackage.hmdc.harvard.edu/JPackage/1.6/generic/non-free/SRPMS/jta-1.0.1-0.b.4jpp.nosrc.rpm
      $ rpm -ivh jta-1.0.1-0.b.4jpp.nosrc.rpm
      
    3. Build and install the RPMs:
      
      $ rpmbuild -bb rpm/SPECS/jta.spec
      $ sudo rpm -ivh rpm/RPMS/noarch/jta-1.0.1-0.b.4jpp.noarch.rpm rpm/RPMS/noarch/jta-javadoc-1.0.1-0.b.4jpp.noarch.rpm
      
  9. Install Tomcat and its many dependencies:
    
    $ sudo up2date -i tomcat5
    

These instructions would probably work on CentOS 4 using yum with little modification.

It appears that all of the steps about building RPMS can be skipped by installing Sun's RPM, and then installing the package java-1.5.0-sun-compat. I'm not sure what I would have done about the JTA stuff though.

[ Read More | 0 comments | 0 pingbacks | , , , , ]

How do I set up a Java development environment on Debian?

Sun does not allow redistribution of their JRE or SDK. The free VM’s for Java are behind by many versions. For that reason, some work has to be put in to get a usable Java development environment on Debian. I am using Debian Testing (Sarge).

There are two methods to get a Java environment set up: use the Blackdown Debian repository, and roll a .deb with Sun’s SDK.

Blackdown’s Debian repository is a hassle free way to install a Java SDK. The downside is that it lags behind Sun’s official SDK in fixes and features, and the repository is not always available or maintained. You can get information about the repository from www.blackdown.org. Using the repository takes three steps:

  • Add deb ftp://ftp.tux.org/java/debian/ sarge non-free to /etc/apt/sources.list
  • Run aptitude update
  • Run aptitude install j2sdk1.4 to get the SDK and aptitude install j2re1.4 to get the JRE

Using the latest official release from Sun takes a bit more work, but Debian has made some tools to stream line it a bit:

  • Make sure you have “unstable contrib” in /etc/apt/sources.list
  • Run aptitude install java-package
  • Download the J2SDK as a binary file from Sun’s web site. Be careful not to get the bin that unpacks into an RPM.
  • Run fakeroot make-jpkg <j2sdk package> to make a .deb package containing the SDK.
  • Run dpkg -i <SDK.deb> to install the package.
  • Run aptitude install sun-j2sdk1.4debian to get the Debian specific components.

That should give you a fully functional Java development environment. You might also want to install ant. I was impressed that Debian took care of installing the Java plugin for Mozilla for me.

Props go to Byron Clark for giving me these instructions.

[ Read More | 0 comments | 0 pingbacks | , , , ]

Which Java package do I need?

My understanding is this: J2ME (Java 2 Micro Edition) is for embedded systems development. If you don’t know what this is, then you don’t need it. If you are using JBoss or IBM’s Websphere, you might consider using the J2EE stuff (Enterprise Environment—server software and stuff). If you just want basic Java functionality, then download J2SE. The J2SE is the right program to download for most people. The J2SE consists of two parts: the JRE and the SDK. If you don’t want to program, then all you need is the JRE (Run-time Environment), which gives you the java interpreter. If you want to program, then you need the SDK (Software Development Kit), which includes a icompiler. The SDK includes the JRE—you don’t need to download both.

[ Read More | 0 comments | 0 pingbacks | , , ]

HOWTO use a Java jar file

There are two steps to using a library from a jar file in your program. First, you need to import the libraries from the jar file that you would like to use into your source code. Second, make sure that your CLASSPATH environmental variable is set. Only the second step warrants additional discussion.

When you compile your program your CLASSPATH environmental variable must be set to point to the jar file that you will want to use; not to the directory, but to the actual file. You can set your CLASSPATH variable in two ways: use the export command to put it into your environment, or use the -classpath flag on the javac compiler and java interpreter. If there is no CLASSPATH variable set, then java assumes that your classpath is the current directory (“.”). If it is set then it will be used instead of the current directory. This means that if you don’t include the “.” in your classpath, when you run your program with the java command it will be unable to find the classes located in your current directory. You can separate multiple entries in your classpath with the colon (“;”).

Note: you do not need to unjar a jar library to use it.

[ Read More | 0 comments | 0 pingbacks | , , ]

Adding the Java SDK to your path

I was told that a good thing to do is to create a .sh and .csh file in /etc/profile.d. The .sh file should have these two lines in them:


    export JDK_HOME=<path to your jdk implementation — mine is /usr/java/j2sdk1.4.1_01>
    export PATH=$PATH:$JDK_HOME/bin

My guess at what the .csh file should look like is this:


    setenv JDK_HOME=<path to your jdk implementation — mine is /usr/java/j2sdk1.4.1_01>
    setenv PATH=$PATH:$JDK_HOME/bin

This sets the path variables for all users on the system with .sh and .csh shells, and it creates the JDK_HOME variable which some programs need to function.

[ Read More | 0 comments | 0 pingbacks | , ]

Email: Password:
OpenID URL:
Forgot Login? Close