2

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');
Community
  • 1
  • 1
Btc Sources
  • 1,912
  • 2
  • 30
  • 58
  • Do you get same error: `javax.servlet.jsp does not exist`? It should find `JspWriter` in `jsp-api.jar`. Look in jar to see if those classes are really there. Try post your code, or at least, `imports` to see if someone is missed. – Albert Mar 06 '15 at 11:33
  • Added some code, and a look of the jar file. Thanks for helping Albert. – Btc Sources Mar 06 '15 at 11:50
  • Still has no sense to me such error. Is it the only error you have? Is it any other output when `javac` is run? – Albert Mar 06 '15 at 12:15
  • Yes, and plus the lines where a JspWriter is used – Btc Sources Mar 06 '15 at 13:49

2 Answers2

3

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

Albert
  • 1,156
  • 1
  • 15
  • 27
  • It solved the problem Albert, thanks. At the beginning it didn't work cause I was so messed up and added this jar to the wrong class when compiling! – Btc Sources Mar 07 '15 at 13:27
2

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

Charlie
  • 639
  • 9
  • 19