Première JSP et problème "cannot be resolved to a type"
Bonjour à tous,
j'essaye de mettre en place une application Java-J2EE et donc je commence simple : l'exemple HelloWorld .... simple : mais pas tant que ça puisque ça ne fonctionne pas :(
J'ai pris l'exemple suivant : http://eboizou.developpez.com/tutoriel/java/J2EE/
Je commence par la première partie du tuto, sauf que je développe directement sous Eclipse ! J'utilise Ant pour déployer. Voici ma "config" :
- un fichier web.xml dans /config/
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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"
version="2.4">
<description>NeOdit</description>
<display-name>NeOdit</display-name>
<taglib>
<taglib-uri>/taglib</taglib-uri>
<taglib-location>/WEB-INF/taglib.tld</taglib-location>
</taglib>
</web-app> |
- un fichier taglib.tld dans /web/WEB-INF/ :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <?xml version="1.0" encoding="ISO-8859-1" ?>
<taglib 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/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>TagLib de NeOdit</description>
<tlib-version>1.0</tlib-version>
<short-name>taglib</short-name>
<tag>
<description>Test de NeOdit !</description>
<name>HelloWorld</name>
<tag-class>HelloWorld</tag-class>
<body-content>empty</body-content>
</tag>
</taglib> |
- un fichier HelloWorld.java dans /src/ :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
public class HelloWorld extends TagSupport
{
public int doStartTag() throws JspException
{
try { pageContext.getOut().println("Hello World !");}
catch (IOException e) { throw new JspException("I/O Error", e);}
return SKIP_BODY;
} // end of doStartTag method
} // end of the class |
- un fichier index.jsp dans /web/ :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <%@ taglib uri="/taglib" prefix="taglib" %>
<html>
<head>
<title>NeOdit</title>
</head>
<body>
<h1>Premier titre H1</h1>
<hr>
<p>Ce tag affiche "Hello, World!", il ne contient pas de body.</p>
<br>
<b><u>Resultat : </u></b>
<taglib:HelloWorld/>
</body>
</html> |
voici mon fichier build.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| <project name="NeOdit" default="compile" basedir=".">
<property name="app.name" value="NeOdit" />
<property name="app.path" value="/${app.name}" />
<property name="app.version" value="0.2.2" />
<property name="build.home" value="${basedir}/build" />
<property name="dist.home" value="${basedir}/dist" />
<property name="docs.home" value="${basedir}/docs" />
<property name="conf.home" value="${basedir}/config" />
<property name="src.home" value="${basedir}/src" />
<property name="web.home" value="${basedir}/web" />
<!-- This inclusion may possibly override values defined above -->
<property file="build.properties" />
<!-- Classpath for compilation -->
<path id="compile.classpath">
<!-- Include all JAR files that will be included in /WEB-INF/lib -->
<fileset dir="lib" includes="*.jar" />
</path>
<!-- Compilation properties -->
<property name="compile.debug" value="true" />
<property name="compile.deprecation" value="false" />
<property name="compile.optimize" value="true" />
<!-- Cleanup and recompile the whole thing -->
<target name="all" depends="clean, compile" description="Clean build and dist directories, then compile" />
<!-- Cleanup -->
<target name="clean" description="Delete old build and dist directories, and war">
<delete dir="${build.home}" />
<delete dir="${dist.home}" />
<delete file="NeOdit.war" />
<delete file="NeOdit-${app.version}.zip" />
</target>
<!-- Compile -->
<target name="compile" depends="prepare" description="Compile Java sources">
<!-- Compile Java classes as necessary -->
<mkdir dir="${build.home}/WEB-INF/classes" />
<javac srcdir="${src.home}" destdir="${build.home}/WEB-INF/classes" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}">
<classpath refid="compile.classpath" />
</javac>
<!-- Copy application resources -->
<copy todir="${build.home}/WEB-INF/classes">
<fileset dir="${src.home}" excludes="**/*.java **/*.example" />
</copy>
</target>
<!-- To distribute the app -->
<target name="dist" depends="war" description="Create binary distribution">
<delete dir="${dist.home}" /><!-- Avoid zipping old files -->
<mkdir dir="${dist.home}"/>
<mkdir dir="${dist.home}/NeOdit"/>
<copy file="config/NeOdit.xml" todir="${dist.home}/NeOdit"/>
<copy file="NeOdit.war" todir="${dist.home}/NeOdit"/>
<zip destfile="NeOdit-${app.version}.zip" basedir="${dist.home}"/>
</target>
<!-- Build the WAR file -->
<target name="war" depends="compile">
<war destfile="NeOdit.war" webxml="${conf.home}/web.xml" basedir="${build.home}" />
</target>
<!-- Deploy -->
<target name="deploy" depends="war" description="Install app to webserver">
<copy file="NeOdit.war" todir="${catalina.home}/webapps" />
</target>
<!-- Undeploy -->
<target name="undeploy" description="Remove app from webserver">
<delete file="${catalina.home}/webapps/NeOdit.war" />
<delete dir="${catalina.home}/webapps/NeOdit" />
</target>
<!-- Redeploy -->
<target name="redeploy" depends="undeploy, deploy" description="Remove and then install app on webserver" />
<!-- Build JavaDoc -->
<target name="javadoc" depends="compile" description="Create Javadoc API documentation">
<mkdir dir="${dist.home}/docs/api" />
<javadoc sourcepath="${src.home}" destdir="${dist.home}/docs/api" packagenames="*">
<classpath refid="compile.classpath" />
</javadoc>
</target>
<!-- Prepare things needed for compilation -->
<target name="prepare">
<!-- Create build directories as needed -->
<mkdir dir="${build.home}" />
<mkdir dir="${build.home}/WEB-INF" />
<mkdir dir="${build.home}/WEB-INF/classes" />
<!-- Copy static content of this web application -->
<copy todir="${build.home}">
<fileset dir="${web.home}" />
</copy>
<!-- Copy external dependencies as required -->
<mkdir dir="${build.home}/WEB-INF/lib" />
<copy todir="${build.home}/WEB-INF/lib">
<fileset dir="${basedir}/lib" excludes="junit-4.4.jar,javaee.jar" />
</copy>
<mkdir dir="${build.home}/WEB-INF/classes/config" />
<copy todir="${build.home}/WEB-INF/classes/config">
<fileset dir="${basedir}/config" includes="repository.xml, *.cnd, mime.types"/>
</copy>
<!-- Copy web content (Screen XSLs, images, CSS, JS) -->
<mkdir dir="${build.home}/js"/>
<copy todir="${build.home}/js">
<fileset dir="${web.home}/js" />
</copy>
<mkdir dir="${build.home}/css"/>
<copy todir="${build.home}/css">
<fileset dir="${web.home}/css" />
</copy>
<mkdir dir="${build.home}/xsl"/>
<copy todir="${build.home}/xsl">
<fileset dir="${web.home}/xsl" />
</copy>
<mkdir dir="${build.home}/img"/>
<copy todir="${build.home}/img">
<fileset dir="${web.home}/img" />
</copy>
<mkdir dir="${build.home}/img/flags"/>
<copy todir="${build.home}/img/flags">
<fileset dir="${web.home}/img/flags"/>
</copy>
<!-- Copy static files from external dependencies as needed -->
</target>
</project> |
J'ai créé un projet classique dans Eclipse pour faire tous ces fichiers. Pour déployer le tout, je fais un Ant Build en précisant bien l'inclusion du jar javaee.jar dans mon classpath.
Et voila l'erreur que j'ai :
Citation:
org.apache.jasper.JasperException: Impossible de compiler la classe pour la JSP:
Une erreur s'est produite � la ligne: 13 dans le fichier jsp: /index.jsp
HelloWorld cannot be resolved to a type
10: <p>Ce tag affiche "Hello, World!", il ne contient pas de body.</p>
11: <br>
12: <b><u>Resultat : </u></b>
13: <taglib:HelloWorld/>
14: </body>
15: </html>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Quelqu'un peut m'aider svp ? Je n'ai pas trouvé de solution dans Google ni dans les autres posts sur internet :(