A few comments...
The only thing I can think it may be is the jspc plugin cannot find your
tools.jar for your JDK. I would probably recommend this declaration in
your pom:
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<systemPath>FULL PATH TO YOUR tools.jar</systemPath>
<scope>system</scope>
</dependency>
If you are using a Mac, there is no tools.jar and a reference to the
classes.jar needs to be made instead:
<systemPath>/System/Library/Frameworks/JavaVM.framework/Versions/
1.5/Classes/classes.jar</systemPath>
Also...and maybe unrelated...
Your maven-compiler-plugin declaration didn't work for me. I had to
make a change to get it to work. This worked for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerVersion>1.5</compilerVersion>
</configuration>
</plugin>
I had to add in the <compilerVersion> tag and remove the target/source
tags to get a good compile to occur.
Additionally, I did not see the war plugin declaration in your pom.
That is a critical piece to using the jspc plugin and it is dependent on
the war plugin (in fact, if I had my druthers, the jspc plugin should
really be a part of the war plugin, but I don't make that decision).
You should have something similar to this snippet in your pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>src/webapp</warSourceDirectory>
<webXml>${basedir}/target/jspweb.xml</webXml>
</configuration>
</plugin>
The important component is the jspweb.xml declaration, so the war plugin
knows to use this as the final web.xml.
Let me know if any of these things helped and I will update the doc on
the plugin to reflect these changes.
Thanks,
Jeff
Andreas Gabriel wrote:
> Hi Jeff!
>
> Thanks for the fix. I found out the same solution in the meantime, but I'm
> still struggling with another problem: I now added a tag file I created
> myself and get weird errors from AntCompiler included in Jasper.
> Here is my testdata:
> index.jsp:
> <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
> <%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
>
> <html>
> <body>
> <h2><c:out value="Hello"/> <tags:test testAttribute="World"/>!</h2>
> </body>
> </html>
>
> WEB-INF/tags/test.tag:
> <%@ attribute name="testAttribute" type="java.lang.String" required="true" %>
>
> ${testAttribute}
>
> The Ant JspC task can create the sources and compile them without any
> problems. When I use Maven, the following stacktrace is created:
>
> 29.01.2006 16:53:53 org.apache.jasper.compiler.AntCompiler generateClass
> SCHWERWIEGEND: Error compiling file:
> /V:/Development/testWebapp/target/jsp-source//org/apache/jsp/tag/web\test_tag.java
> [javac] Compiling 1 source file
>
> 29.01.2006 16:53:53 org.apache.jasper.compiler.AntCompiler generateClass
> SCHWERWIEGEND: Javac exception
> Unable to find a javac compiler;
> com.sun.tools.javac.Main is not on the classpath.
> Perhaps JAVA_HOME does not point to the JDK
> at
> org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:105)
> at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:924)
> at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:757)
> at
> org.apache.jasper.compiler.AntCompiler.generateClass(AntCompiler.java:219)
> at org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
> at org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
> at org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
> at
> org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
> at
> org.apache.jasper.servlet.JspServletWrapper.loadTagFile(JspServletWrapper.java:200)
> at
> org.apache.jasper.compiler.TagFileProcessor.loadTagFile(TagFileProcessor.java:515)
> at
> org.apache.jasper.compiler.TagFileProcessor.access$000(TagFileProcessor.java:48)
> at
> org.apache.jasper.compiler.TagFileProcessor$TagFileLoaderVisitor.visit(TagFileProcessor.java:566)
> at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)
> at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
> at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
> at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
> at org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
> at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
> at
> org.apache.jasper.compiler.TagFileProcessor.loadTagFiles(TagFileProcessor.java:584)
> at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:169)
> at org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
> at org.apache.jasper.JspC.processFile(JspC.java:953)
> at org.apache.jasper.JspC.execute(JspC.java:1094)
> at org.apache.jasper.JspC.main(JspC.java:231)
> at org.codehaus.mojo.jspc.JspcMojo.execute(JspcMojo.java:154)
> at
> org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:415)
> at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:531)
> at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:472)
> at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:451)
> at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:303)
> at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:270)
> at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:139)
> at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
> at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
> at org.apache.maven.cli.MavenCli.main(MavenCli.java:249)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
> at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
> at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
> at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
> 29.01.2006 16:53:53 org.apache.jasper.compiler.AntCompiler generateClass
> SCHWERWIEGEND: Env: Compile:
> javaFileName=/V:/Development/testWebapp/target/jsp-source//org/apache/jsp/tag/web\test_tag.java
> classpath=V:\Development\testWebapp\target\classes;D:\Dokumente und
> Einstellungen\Andi\.m2\repository\taglibs\request\1.0.1\request-1.0.1.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\struts\struts\1.2.7\struts-1.2.7.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\displaytag\displaytag\1.0\displaytag-1.0.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\commons-lang\commons-lang\2.0\commons-lang-2.0.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\struts\struts-el\1.2.7\struts-el-1.2.7.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\javax\servlet\jstl\1.1.2\jstl-1.1.2.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\commons-beanutils\commons-beanutils\1.7.0\commons-beanutils-1.7.0.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\commons-collections\commons-collections\2.1.1\commons-collections-2.1.1.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\commons-validator\commons-validator\1.1.4\commons-validator-1.1.4.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\commons-digester\commons-digester\1.6\commons-digester-1.6.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\taglibs\standard\1.1.2\standard-1.1.2.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\itext\itext\0.99\itext-0.99.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\xml-apis\xml-apis\1.0.b2\xml-apis-1.0.b2.jar;D:\Dokumente
> und
> Einstellungen\Andi\.m2\repository\antlr\antlr\2.7.2\antlr-2.7.2.jar;
> cp=v:\development\java\maven-2.0.2\core\boot\classworlds-1.1.jar
> cp=V:\Development\testWebapp\target\classes
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\taglibs\request\1.0.1\request-1.0.1.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\struts\struts\1.2.7\struts-1.2.7.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\displaytag\displaytag\1.0\displaytag-1.0.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\commons-lang\commons-lang\2.0\commons-lang-2.0.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\struts\struts-el\1.2.7\struts-el-1.2.7.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\javax\servlet\jstl\1.1.2\jstl-1.1.2.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\commons-beanutils\commons-beanutils\1.7.0\commons-beanutils-1.7.0.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\commons-collections\commons-collections\2.1.1\commons-collections-2.1.1.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\commons-validator\commons-validator\1.1.4\commons-validator-1.1.4.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\commons-digester\commons-digester\1.6\commons-digester-1.6.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\taglibs\standard\1.1.2\standard-1.1.2.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\itext\itext\0.99\itext-0.99.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\xml-apis\xml-apis\1.0.b2\xml-apis-1.0.b2.jar
> cp=D:\Dokumente und
> Einstellungen\Andi\.m2\repository\antlr\antlr\2.7.2\antlr-2.7.2.jar
> work dir=V:\Development\testWebapp\target\jsp-source
> extension dir=c:\java\jdk1.5.0_01\jre\lib\ext
> srcDir=V:\Development\testWebapp\target\jsp-source
> compilerTargetVM=1.4
> compilerSourceVM=1.4
> include=org/apache/jsp/tag/web/test_tag.java
>
> The java file for the tag is created correctly, but it seems that it fails
> compiling it.
>
> Andi
>
>
>> Hi Andreus,
>>
>> You found a bug in the jspc plugin. I just fixed it. So update your
>> jspc plugin source and rebuild it. Its now up to version 1.3 (don't
>> forget to update your pom to reflect v1.3).
>>
>> Thanks,
>>
>> Jeff
>>
>> Andreas Gabriel wrote:
>>> Hello again!
>>>
>>> I've another question regarding th JspC plugin: I build a very simple
>>> web app based on the webapp archetype and want to precompile the JSPs
>>> with the plugin. I want to use tag libraries like JSTL. I tried to
>>> compile a sample JSP with the following content:
>>> <%@ page language="java" contentType="text/html"
>>> pageEncoding="UTF-8"%> <%@ taglib prefix="c"
>>> uri="http://java.sun.com/jsp/jstl/core"%>
>>> <html>
>>> <body>
>>> <h2>Hello World!</h2>
>>> </body>
>>> </html>
>>>
>>> When I call the JspC plugin, the following error occurs:
>>> [INFO] [jspc:compile {execution: jspc}]
>>> [INFO] jspc args: [-uriroot,
>>> V:\Development\testWebapp/src/main/webapp, -d,
>>> V:\Development\testWebapp/target/jsp-source, -s, -l, -webinc,
>>> V:\Development\testWebapp/target/web-fragment.xml, -p, jsp]
>>> [INFO] V:\Development\testWebapp\target\classes
>>> [INFO] D:\Dokumente und
>>> Einstellungen\Andi\.m2\repository\tomcat\jasper-runtime\5.5.12\jasper-runtime-5.5.12.jar
>>> [INFO] D:\Dokumente und
>>> Einstellungen\Andi\.m2\repository\tomcat\jasper-compiler\5.5.12\jasper-compiler-5.5.12.jar
>>> [INFO] D:\Dokumente und
>>> Einstellungen\Andi\.m2\repository\taglibs\standard\1.1.2\standard-1.1.2.jar
>>> [INFO] D:\Dokumente und
>>> Einstellungen\Andi\.m2\repository\javax\servlet\jstl\1.1.2\jstl-1.1.2.jar
>>> 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 deployed with this application
>>>
>>> My pom.xml looks like this:
>>> <project xmlns="http://maven.apache.org/POM/4.0.0"
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
>>> http://maven.apache.org/maven-v4_0_0.xsd">
>>> <modelVersion>4.0.0</modelVersion>
>>> <groupId>com.webapp</groupId>
>>> <artifactId>testWebapp</artifactId>
>>> <packaging>war</packaging>
>>> <version>1.0-SNAPSHOT</version>
>>> <name>Maven Webapp Archetype</name>
>>> <url>http://maven.apache.org</url>
>>> <build>
>>> <finalName>testWebapp</finalName>
>>> <plugins>
>>> <!-- use Java 5 compiler settings -->
>>> <plugin>
>>> <groupId>org.apache.maven.plugins</groupId>
>>> <artifactId>maven-compiler-plugin</artifactId>
>>> <configuration>
>>> <source>1.5</source>
>>> <target>1.5</target>
>>> </configuration>
>>> </plugin>
>>>
>>> <!-- precompile JSPs -->
>>> <plugin>
>>> <groupId>org.codehaus.mojo</groupId>
>>> <artifactId>jspc-maven-plugin</artifactId>
>>> <version>1.2</version>
>>> <executions>
>>> <execution>
>>> <id>jspc</id>
>>> <phase>generate-sources</phase>
>>> <goals>
>>> <goal>compile</goal>
>>> </goals>
>>> </execution>
>>> </executions>
>>> </plugin>
>>> </plugins>
>>> </build>
>>> <dependencies>
>>> <!-- Servlet 2.4 / JSP 2.0 APIs -->
>>> <dependency>
>>> <groupId>javax.servlet</groupId>
>>> <artifactId>servlet-api</artifactId>
>>> <version>2.4</version>
>>> <scope>provided</scope>
>>> </dependency>
>>> <dependency>
>>> <groupId>javax.servlet</groupId>
>>> <artifactId>jsp-api</artifactId>
>>> <version>2.0</version>
>>> <scope>provided</scope>
>>> </dependency>
>>>
>>> <!-- JSTL implementation -->
>>> <dependency>
>>> <groupId>javax.servlet</groupId>
>>> <artifactId>jstl</artifactId>
>>> <version>1.1.2</version>
>>> </dependency>
>>> <dependency>
>>> <groupId>taglibs</groupId>
>>> <artifactId>standard</artifactId>
>>> <version>1.1.2</version>
>>> </dependency>
>>>
>>>
>>> <!-- Jasper for compiling the JSPs -->
>>> <dependency>
>>> <groupId>tomcat</groupId>
>>> <artifactId>jasper-compiler</artifactId>
>>> <version>5.5.12</version>
>>> </dependency>
>>> <dependency>
>>> <groupId>tomcat</groupId>
>>> <artifactId>jasper-runtime</artifactId>
>>> <version>5.5.12</version>
>>> </dependency>
>>> </dependencies>
>>> </project>
>>>
>>> The web.xml looks like this:
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <web-app id="test" version="2.4"
>>> xmlns="http://java.sun.com/xml/ns/j2ee"
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
>>> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
>>>
>>> <!-- [INSERT FRAGMENT HERE] -->
>>>
>>> <display-name>Archetype Created Web Application</display-name>
>>>
>>> </web-app>
>>>
>>> As standard.jar contains the file c.tld in the META-INF directory with
>>> the tag library definition for the specified URI, the library should
>>> be present in the classpath
>>>
>>> Thanks,
>>> Andi
>>>
>
>