File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Running a web app with compiled code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Running a web app with compiled code" Watch "Running a web app with compiled code" New topic
Author

Running a web app with compiled code

Prasad Darsi
Greenhorn

Joined: Sep 26, 2004
Posts: 16
Hi,
I am testing a webapp named 'myWebApp' with Tomcat 5.5.
Tomcat is storing all the class files (i.e., the compiled code of jsps) in the directory 'Tomcat 5.5\work\Catalina\localhost\myWebApp'.
If I remove the souce jsp pages from 'Tomcat 5.5\webapps\myWebApp', and try to access a page, it is showing the error 'The requested resource (/test/Test.jsp) is not available'

I was able to achieve this with Oracle HTTP server.

How to tell tomcat to run the application from the compiled code ?

Thanks in advance..
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

You're wanting to used pre-compiled JSP's, and (as you've discovered) it's not as simple as letting them compile by themselves, and just removing the source after.

What's happening is, the JSP servlet (which is mapped to *.jsp) is trying to find the *.jsp file on the filesystem, so that it can compare the date with the date on the classfile. When it's not found, it becomes unhappy.

With precompiled JSPs (which should be done in advance), you need to map each and every *.jsp to the generated servlet class. Your web.xml will contain many more entries than it currently does!

The site appears down, as I post this, so hopefully it will come back up at some time, but here is a step-by-step for Tomcat 5.0.x

http://cvs.apache.org/~fhanik/precompile.html
Scott Dunbar
Ranch Hand

Joined: Sep 23, 2004
Posts: 245
In addition to what Mike said I would add why?. Yes, in theory there is a tiny performance hit: every time a JSP is requested the server has to fstat() (or whatever your O/S does) two files and compare the dates. But otherwise there is no performance penalty for leaving the JSP file alone. What is the advantage of removing it?


<a href="http://forums.hotjoe.com/forums/list.page" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
Prasad Darsi
Greenhorn

Joined: Sep 26, 2004
Posts: 16
Hi Scott Dunbar,

I want to remove the source JSPs so that others cannot see the actual code.
If there is only compiled version, it will have only class files, so others cannot know what exactly is inside the original jsp page.

Is there any other way to hide source code ? (creating a war file can solve this problem ?)
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

WAR file is just a deployment unit. Someone can use winzip and extract pages.

and a *class file can get decompiled.

So while removing *.JSP and pre-compiling might stop the idly curious, it certainly won't stop someone determined to see your code.

google for "obfuscation", there are a number of products that might help you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running a web app with compiled code