my dog learned polymorphism*
The moose likes JSP and the fly likes JSP Precompile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Precompile " Watch "JSP Precompile " New topic
Author

JSP Precompile

Sridhar Raman
Greenhorn

Joined: Jun 29, 2001
Posts: 12
How can i precompile jsp using Ant and tomcat
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
All jsp's will convert to (servlet) java code on calling jsp in a folder called 'work' which is present in tomcat root folder.
Is it what you wanted. Else post back with more detail regarding the problem
-arun


Sharing is learning
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Part of the JSP spec is to implement jsp precompilation from a URL: http://host/app/page.jsp?jsp_precompile=true -- maybe you can create a script that will run that URL for you -- or some app server vendors provide a .bat file that will run precompilation, maybe you can create an ant script that will call that bat file for you...


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Sridhar Raman
Greenhorn

Joined: Jun 29, 2001
Posts: 12
What i wanted to know is using Ant you can compile java files, jar it war it create ear and also deploy it. but is there a way to use ant script and compile jsp code also
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Originally posted by Sridhar Raman:
What i wanted to know is using Ant you can compile java files, jar it war it create ear and also deploy it. but is there a way to use ant script and compile jsp code also

Not built into it natively, no. Because JSP Precompilation is vendor dependent -- the resultant java servlet will have the vendor's code written in it, so Ant can't do it itself.
Dave P
Greenhorn

Joined: Jun 05, 2001
Posts: 8
Yes, you can use the jspc task in ant to precompile your jsp files into .java files. You can also postcompile those .java files into .class files. Read this link: http://ant.apache.org/manual/OptionalTasks/jspc.html
However, I'll warn you that jspc will create the proper directory structure including subdirectories, but it doesn't put subdirectory information into the .java package declaration. Everything is stuffed into a single package. This means that if you have
maindir/subdir1/index.jsp
and
maindir/subdir2/index.jsp, you'll end up with 2
index_jsp.java files which BOTH have package
maindir. subdir1 and subdir2 won't be put into the package name.
If anyone knows how to get around this, please shout!
E Laverdiere
Greenhorn

Joined: Oct 01, 2003
Posts: 1
Hi,
For security purpose, I have tried many time to make a pre-compile of JSP to be able to remove all *.jsp file leaving only *.class files. But I never made it work.
I am using Tomcat 4.1.xx and it automaticaly compile everything in the work folder. All jsp file is translate in java in an "org.apach.jsp package", even if the jsp page is in a sub-folder of the root.
The problem about the ANT jspc is that it translate the page in another package bellow the "org.apache.jsp" one. I think that is a reason why tomcat cannot find its JSP classes.
The other problem I face is that I put all jsp in the WEB-INF/jsp folder because I use Struts and I dont want my jsp page to be see directly (only via a Controller Servlet see MVC). The jspc compiler will put all my jsp in the org.apache.jsp.WEB_0002dINF.jsp folder... this doesn't help I guess.
ANY CLUE ANYONE ?
See : ANT JSPC to have more info
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Some servers like weblogic allow for precompilation of JSP.


Groovy
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

Welcome to the Ranch Dave P!
You'll find this forum a great place to seek help on JSP pages, and there
aren't many rules you'll have to worry about, but one is that proper names
are required. Please take a look at the
JavaRanch Naming Policy and
change your display name to match it.
Thanks!
bear
JSP Fourm Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
JohnV Varghese
Greenhorn

Joined: Oct 09, 2003
Posts: 7
Hi,
I was able to precompile the jsp's into .class files .
I have used the jspc and javac tasks.
Now should I move them into the work dir of tomcat
pls suggest the next step.
raj pan
Greenhorn

Joined: Oct 13, 2005
Posts: 5
I am having the same problem as mentioned by E Laverdiere. John how did you make it work? Please let us know.Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Precompile