I am attempting to compile source code to be used in a webapp. I know things in Ubuntu are not like things in Windows and that setting classpath
permanently is not a good thing to do so I decided to set the flag temporarily. Here is my command in terminal:
littlejavachild@ubuntu:~/LittleJavaChild/ServletProjects/beerV1$ javac -cp "/usr/share/tomcat7/servlet-api.jar" -d classes src/com/example/*.java
What I am trying to achieve is:
.java
files in the package com.example
.class
files directly to the appropriate directories WEB-INF
folder Despite setting the classpath
I get the errors:
src/com/example/ListenerTester.java:3: error: package javax.servlet does not exist
import javax.servlet.*;
^
src/com/example/ListenerTester.java:4: error: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
src/com/example/ListenerTester.java:7: error: cannot find symbol
public class ListenerTester extends HttpServlet{
^
symbol: class HttpServlet
src/com/example/ListenerTester.java:8: error: cannot find symbol
public void doGet(HttpServletRequest request,
^
symbol: class HttpServletRequest
location: class ListenerTester
src/com/example/ListenerTester.java:9: error: cannot find symbol
HttpServletResponse response) throws IOException, ServletException {
^
symbol: class HttpServletResponse
location: class ListenerTester
src/com/example/ListenerTester.java:9: error: cannot find symbol
HttpServletResponse response) throws IOException, ServletException {
^
symbol: class ServletException
location: class ListenerTester
src/com/example/MyServletContextListener.java:2: error: package javax.servlet does not exist
import javax.servlet.*;
^
src/com/example/MyServletContextListener.java:4: error: cannot find symbol
public class MyServletContextListener implements ServletContextListener{
^
symbol: class ServletContextListener
src/com/example/MyServletContextListener.java:5: error: cannot find symbol
public void contextInitialized(ServletContextEvent event){
^
symbol: class ServletContextEvent
location: class MyServletContextListener
src/com/example/MyServletContextListener.java:12: error: cannot find symbol
public void contextDestroyed(ServletContextEvent event){
^
symbol: class ServletContextEvent
location: class MyServletContextListener
src/com/example/ListenerTester.java:14: error: cannot find symbol
Dog dog = (Dog) getServletContext().getAttribute("dog");
^
symbol: method getServletContext()
location: class ListenerTester
src/com/example/MyServletContextListener.java:6: error: cannot find symbol
ServletContext sc = event.getServletContext();
^
symbol: class ServletContext
location: class MyServletContextListener
I know these errors occur when the classpath is not set properly. Please help me with this. Tell me what is wrong and how do I go about correcting it and how to avoid it in future.
Update with -verbose
[search path for class files: /usr/lib/jvm/java-7-openjdk-i386/jre/lib/resources.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/rt.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/sunrsasign.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/jsse.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/jce.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/charsets.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/netx.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/plugin.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/rhino.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/jfr.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/classes,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/localedata.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/sunjce_provider.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/dnsns.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/java-atk-wrapper.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/pulse-java.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/sunpkcs11.jar,/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/zipfs.jar,.,/usr/share/tomcat7/servlet-api.jar]
javac
directly. – Tim Benderjavac
will not be the greatest asset to you professionally. You're much better off expending your efforts in learning a build system than you are in struggling with this. – Tim Bender