my dog learned polymorphism*
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant task to compile JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant task to compile JSP" Watch "Ant task to compile JSP" New topic
Author

Ant task to compile JSP

Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Hello,
I was testing ant with JSP compilation.
My JSPC task is defined as follows

<!-- *********************************************************************
* jspc - Compile JSP files.
********************************************************************** -->
<target name="jspc" description="Compile JSP source." depends="init">
<path id="jspc.ref.classpath2">
<pathelement path="${env.CLASSPATH}"/>
<pathelement location="${TESTPROJECT.src}"/>
<pathelement location="${TESTPROJECT.build.classes}"/>
<pathelement location="${src}"/>
<pathelement location="${build.classes}"/>
<fileset dir="${TESTPROJECT.lib}" includes="*.jar"/>
<fileset dir="${ant.home}/lib" includes="*.jar"/>
<fileset dir="${TESTPROJECT.build.lib}" includes="*.jar"/>
<fileset dir="${build.lib}" includes="*.jar"/>
</path>

<!-- *********************************************************************
* JSP compile: ROOT
********************************************************************** -->
<compile-jsp name="ROOT" uriroot="${maven.src.main.jsp}/ROOT"
outputdir="${build.jspc_base}/_" />

</target>
Error:
jspc:
[echo]
[echo] ROOT [jsp->java->class]
[echo] [jsp->java] Compiling jsp source to java source...
[java] - Internal Error: File /WEB-INF/web.xml not found
[java] org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files de ployed with this application
[echo] [java->class] Compiling java source to java bytecode...

Please let me know how i can get it working.


SCJP, SCWCD, SCBCD
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

It's expecting you to provide a WEB-INF/web.xml file that itself refers to the tag library http://java.sun.com/jsp/jstl/core.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
The tag library http://java.sun.com/jsp/jstl/core is defined by JSTL library. How can i include the library in the ANT file.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

Deepak Jain wrote:The tag library http://java.sun.com/jsp/jstl/core is defined by JSTL library. How can i include the library in the ANT file.


Are the JSTL jar files (standard.jar & jstl.jar) in your classpath ? Normally this is what required for compiling the JSPs.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Thought so, but your reply was a trigger to actually try that. It has fixed part of the error.
Now i see the following error
[java] - Internal Error: File /WEB-INF/web.xml not found

where as earlier i used to see

[java] - Internal Error: File /WEB-INF/web.xml not found
[java] org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files de ployed with this application

Now the JSP's are compiling into Java classes.
How do i avoid the below error
[java] - Internal Error: File /WEB-INF/web.xml not found


Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

Now i see the following error
[java] - Internal Error: File /WEB-INF/web.xml not found


That's may be you haven't specify the webxml attribute, which is not required actually (I haven't tried it though) ... But jspc is deprecated here.


jspc (deprecated)

Deprecated if you use this task with Tomcat's Jasper JSP compiler, you should seriously consider using the task shipping with Tomcat instead. This task is only tested against Tomcat 4.x. There are known problems with Tomcat 5.x that won't get fixed in Ant, please use Tomcat's jspc task instead.
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Its a huge project that am working on and i don;t have control of changing ANT itself. Infact am having tough time to convincing people to use JSTL and scriptless-FREE JSP pages, I am the one who is putting all the effort and still guys are not ready to use JSTL and approach of Script-free pages.

How should specify webxml attribute? Can you please edit the JSPC task that i had shared with the post.
Thanks a lot for your reply, to be honest i wasn;t expecting any replies.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

Deepak Jain wrote:Its a huge project that am working on and i don;t have control of changing ANT itself.


What you mean by that? Changing your build.xml or ant libraries? If the latter, I don't think it's necessary.

How should specify webxml attribute?


Check the documentation and try it . BTW why are you compiling the JSPs yourself?
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Vijitha Kumara wrote:
Deepak Jain wrote:Its a huge project that am working on and i don;t have control of changing ANT itself.


What you mean by that? Changing your build.xml or ant libraries? If the latter, I don't think it's necessary.

How should specify webxml attribute?


Check the documentation and try it . BTW why are you compiling the JSPs yourself?


I can only assume he wants to precompile the JSPs to get any warnings early and/or deliver precomipled JSPs to the web server (some web servers compile the first time you hit the page which makes for bad user experience).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Ant task to compile JSP
 
Similar Threads
ant exception
HOW TO COMPILE JAVA FILES PROGAMMATICALLY
war from ant not running
package javax.ejb does not exist
ant tomcat dist -wrong file structure specified