Java 在 Windows 7 中使用命令提示符设置类路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18802098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 11:12:47  来源:igfitidea点击:

Setting Classpath using command prompt in Windows 7

java

提问by user2779202

I am compiling my code through Windows 7 using command prompt -- here are details :

我正在使用命令提示符通过 Windows 7 编译我的代码 - 以下是详细信息:

I set the class path like this :

我这样设置类路径:

set classpath= %classpath%;C:\java-programes\Servlet-Programing-new1\TotalUsersOnline\lib\servlet-api\*.jar;C:\java-programes\Servlet-Programing-new1\TotalUsersOnline\lib\servlet\*.jar;

and then I tried to compile my file like :

然后我尝试编译我的文件,如:

javac -d ..\classe com\java\controller\LoginServlet.java

output:

输出:

com\java\controller\LoginServlet.java:7: package javax.servlet does not exist
import javax.servlet.RequestDispatcher;
                    ^

com\java\controller\LoginServlet.java:8: package javax.servlet does not exist
import javax.servlet.ServletException;
                    ^

com\java\controller\LoginServlet.java:9: package javax.servlet.http does not exist
import javax.servlet.http.HttpServlet;
                         ^

com\java\controller\LoginServlet.java:10: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletRequest;
                         ^

com\java\controller\LoginServlet.java:11: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletResponse;
                         ^

com\java\controller\LoginServlet.java:13: cannot find symbol
symbol: class HttpServlet
public class LoginServlet extends HttpServlet{
                                  ^

com\java\controller\LoginServlet.java:21: cannot find symbol
symbol  : class HttpServletRequest
location: class com.java.controller.LoginServlet
        public void service(HttpServletRequest request, HttpServletResponse response)
                            ^

com\java\controller\LoginServlet.java:21: cannot find symbol
symbol  : class HttpServletResponse
location: class com.java.controller.LoginServlet
        public void service(HttpServletRequest request, HttpServletResponse response)
                                                        ^

com\java\controller\LoginServlet.java:22: cannot find symbol
symbol  : class ServletException
location: class com.java.controller.LoginServlet
                        throws ServletException, IOException {
                               ^

com\java\controller\LoginServlet.java:46: cannot find symbol
symbol  : class RequestDispatcher
location: class com.java.controller.LoginServlet
                RequestDispatcher dispatcher = request.getRequestDispatcher("/home.jsp");
                ^

com\java\controller\LoginServlet.java:20: method does not override or implement a method from a supertype
        @Override

after that I tried like :

之后我尝试过:

javac  -classpath C:\java-programes\Servlet-Programing-new1\TotalUsersOnline\lib\servlet-api\*.jar com\java\controller\LoginServlet.java

then the output I got is :

那么我得到的输出是:

javac: invalid flag: C:\java-programes\Servlet-Programing-new1\TotalUsersOnline\lib\servlet-api\servlet-api-2.5.jar
Usage: javac <options> <source files>
use -help for a list of possible options

Please Help on this As I am stuck on this point and I am not getting anything..how to go forward.I need help badly :(

请帮助解决这个问题因为我被困在这一点上,我没有得到任何东西..如何前进。我非常需要帮助:(

Thanks in Advance

提前致谢

回答by Gyanendra Dwivedi

Understanding class path wildcards

了解类路径通配符

Class path entries can contain the basename wildcard character , which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For example, the class path entry foo/specifies all JAR files in the directory named foo. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory.

A class path entry that contains * will not match class files. To match both classes and JAR files in a single directory foo, use either foo;foo/* or foo/*;foo. The order chosen determines whether the classes and resources in foo are loaded before JAR files in foo, or vice versa.

Subdirectories are not searched recursively. For example, foo/* looks for JAR files only in foo, not in foo/bar, foo/baz, etc.

类路径条目可以包含基本名称通配符,这被认为等同于指定目录中所有文件的列表,扩展名为 .jar 或 .JAR。例如,类路径条目 foo/指定名为 foo 的目录中的所有 JAR 文件。仅由 * 组成的类路径条目扩展为当前目录中所有 jar 文件的列表。

包含 * 的类路径条目将不匹配类文件。要匹配单个目录 foo 中的类和 JAR 文件,请使用 foo;foo/* 或 foo/*;foo。选择的顺序决定了 foo 中的类和资源是在 foo 中的 JAR 文件之前加载,反之亦然。

不递归搜索子目录。例如,foo/* 只在 foo 中查找 JAR 文件,而不在 foo/bar、foo/baz 等中查找。

Must read full detail here, it is awesome http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html

必须在这里阅读完整的细节,它很棒http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html