编译一个Servlet在Ubuntu返回错误 [英] Compiling a Servlet in Ubuntu returns errors
问题描述
我试图编译源$ C $ C在web应用中使用。我知道的事情在Ubuntu不喜欢的东西在Windows和设置的classpath
永久是不是一个好的事情,所以我决定暂时设置标志。这是我的命令在终端:
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类的src / COM /例子/ *的java
我想实现的是:结果
的.java
文件 com。示例
的.class
文件直接到相应的目录 WEB-INF
文件夹What I am trying to achieve is:
.java
files in the package com.example
.class
files directly to the appropriate directories WEB-INF
folder 尽管设置的classpath
我得到的错误:
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
我知道,如果没有设置classpath中适当出现这些错误。请帮我这个。告诉我什么是错的,我怎么去纠正它,以及如何避免它的未来。
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.
类文件[搜索路径: /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]
[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]
推荐答案
在分割位的任务,我们只是先尝试编译java文件。后来检查如何移动类文件。
Split the task in bits, and let's just try to compile the java files first. Later check for how to move the class file.
该错误确实是说,它没有找到所需的类,所以罐子未正确添加到类路径。勾选此
The error indeed says that it didn't find the required class, so the jar isn't added correctly to the classpath. Check this
javac -classpath .:/usr/share/tomcat7/servlet-api.jar src/com/example/*.java
确保瓶子是在给定位置present。也可以尝试从src文件夹运行此并给予路径COM /例子/ *。java的
Ensure the jar is present at the given location. Also try running this from the src folder and giving the path as com/example/*.java
这篇关于编译一个Servlet在Ubuntu返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!