Date: Fri, 15 Nov 2002 20:50:39 -0600 From: "Warner, Michael - Contractor" <michael.warner@xo.com> To: "'freebsd-java@freebsd.org'" <freebsd-java@freebsd.org> Subject: RE: java tutorials for freebsd? Message-ID: <45EDA71CFF25D411A2E400508B6FC52A0A1F97C4@orportexch1.internal.nextlink.net>
index | next in thread | raw e-mail
Found a typo, if that's the kind of feedback needed. Shouldn't that say jdk
1.1.8 rather than 1.8?
-----Original Message-----
From: Kendall Gifford [mailto:kendall@jedis.com]
Sent: Friday, November 15, 2002 5:11 PM
To: freebsd-java@FreeBSD.ORG
Subject: RE: java tutorials for freebsd?
Clemens Fischer wrote:
>
> We currently do not have any FreeBSD specific tutorials. If you
> would like to see one, send a message to freebsd-java@freebsd.org.
>
Greetings all. I was recently asked by a FreeBSD user how I installed
and got Jakarta-Tomcat working. I know I'd had a bit of a time getting
all the different parts installed when I first did it, and I suspect
others may have as well. I know a very detailed, simple, step by step
instruction list would have been nice to know what is involved in
installing Java and Java applications on FreeBSD. Novices like me
frequently think they can just do a 'make install' in the jdk13
directory, which we all know isn't quite enough.
Anyhow, I wrote up the following tutorial in answer to a specific
user's question and thought it might be of use to others as well. I'll
post this tutorial here for comment (fix any wrong ideas or phrases it
may have) and so that whomever has the authority/influence on FreeBSD
Java documentation can see as well.
/*
* Jakarta-Tomcat and Java on FreeBSD Tutorial
* By: Kendall P. Gifford
* (As best as I understand it)
*/
Hello, here is a preliminary Tomcat on FreeBSD recipe. I hope some
of this helps. We've found FreeBSD to be very stable and have had
fewer problems, crashes, or weirdness than we used to with Tomcat on
Windows 2000.
The most hairy part that I had to deal with when first installing
Tomcat on FreeBSD was installing the JDK. I don't know how familiar
you are with Java support in FreeBSD but, due to some licensing issues
of some sort, there is not a Sun supported FreeBSD JDK past version 1.8.
So, in order to install a newer native JDK (like 1.3) you have to
build it from the source code that you manually download from Sun's
Java site. The catch, is that in order to build the JDK, you need an
existing one to already be installed. This is where FreeBSD's linux
emulation environment comes in handy. You can install a Sun supported
Linux JDK that runs under emulation. Fortunately, all of this work can
be done via the ports collection.
The order of operations I followed was thus:
----------------------------------------
1. The usual update of the ports collection (cvsup) so as to install
the latest code. You'll note in my example I have a cvsup file
specifically for updating the ports collection.
cvsup /etc/cvsupfile_ports
2. Since I use portupgrade, the ports and packages management wrapper
utilities, I then run:
portsdb -uU
(* see notes below)
3. If I don't already have X installed, I do so here. I don't ever
actually run X11 on the server, but building the native JDK will
install X anyway as the swing classes require open-motif which
requires X. I like to manually build X or else version 3 will be built
for me automatically instead of version 4 (is this still true?).
portinstall x11/XFree86-4
portinstall x11-toolkits/open-motif
4. If I don't already have the linux emulation environment of my
choice installed, I do so here:
portinstall emulators/linux_base
5. Now it is time to manually download the linux JDK file from Sun's
site. I, as a paranoid person, always like to first check the Makefile
for the port and see which jdk revision number it expects, as this
determines which JDK file to download. Also, the Makefile usually
contains an exact URL to the correct JDK file.
grep "\(JDK_REVISION\)\|\(DOWNLOAD_URL\)" \
/usr/ports/java/linux-sun-jdk13/Makefile
6. After you download the JDK file (something like
j2sdk-1_3_1_05-linux-i586.bin), put it in /usr/ports/distfiles. Then
building the linux JDK is straight forward:
portinstall java/linux-sun-jdk13
7. You could just use the linux JDK for all of your Java and Tomcat
needs, but I (and quite a few others) find the patched, native JDK
stable enough to use and some say it will perform better (is this
true?). So, to install it, you need to grab the JDK1.3 source package
from Sun's site. Again, I check the ports Makefile for the download
URL and name of the file to look for:
grep --context=1 MASTER_SITES /usr/ports/java/jdk13/Makefile
Just a heads up, you'll need to have a (free) user account in order
to download the source code from Sun's site. The file you'll download
is something like j2sdk-1_3_1-src.tar.gz and goes in
/usr/ports/distfiles as well.
8. Now you have to get the FreeBSD JDK source patches. Make sure you
get the patch set that matches the one specified in the Makefile (if
you cvsup'ed, this'll be the latest patch set).
grep JDK_PATCHSET_VERSION /usr/ports/java/jdk13/Makefile
You download this file from:
http://www.eyesbeyond.com/freebsddom/java/jdk13.html
9. Once you put the patch set file (bsd-jdk131-patches-7.tar.gz) in
/usr/ports/distfiles, you can finally build the native JDK.
portinstall java/jdk13
10. Once you have Java installed and working, installing Tomcat is
fairly simple using portupgrade on the ports collection:
portinstall www/jakarta-tomcat41
11. Some other commonly used software and utilities I install for
JSP/Servlet development:
portinstall devel/jakarta-ant
portinstall databases/mysql-jdbc-mm (**See note below)
12. If you are running Tomcat through Apache, you'll need to install
and/or configure Apache (and a connector module - mod-jk?). For our
web application, we have no static content and aren't doing any load
balancing yet, so there is no reason for us to use Apache. We use
Tomcat in a standalone configuration.
13. Now there is the obvious application and environment
configuration. For our developer's convenience, who all use bash, I
set some global environment variables in /etc/profile:
JAVA_HOME=/usr/local/jdk; export JAVA_HOME
TOMCAT_HOME=/usr/local/tomcat; export TOMCAT_HOME
CATALINA_HOME=/usr/local/tomcat; export CATALINA_HOME
CLASSPATH=...
I also like to create convenient symlinks for Java and Tomcat. I
symlink the installed, production jdk and tomcat directory thus:
ln -s /usr/local/jdk1.3.1 /usr/local/jdk
ln -s /usr/local/jakarta-tomcat4.1 /usr/local/tomcat
ln -s /usr/local/jakarta-ant-1.5.1 /usr/local/ant
etc.
14. Notes: Possible Gotchas, Misc. Ramblings (Wisdom?)
When the Tomcat 4.x port installs, it puts a typical Tomcat
directory hierarchy under /usr/local/jakarta-tomcat4.x. To start and
stop Tomcat, it also installs a C program (based on daemonctl.c)
called tomcat4ctl or tomcat41ctl under /usr/local/bin. It works much
like apachectl does for apache. To actually start Tomcat (at bootup
for instance), the script 020.jakarta-tomcat4.sh (or
020.jakarta-tomcat41.sh) is installed into /usr/local/etc/rc.d. It
just manages a PID file, and executes tomcat4ctl as user:group www:www.
The daemonctl.c program executes the $TOMCAT_HOME/bin/bootstrap.jar
file and writes a PID file. This information has been important to me,
trying to run Tomcat as a standalone web server, for multiple reasons.
First of all, since bootstrap.jar is executed as user www, Tomcat
can't have any connectors using any privileged port (<1024). Since I'm
doing Tomcat as a standalone server, this is inconvenient since I want
to use ports 80 and 443. Unfortunately, I don't think bootstrap.jar,
with its cross platform-ed-ness and single-process-ed-ness, will ever
give the ability to have a parent process running as root that spawns
a child for actually handling requests, which binds to port 80, then
setuid()'s to user www, thus allowing the request handling Tomcat
process to have privileged ports and limited system access. This is
the downside of not using Apache in conjunction with Tomcat.
On our system, to allow Tomcat to use ports 80 and 443, we have to
(dangerously) run Tomcat as root. The tomcat4ctl program has the suid
and sgid bits on by default, and is owned by www:www. I just changed
the ownership of the file to root:www. Then, all our developers who
need to start/stop Tomcat are made members of the www group (group
execution is, of course, on). Having Tomcat running as root, however,
is insecure and should be avoided.
Also of note to some is the use and presence of the CLASSPATH
system variable. Our developers used to use the classpath in some
classes to access some properties files. It worked fine on Tomcat 3.x
and works fine on Windows 2000 running Tomcat 4.x standalone. On our
current FreeBSD system w/Tomcat 4.x, it doesn't. None of the scripts
in Tomcat's bin directory are ever used by FreeBSD by default. On
Windows, the developers modified setclasspath.sh/setenv.sh (er, .bat?)
and started Tomcat with startup.bat. On FreeBSD, none of those scripts
are ever used and are meaningless. It seems I tried to manually use
one of those scripts to start/stop Tomcat once and it either didn't
work at all, or it put Tomcat into a weird state (perhaps some weird
option was set in the scripts or something?). Also, be careful what
user you start/stop Tomcat as using the FreeBSD ports' tomcat4ctl or
020.jakarta-tomcat4.sh. Some of our developers took it upon themselves
to restart Tomcat. They naturally weren't logged in as root. I can't
remember what happened (this may have been the older 3.x version that
this happened on) but it didn't work.
Since our developers make use of the CLASSPATH variable, we've had
an issue recently with the latest Tomcat and the way it is started and
the way it runs. There is no way (that I can figure out) to set the
CLASSPATH variable and have it passed into Tomcat since version 4.x. I
even manually modified daemonctl.c and rebuilt tomcat4ctl, having it
pass the '-cp classpath' option to the java instance that would be
executing bootstrap.jar. It was to no avail as the classpath must be
cleared or ignored somewhere by the Tomcat class loader. When we
output System.getProperty("java.class.path") we would always get
"bin/boostrap.jar" and nothing else. It is here that my knowledge ends
and my ignorance begins.
/*------------------------------------*/
* - All port installation examples here make use of the portinstall
command from the portupgrade utility collection. All examples could
just as easily be installed by cd'ing to the port's directory and
running: make install
Ex. cd /usr/local/ports/java/jdk13; make install && make clean
To install and use portupgrade:
cd /usr/local/ports/sysutils/portupgrade
make install && make clean
pkgdb -uF
portsdb -uU
** - The last time I installed the MySQL JDBC driver, the installation
failed. To build it, it needed the JDK1.8 installed as well as a Java2
JDK. I don't know if this is still the case. However, since FreeBSD
Java uses the javavmwrapper port (some scripts and a registration file
in /usr/local/etc) to manage the different JDK's, you can install all
the JDK's you want without a problem.
The other option is to just download the pre-built driver from
MySQL's web site, unjar it, and manually install the driver jar files
wherever is convenient.
/*------------------------------------*/
/*
* End of tutorial.
*/
--
----------------------------------------
ASCII RIBBON CAMPAIGN /\
NO HTML/RTF EMAILS! / \
\ /
Kendall P. Gifford \/
kendall@jedis.com /\
http://kendall.jedis.com / \
----------------------------------------
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45EDA71CFF25D411A2E400508B6FC52A0A1F97C4>
