When you think of platforms upon which you would deploy a Java Application Server, FreeBSD probably isn’t the first one that comes to mind. However, I hope to show in this tutorial how easy it is to deploy Apache Tomcat on a FreeBSD system, complete with a native build of the JDK.The first thing you will need is a fresh copy of the ports tree. There are
several ways to obtain this, all detailed in the FreeBSD handbook. I won’t go into obtaining a fresh ports tree as it transcends the scope of this tutorial.
Next, we will build a native JDK 1.3 for FreeBSD. While there are patches for JDK 1.4 to build it out of the ports collection, they are currently not production quality. For the sake of stability, this tutorial will cover how to do a native build of JDK 1.3.
In order to build the JDK, you will need Linux compatibility enabled. You will need to add the following line:
linux_enable=”YES”
To /etc/rc.conf and install the linux_base package. This can be accomplished with the following command:
pkg_add -r linux_base
Note that your system cannot be at a securelevel if you do this, because you must load kernel modules while running at a securelevel. If you get “Operation not permitted” when the linux_base package tries to load the Linux compatibility module, edit /etc/rc.conf and look for the following line:
kern_securelevel_enable=”YES”
And change YES to NO, then reboot.
Next, we will need to install a Linux JDK package. You will need to download the file j2sdk-1_3_1_08-linux-i586.bin from Sun and place it in /usr/ports/distfiles. Now cd to /usr/ports/java/linux-sun-jdk13 and type “make install”. This will install the Linux JDK, which we will use to build our own native FreeBSD JDK.
To build a native JDK, you will need to manually fetch two files, the source to the JDK, and a set of patches for the JDK. After fetching these, place both in /usr/ports/distfiles. The JDK 1.3.1 sources may be found at http://wwws.sun.com/software/java2/download.html and the patchset at http://www.eyesbeyond.com/freebsddom/java/jdk13.html.
Now cd to /usr/ports/java/jdk13 and type “make install”. If all goes well a native copy of the JDK will then be installed under /usr/local/jdk1.3.1. You will probably want to run “make clean” as building the JDK will use quite a bit of space. Also, at this point you can remove the Linux JDK. Run the following to remove it:
pkg_delete “linux-sun-jdk13*”
Now we will install Apache 2. This is quite simple, cd to /usr/ports/www/apache2 and type “make install”. Configuration will be placed in /usr/local/etc/apache2/, edit it to your wishes.
Next we will install Tomcat. Just cd to /usr/ports/www/jakarta-tomcat41 and type “make install”. This will also install other Jakarta tools like Apache Ant, a build tool which you might consider for JSP development.
The final phase of the installation is installing a connector. A connector allows Apache to act as a frontend for Tomcat and process requests for Java servlets. There are 3 connectors to consider, mod_jk2, Coyote, and mod_webapp. We will use mod_webapp because it provides the best performance and easiest configuration. The only drawback of mod_webapp is that it currently doesn’t support load balancing, which is an issue that transcends the scope of this tutorial.
To build mod_webapp, fetch the file jakarta-tomcat-connectors-4.1.12-src.tar.gz and place it in /usr/ports/distfiles/mod_webapp (you will need to create the mod_webapp subdirectory). Now cd to /usr/ports/www/mod_webapp-apache2 and type “make install”.
Now we need to configure Apache to use mod_webapp. Edit /usr/local/etc/apache2/httpd.conf. The first thing we need to do is ensure that the ServerName directive is valid and also contains the port number that our server listens on:
ServerName example.server.com:80
Now, look for the LoadModule section and add the following line:
LoadModule webapp_module libexec/apache2/mod_webapp.so
Now we will add configuration that tells mod_webapp how to connect to Tomcat. Place the following two lines at the end of your httpd.conf:
WebAppConnection warpConnection warp localhost:8008
WebAppDeploy example warpConnection /example
These directives take the following form:
WebAppConnection <connection name> <provider> <host:port>
WebAppDeploy <application name> <connection name> <application path>
You will want to change the application name and path to reflect where you are deploying JSP on your system. Add the following line to get information about your current mod_webapp configuration.
WebAppInfo /webapp-info
Now we need to configure Tomcat to listen on port 8008. The stock /usr/local/jakarta-tomcat4.1/conf/server.xml file contains a great deal of unnecessary options for our intended use, which is with mod_webapp. You will want to back it up or delete, then replace its contents with the following, remembering to change example.server.com to match the name given in your Apache configuration’s ServerName field:
<Server shutdown=”SHUTDOWN” debug=”0″>
<Service name=”example.server.com”>
<Connector className=”org.apache.catalina.connector.warp.WarpConnector” port=”8008″ minProcessors=”5″ maxProcessors=”75″
enableLookups=”true” scheme=”http” secure=”false” appBase=”webapps”
acceptCount=”10″ debug=”0″ />
<Engine className=”org.apache.catalina.connector.warp.WarpEngine”
name=”example.server.com” debug=”0″>
<Logger className=”org.apache.catalina.logger.FileLogger”
prefix=”apache_log.” suffix=”.txt” timestamp=”true” />
<Host className=”org.apache.catalina.connector.warp.WarpHost”
name=”example.server.com” debug=”0″ appBase=”webapps” unpackWARs=”true”>
<Context path=”” docBase=”ROOT” debug=”0″ />
</Host>
</Engine>
</Service>
</Server>
After you have done this, start Tomcat by running:
/usr/local/etc/rc.d/020.jakarta-tomcat41.sh start
And start Apache by running:
/usr/local/etc/rc.d/apache2.sh start
Now point a browser at http://yourserver/webapp-info/
If all is working information about mod_webapp should be displayed, in which case you may now begin using your FreeBSD-based Java Application Server.
About the Author:
Tony Arcieri is a Solaris system administrator by profession, working on a number of projects for the Colorado
Climate Center developed in C, C++, Java, PHP, and Perl. He is also working on a number of open source projects, including libtorrent and phpkeychain.
Just wondering why do you choice FreeBSD over Linux for the Java Server? Myself, I wouldn’t choice FreeBSD for now, but should be better when 5.2 or later is released.
Java and MySQL are doing better on the Linux, because of threads and etc.
<off point>
Two of your new projects, libtorrent and phpkeychain. They look very insterest and useful.
It’s very good idea to create the libtorrent, which I think it might be useful for Apache modules and many other tools.
phpkeychain looks interest, but I am not sure what exactly it will work with PHP. I am going to read the FAQ that you have posted yesterday. I might throw some comments or/and questions.
</off point>
Probably because, like me, he finds working with FreeBSD far more enjoyable than working with “Linux”. The performance difference is irrelevent (at least for me).
Tony “Bascule” Arcieri is a known FreeBSD, OSX and Solaris fan around here. ๐
Just wondering why do you choice FreeBSD over Linux for the Java Server?
I wrote this article partly because FreeBSD gets such a bad rap in the area of Java support. We have been developing a JSP web site with a number of other groups around the country which allows volunteers to enter precipiation data they’ve collected. The data is then stored in a MySQL backend accessed via JDBC, then the data can be accessed or analyzed either from web pages or SOAP services.
As for why the server is running FreeBSD, it’s simply what I chose as a personal preference. The codeveloped JSP data collection system came about long after I installed the server, but when it came time to deploy Tomcat I was surprised at how remarkably easy it was to do through the ports collection. On a decently fast system you should be able to complete all the steps in this tutorial in under an hour.
If you’re looking to build a JSP server from scratch and performance is critical, FreeBSD probably isn’t going to be your first choice. We have had no performance issues using FreeBSD as a JSP server (on a dual 866MHz Dell w 512MB RAM) but our site is relatively low traffic (approximately 1500 hits/day)
He choose FreeBSD because its a mature,well built,well documented,fast and stable UNIX system. Unlike Linux which is a hacked together clone of UNIX with far too much hype
Eugenia: Tony “Bascule” Arcieri is a known FreeBSD, OSX and Solaris fan around here. ๐
Yeah, I am aware of it. His comments in OSNews.com is one of my favorite to read. ๐ However, myself always prefer FreeBSD over for anything. But, I still will have to choice Linux for Java or whatever, when it’s lacking on FreeBSD. Linux is one of my last choice of kernel/gnu (OS).
Bascule: I wrote this article partly because FreeBSD gets such a bad rap in the area of Java support.
That’s good point and think, I like that.
Bascule: As for why the server is running FreeBSD, it’s simply what I chose as a personal preference.
[…]
If you’re looking to build a JSP server from scratch and performance is critical, FreeBSD probably isn’t going to be your first choice. We have had no performance issues using FreeBSD as a JSP server (on a dual 866MHz Dell w 512MB RAM) but our site is relatively low traffic (approximately 1500 hits/day)
I agree. I don’t experience on Java server that much, but how does it compares to run on Linux and FreeBSD to you today? Way back in like FreeBSD 4.3 or 4.4, it was sucks and ran on Linux better. It pissed me off.
Mark: He choose FreeBSD because its a mature,well built,well documented,fast and stable UNIX system. Unlike Linux which is a hacked together clone of UNIX with far too much hype.
No, it’s not that simple. Java on FreeBSD aren’t full mature, yet. I never recommend anyone to run the Java server on FreeBSD, which I point them to Linux or Solaris. As for small personal or so, it’s ok. Java and MySQL are doing better on Linux than FreeBSD does. But, for the other things, FreeBSD blows Linux out of water.
FreeBSD always has been my first choice of OS, but lack of threads and etc do hurt FreeBSD.
As for a best example, Yahoo can’t give up the FreeBSD, so they use PHP (and C/C++ too?) instead Java.
well, i respected your comment till you got to the hacked together part, then i saw the axe you’ve been grinding hidden behind your back.
i do like freebsd…but “hacked together” sounds like you got a stick in your craw.
there ARE advantages to running linux in some cases.
just like there are advantages to running windows or mac.
maybe just not in the sphere of things YOU do.
I’ll try it soon. . . but not with the native jdk.
i like freebsd, i like java but i’m victim of little frustration when try to join it. why?? simple: the native jdk doesn’t run NetBeans. . . i need to run the IDE with the linux jdk and of course with the linux “runtimes”.
Very nicely done. I had given up on tomcat in frustration due to the lack of documentation in getting it to co-exist seamlessly with apache.
Now how do I get apache to automatically invoke tomcat for *.jsp, /WEB-INF urls? Finally, how do I deploy a war file?
regards,
Gavin
Firstly, my thanks to Greg Lewis and others for keeping the Java port alive. It’s a pity Sun won’t chuck a few dollars towards ‘official port’ status.
Like most readers of this thread I’ve heard all the good publicity regarding FreeBSD and how it’s more fun to use that Linux.
However, I’m a Java developer by trade and convincing me and others to try one of the BSDs is difficult when none of the commonly used tools (DB2, Oracle, NetBeans, Eclipse) are supported and the JDK doesn’t pass Sun’s JCK.
Sure, you might get them to run under emulation but if you’re going to emulate linux might one just as well run Linux?
Disappointing when one of the project leaders interviewed on this site a week or so ago dismissed it as a non-issue. And yet While there are patches for JDK 1.4 to build it out of the ports collection, they are currently not production quality.
So, I’m curious
i. how far away is a usable JDK 1.4?
ii. Installing the Linux JDK in order to compile the FreeBSD seems like overkill. What dependencies does this bootstrapping resolve that could otherwise be eliminated?
Perhaps when I get a new box for home I’ll install it myself.
>But, for the other things, FreeBSD blows Linux out of water.
Are you sure? 3D preformance is really BAD on FreeBSD.
If there is OpenBSD why the hell do you need FreeBSD?
OpenBSD has everything FreeBSD lacks and more…and Linux is catching up very quickly i guess there is no reason, concernig stability and/or preformance to choose FreeBSD. That does not mean its not a good product, i like FreeBSD but is nonsens to think its better then Linux. Depends on what you need to do, with how much support and how much time in wich envoirment..Penguins kick ass!
Are you sure? 3D preformance is really BAD on FreeBSD.
False, Nvidia driver runs faster on FreeBSD than on RedHat, which my machine is only 450Mhz and other machine is 1.4Mhz. I tested it on the glxgears. Even, the tuxracer runs a lot smoother on 450Mhz (FreeBSD) and not on 1.4Mhz (RedHat8).
If there is OpenBSD why the hell do you need FreeBSD?
Uh, what’s your point anyway? I have lost the count of Linux distros out there. If there is Microsoft Linux why the hell do you need Linux?
OpenBSD has everything FreeBSD lacks and more.
Like what? I only see thing is PF. FreeBSD 5.x already has a lot of better stuff. All three BSDs are sharing the code most of time, anyway.
Linux is catching up very quickly i guess there is no reason, concernig stability and/or preformance to choose FreeBSD.
So, you mean Linux is <u>still</u> catch<u>ing</u> up very quickly and FreeBSD is still ahead?
Depends on what you need to do, with how much support and how much time in wich envoirment.
Time? FreeBSD saves a lot of time, it’s a lot easier to admin than Linux does.
Anyway, it’s getting way off topic and let this end. If you want to discuss more, post in the ‘OS war’ forum.
I would hope your 450 mhz computer beats out your other 1.4 mhz computer. 1.4 mhz isn’t a lot to work with nowadays, especially if you want to use X.
I would hope your 450 mhz computer beats out your other 1.4 mhz computer. 1.4 mhz isn’t a lot to work with nowadays, especially if you want to use X.
Good catch, I mean 1.4Ghz…. ๐
>False, Nvidia driver runs faster on FreeBSD than on RedHat,
>which my machine is only 450Mhz and other machine is 1.4Mhz.
>I tested it on the glxgears. Even, the tuxracer runs a lot
>smoother on 450Mhz (FreeBSD) and not on 1.4Mhz (RedHat8).
I gues 1.4mhz would be 1.4ghz..
I do not shgare those figures…maybe your 3D card (nvidia) is note the same i the redhat pc or you missconfigured it..
Anyway Nvidia is not the only player in 3D land ever heard of 3Dlabs or Elsa? i am talking about 3D as in Maya and Softimage not games..
>So, you mean Linux is <u>still</u> catch<u>ing</u> up very
>quickly and FreeBSD is still ahead?
No i ment Linux is catching up with OpenBSD not FreeBSD and yes there are certain terrains where i would choose FreeBSD
over Linux and the other way around.
>Time? FreeBSD saves a lot of time, it’s a lot easier to
>admin than Linux does.
Nonsens!
I have been hammering on both FreeBSD (for several years) and Gentoo Linux (for around a year).
There’s a reason I’m running FreeBSD 5.1-BETA right now, it is because I find it faster and more stable. Sometimes linux just bogs down with it’s pathetic scheduler it just does not offer as smooth a user experience. I’m even running a SCHED_ULE kernel, while it’s not BeOS, it does a pretty fine job for costing me no money.
Also, since I try to stay on the very bleeding edge of each, it is MUCH easier to keep track of the progress of FreeBSD. Although FreeBSD 5 can become completely unusable during periods of major changes, the FreeBSD system allows me to know *exactly* what is going on and who is making what changes.
With Gentoo, at least, you’ve got these guys with some random script kiddy username making god only knows what kind of stupid commits to the sources.
Isn’t this phrase getting reeeaaally old?
I’ve heard Linux is catching up the desktop for about 3 years now and I still haven’t seen anything usable.
Pretty much same with Linux vs BSD… it’s catching up and for how long has it been like that? 8 years?
Linux may catch up ol’ developments from other systems but will never really get there….
> Java and MySQL are doing better on the Linux, because of threads and etc
“Revisiting FreeBSD vs. Linux for MySQL” http://jeremy.zawodny.com/blog/archives/000697.html
He said: “MySQL now runs very well on FreeBSD.”
I don’t know where you folks get your information on Linux vs. FreeBSD from, but I use both, along with Mac OS X. I find both FreeBSD and Linux to be quite capable, stable AND mature.
I do find FreeBSD to be easier to administer, mainly because it is a much simpler system.
I had been debating on replacing Linux on my server with FreeBSD, but after working with Debian for a couple of months, have decided to switch to that instead. I had been running Mandrake Linux 7.2, and with building a new server, had decided to use a more “updatable” OS. I love FreeBSD for it’s ports collection and buildworld capability, but you just can’t beat Debian’s “apt-get update && apt-get upgrade” ๐
This doesn’t mean I will stop using FreeBSD, or that I will start bad-mouthing it, I still find FreeBSD to be an exceptional OS. Very robust, stable, mature and FAST.
Moral of this story: You don’t have to pick just one OS to use. That’s one of the beauties of Open Source software. Why not use the right tool for the job, and let religion stay in the church, where it belongs.
I recently went through hell on FreeBSD and Java. We were running the old 1.1.8 Java native for FreeBSD and Tomcat. The Java code was updated during a regular maintenance window. The code was tested in the dev environment and nothing came up. In production, however, problems started appearing about a day later. The Tomcat servers would just hang and stop serving requests. Tomcat/Apache had to be shutdown and restarted, thereby clearing out user sessions (an annoyance and it meant lost work). It happened about once every 36 hours for all of our webserver, and I didn’t get much sleep.
Dev decided that upgrading Java was in order, and we thought about running Java in Linux compatibility mode. Given the problems we had, we weren’t ready to take that risk. We used IBM’s 1.4 JDK and it worked right out of the box, and worked perfectly ever since.
‘ll try it soon. . . but not with the native jdk.
i like freebsd, i like java but i’m victim of little frustration when try to join it. why?? simple: the native jdk doesn’t run NetBeans. . . i need to run the IDE with the linux jdk and of course with the linux “runtimes”.
That’s odd I compiled the jdk from ports some time ago on FreeBSD 5.0 and it worked fine. I did have to edit the startup script though (runide.sh)
I wish I could remember what I did to it ๐ It was a matter of deleting some lines.
Is it me or there is no jdk1.3 port on the master server?
I don’t have ports collection, so I wanted to manually download linux-sun-jdk1.3 port. It is not in linux nor java directory.