Btc Sources
Btc Sources

Reputation: 2041

Compile error: package javax.servlet.jsp does not exist

first of all, this is not a duplicated post, since:

1.- I'm building without any IDE, Ant nor Maven.

2.- I've already looked for it, and tried the solutions given in: Compile error: package javax.servlet does not exist.

However, my problem is still here.

Basically, I'm trying to import:

import javax.servlet.jsp.JspWriter;

But at compiling time I get:

./src/tfg/lti/UI/Painter.java:4: error: package javax.servlet.jsp does not exist import javax.servlet.jsp.JspWriter

I was compiling the class like the first of next lines, and after looking for solutions, I tried the next ones, since an user said that the link files gave him troubles and needed to point to the real file:

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/ ./src/tfg/lti/Config/Setup.java

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/tomcat6/lib/servlet-api.jar ./src/tfg/lti/Config/Setup.java

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/java/servlet-api.jar ./src/tfg/lti/Config/Setup.java

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/java/servlet-api-2.5.jar ./src/tfg/lti/Config/Setup.java

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/java/servlet-api-2.4.jar ./src/tfg/lti/Config/Setup.java

As You can see, I tried with all the posibble link to the files I've for the package, but I still obtain the error when compiling. There You can see the files in a quick view:

ll /usr/share/tomcat6/lib/ | grep servlet
lrwxrwxrwx 1 root root   30 jul 24  2014 servlet-api.jar -> ../../java/servlet-api-2.5.jar

ll /usr/share/java/ | grep servlet
-rw-r--r--   1 root root    93251 oct 22  2011 servlet-api-2.4.jar
-rw-r--r--   1 root root    88360 jul 24  2014 servlet-api-2.5.jar
lrwxrwxrwx   1 root root       19 oct 22  2011 servlet-api.jar -> servlet-api-2.4.jar

Any idea about it?

Thank you in advance

Update: Since Albert told me to use jsp-api in classpath, I tried the following ones:

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/tomcat6/lib/servlet-api.jar:/usr/share/tomcat6/lib/jsp-api.jar ./src/tfg/lti/Config/Setup.java
javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/java/servlet-api-2.4.jar:/usr/share/java/jsp-api-2.1.jar ./src/tfg/lti/Config/Setup.java

With the same results. The files jsp-api that are available for me:

ll /usr/share/tomcat6/lib/ | grep jsp-api
lrwxrwxrwx 1 root root   26 jul 24  2014 jsp-api.jar -> ../../java/jsp-api-2.1.jar

Update 2: Adding what jsp-api.jar contains (you're right Albert, JspWriter is inside it). Adding some code (imports and something more).

jsp-api-2.1.jar content: jsp-api-2.1.jar content

Code from the class that is giving the faulire:

Imports:

import java.util.Date;
import javax.servlet.jsp.JspWriter;
import java.io.IOException;
import tfg.lti.Config.TextFileWorker;

First function, which calls the function where JspWriter is used:

public void BuildUI(boolean periodEnabled, Date nextDeliver, 
        String nextDeliveryTitle, String path, JspWriter webWriter)

Call for the function:

BuildLoadUI(nextDeliveryTitle, path, webWriter);

Part of the target function which I need to work:

private void BuildLoadUI(String nextDeliveryTitle, String path,
                                JspWriter webWriter) throws IOException
{

    TextFileWorker Reader = new TextFileWorker();
    String[] fileString;

    webWriter.print("<h2>Evaluación - " + nextDeliveryTitle + "</h2>" + '\n');

Upvotes: 2

Views: 8704

Answers (2)

Charlie
Charlie

Reputation: 753

if you are using maven, add this in:

<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.1</version>
</dependency>

where version should match yours in repository

Upvotes: 2

Albert
Albert

Reputation: 1216

I think you missed to add lib/jsp-api.jar in your classpath, which is where those classes are.

Upvotes: 3

Related Questions