Ahmad Nabi
Ahmad Nabi

Reputation: 43

find.java:14: error: cannot find symbol JAVA

Basically I have a servlet named find.java created with Eclipse IDE.

The Problem is what compiling it I'm getting These errors:

D:\pack>javac find.java
find.java:4: error: package javax.servlet does not exist
import javax.servlet.ServletException;
                    ^
find.java:5: error: package javax.servlet.annotation does not exist
import javax.servlet.annotation.WebServlet;
                               ^
find.java:6: error: package javax.servlet.http does not exist
import javax.servlet.http.HttpServlet;
                         ^
find.java:7: error: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletRequest;
                         ^
find.java:8: error: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletResponse;
                         ^
find.java:12: error: cannot find symbol
public class find extends HttpServlet {
                          ^
  symbol: class HttpServlet
find.java:11: error: cannot find symbol
@WebServlet("/find")
 ^
  symbol: class WebServlet
find.java:14: error: cannot find symbol
        protected void doGet(HttpServletRequest request, HttpServletResponse res
ponse) throws ServletException, IOException {
                             ^
  symbol:   class HttpServletRequest
  location: class find
find.java:14: error: cannot find symbol
        protected void doGet(HttpServletRequest request, HttpServletResponse res
ponse) throws ServletException, IOException {
                                                         ^
  symbol:   class HttpServletResponse
  location: class find
find.java:14: error: cannot find symbol
        protected void doGet(HttpServletRequest request, HttpServletResponse res
ponse) throws ServletException, IOException {
              ^
  symbol:   class ServletException
  location: class find
10 errors

As you might have noticed, Errors are throwing cause of java web-app builtin Variables such as HttpServletRequest or HttpServletResponse

Based on my knowledge I would say This could be caused by not finding the libraries required to compile the file.

So I tried This:

D:\pack>set CLASSPATH="C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib\*.jar":%CLASSPATH%

or

D:\pack>set CLASSPATH="C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib\*":%CLASSPATH%

and

D:\pack>set CLASSPATH="C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib\servlet-api.jar":%CLASSPATH%

Then javac find.java

But didn't worked and also my Environment variables are defined as:

User Variable for Nobody:

Variable Name: CLASS 
Variable Value: C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib;C:\Program Files\Java\jdk8\lib

System Variable:

Variable Name: jdk
Variable Value: C:\Program Files\Java\jdk8

Variable Name: path
Variable Value: C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Java\jdk8\bin

FYI: I have Tested my servlet find.java at Eclipse IDE with sending and responding request which worked find but now I need to deploy it for to create .war file. But I'm getting these Error

Much Appreciations :)

Upvotes: 0

Views: 3947

Answers (1)

Ahmad Nabi
Ahmad Nabi

Reputation: 43

Okay I found My answer, Thought it might help future generation.

So My Guess about it not finding the required libraries wore right. But other than using

set CLASSPATH="C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib\*":%CLASSPATH%

I used:

javac -cp "C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib\*" find.java

Which here -cp tag stands for CLASSPATH Which compiles the program within the same directory as find.java is located.

Good Luck :)

Upvotes: 1

Related Questions