I do this in Ubuntu 12.10 but I think it applies to Windows 7 configurations too. I wanted to run more than one application in a single instance of tomcat. I have to say this is not the best decision I have made.
You can load two apps in one server instance if you put them in different directories and have two different host names.
In my case, my two hostnames are app1.internal.kw.sg and app2.internal.kw.sg, yours will be different. You can edit your hosts here in your /etc/hosts
Both of my apps would be called app1 and app2. I put them into the corresponding directories, as specified in appBase. In my case, I placed them in:
You can open up your /etc/tomcat7/server.xml file. In Windows 7, it would be where ever your central tomcat configuration files are at. This is my server.xml file:
You can refer to it. Unfortunately I cannot provide much support for this.
Well, this method has a key disadvantage, each time you rebuild your Java classes, you need to restart the server and it would be better to be able to restart one application at a time rather than both applications together due to a longer loading time. Most of the time you will only make changes to one application anyway. It is better to have a configuration with two servers and each of them supporting just one application. That’s my take and I learnt it the hard way.
I am very bothered by the way a typical Java web site development works. Java website developments, through JSP (Java Server Pages) is largely supported by IDEs such as Eclipse and Netbeans. It is not in any way the easiest to utilize. And at worst these huge IDEs are too kludgy for my liking.
Take the current Java project that I am working on, it’s a website that has sign in and numerous data presentation tools. Everything .java compiles into a .class file and the remaining JSP files are deployed into this WAR file through Apache Maven into tomcat. With an IDE, everything seems seamless. You don’t even need to know how it works. Just by magic. You configure the servers and paths and it just works.
You could of course decide to dump WAR files again and again to the server paths and watch it automatically deploy after you do a manual restart of tomcat. Unfortunately that’s too unproductive, starting a tomcat server takes 2 seconds for me, and starting the application takes 10 seconds in debug mode. That’s unacceptably slow because it all adds up.
So, IDEs make you more productive by deploying the files in the server for you and compiles the .java files into .class and .jar files or something like that. Essentially you only need to restart the tomcat7 server if you updated the controller. Updates to the views do not require compilation. However — there’s always a caveat — you have the .jsp file edited on the server path rather than your workspace.
Now, under the hood of the IDE, each time you save a .jsp file, what you are essentially doing is:
Saving the file in your workspace.
Copying the file from your workspace to the server path.
Your workspace can be managed by revisioning tools such as SVN or git and the remnants don’t get copied over to the server space. It’s pretty well thought except that you really need a proper IDE set up to save you all the repetitive work.
So the reason why I am writing this is because I wanted to use Sublime Text and Sublime Text doesn’t have Java and tomcat integration features at all. At first this seemed surprising, after all Java is so common. Upon discovering what Eclipse and Netbeans actually does, I can’t help but to feel that there is a certain amount of over-engineering.
Forgive me if that’s not the way Java IDEs work. I’m uncovering new things every day still, so please correct my mistakes, I want to understand the platform better too.
And so I have the displeasure of working with Java — a platform I once swear to avoid for the rest of my life — and I had to have my Ubuntu 12.10 environment set up. This is also verified to be similar in Ubuntu 12.04.
If you install tomcat7 from the official repository using “sudo apt-get install tomcat7”, the following paths and commands are probably helpful to you too.
It should be called “catalina.out”. It’s useful to check here for troubleshoot Apache Tomcat. It doesn’t mean that tomcat’s successful start would mean the application to be working. catalina.out has saved me on several occasions.
This is more of a personal note and a really specific topic. This tutorial assumes you are using Ubuntu 12.10 or Ubuntu 12.04 and installed tomcat7 package. If you haven’t already installed tomcat7, use:
I have a web robot which is a Java app. I need to be able to set the User-Agent field in the HTTP header in order to be a good net citizen (so people know who is accessing their server). Anyone have any ideas?
Right now, Java sends a request that includes something like:
I’d rather not rewrite all the HTTP stuff myself. I tried just searching in the JDK for the Java/1.0beta2 figuring I could just change the string, but I couldn’t find it. Perhaps it is stored as a unicode string?
An easy method of setting the User-Agent field should probably be added to Java, so people can properly identify their programs.
This is a good move perhaps, one of the new features of Java 1.6 Update 14 is:
Garbage First (G1) Garbage Collector
Garbage First, or G1, is a low pause, server style collector. G1’s primary advantages over the Concurrent Mark-Sweep (CMS) collector include incremental compaction, better predictability and ease of use.
Although G1 is available for use in this release, note that production use of G1 is only permitted where a Java support contract has been purchased. G1 is supported thru Sun’s Java Platform Standard Edition for Business program. Source: Sun
I got really tired of Java updates. I realized it never just updates to the latest, instead it keeps all the old ones which I see no need for.
I haven’t been blogging for a while as it’s exam period. It’s also been busy busy at 24seven. The new product which name you will never guess right.
Today’s paper is on programming, it’s (so-call) advanced concepts. Honestly the whole course’s been a mess but never mind that. I did 3 questions on Java, 2 question on SML and 1 question on Prolog. The Java questions are quite easy. Most of what I studied came out. I planned to do 3 questions out of the 5 Java questions and it went well.
What caught me in a surprise is Prolog which is quite hard, especially the last question which was basically some professor wanting to read some opinion. If I were a computing journalist, I probably choose that question.
SML isn’t that hard. What I studied came out, what I didn’t study I chose not to do. And I quickly went home and I try to see if the average function I wrote work in SML. And it did:
[code lang=”ocaml”]fun average x =
fun sum  = 0.0
| sum (h::t) = h + sum t;
fun count  = 0.0
| count (h::t) = 1.0 + count t;
sum x / count x
I wrote this function very neatly on the paper. I never had so much sense of achievement writing an SML function.
An alternate way of writing would be probably:
[code lang=”ocaml”]fun average x = foldl op+ 0.0 x / real (length x);[/code]
You gotta love foldl sometimes.
Tomorrow’s paper is database. I probably won’t do too well for that. Lots of memorizing to do and my memory’s failing me.
Bloomberg reports that IBM is interested in purchasing Sun Microsystems for $6.5 billion. This acquisition makes sense for IBM although I don’t think it’s worth paying that amount for this company. IBM offers numerous Java-based solutions I think. I don’t see much advantage for IBM in this merger.
IBM May Pay $6.5 Billion to Buy Sun Microsystems, WSJ Reports
International Business Machines Corp. is in talks to buy Sun Microsystems Inc., the Wall Street Journal reported, citing people familiar with the matter.
IBM may pay at least $6.5 billion, 100 percent more than Sun’s closing price of $4.97 a share on Tuesday, the report said, citing the people. An agreement may not be reached, the newspaper said.
An acquisition of Sun Microsystems would bolster IBM’s Internet, data storage, government and telecommunications business, the newspaper said, citing the people.
In recent months, Sun Microsystems has contacted a number of technology companies with the aim of being acquired, people familiar with the matter said, according to the newspaper. Hewlett-Packard Co. declined the offer, the newspaper reported, citing a person briefed on the matter. (Source: Bloomberg)
Sun has too much open-source products and failed to really monetize much of their software. Perhaps IBM can do something about it.