Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35168

Re: How to direct javac to search a jar file?

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Nigel Wade <nmw@local.domain>
Newsgroups comp.lang.java.programmer
Subject Re: How to direct javac to search a jar file?
Date Tue, 2 Aug 2016 17:50:56 +0100
Lines 43
Message-ID <e0c1bgFudoeU1@mid.individual.net> (permalink)
References <nnqbs5$gs6$1@gioia.aioe.org>
Mime-Version 1.0
Content-Type text/plain; charset=gbk; format=flowed
Content-Transfer-Encoding 8bit
X-Trace individual.net lKL8/GeCCn5lTNcgLk0CKg2ZF+OIqEPCKlHbBHzURz6+AhljGP
Cancel-Lock sha1:azpR54JVeUWalSjSAyNHVBKStlI=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0
In-Reply-To <nnqbs5$gs6$1@gioia.aioe.org>
Xref csiph.com comp.lang.java.programmer:35168

Show key headers only | View raw


On 02/08/16 15:48, parmenides wrote:
> Hi,
>
>     I'm learning how to write servlet. There is an example like this:
>
> package home.parmenides;
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> public class Hello extends HttpServlet{
>     public void init(ServletConfig config) throws ServletException{
>        super.init(config);
>     }
>     public void service(HttpServletRequest reqest,HttpServletResponse response) throws IOException{
>        response.setContentType("text/html;charset=utf-8");
>        PrintWriter out=response.getWriter();
>        out.println("<html><body>");
>        out.println("<h2>Welcome to servlet。</h2>");
>        out.println("</body></html>");
>     }
> }
>
> Now that packages of servlet are imported. According to the tutorial, these packages are archived in the C:\Tomcat 9.0\lib\servlet-api.jar, and it is necessary to copy the file to a JDK directory, namely C:\java\jre\lib. This works indeed. But, I think it is more convenience to let javac to find the file rather than copying file. I added the following path into the classpath:
>                 C:\Tomcat 9.0\lib
> But, javac can not find the servlet-api.jar. How can I deal with the problem? Thanks.

Specifying a folder won't include jar files. A folder in the classpath is used as the root of a tree containing class files.
To include a single jar specify the path to that jar file. To include all jar files in a folder use the syntax <folder>/*, where <folder> is the path to the folder in question.

The required classpath is probably:
javac -cp C:"\Tomcat 9.0\lib\servlet-api.jar";"."

or
javac -cp C:"\Tomcat 9.0\lib\*";"."

if more jar's are needed.
If you specify a classpath for the jar then you need to ensure that you also include the default classpath of ".", the current folder, or classes in the current folder/tree won't be found.

The definitive resource on setting the classpath is the Oracle documentation at:
http://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html

Note that changing the CLASSPATH environment variable is considered bad. It is global, and affects every Java program you compile, or run.
If you try to keep adding every possible classpath to it which every compilation and execution requires it will become a problem.

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to direct javac to search a jar file? parmenides <xparmenides@yahoo.com> - 2016-08-02 22:48 +0800
  Re: How to direct javac to search a jar file? Eric Douglas <e.d.programmer@gmail.com> - 2016-08-02 08:11 -0700
  Re: How to direct javac to search a jar file? Nigel Wade <nmw@local.domain> - 2016-08-02 17:50 +0100
    Re: How to direct javac to search a jar file? Eric Douglas <e.d.programmer@gmail.com> - 2016-08-02 10:49 -0700
      Re: How to direct javac to search a jar file? Lew <lewbloch@gmail.com> - 2016-08-02 10:53 -0700
        Re: How to direct javac to search a jar file? Eric Douglas <e.d.programmer@gmail.com> - 2016-08-02 11:11 -0700
          Re: How to direct javac to search a jar file? Lew <lewbloch@gmail.com> - 2016-08-02 13:23 -0700
            Re: How to direct javac to search a jar file? Eric Douglas <e.d.programmer@gmail.com> - 2016-08-03 05:32 -0700
              Re: How to direct javac to search a jar file? Nigel Wade <nmw@local.domain> - 2016-08-03 14:30 +0100
                Re: How to direct javac to search a jar file? Eric Douglas <e.d.programmer@gmail.com> - 2016-08-03 12:02 -0700
                Re: How to direct javac to search a jar file? Arne Vajhøj <arne@vajhoej.dk> - 2016-08-03 19:34 -0400
                Re: How to direct javac to search a jar file? Nigel Wade <nmw@local.domain> - 2016-08-04 14:22 +0100
              Re: How to direct javac to search a jar file? Arne Vajhøj <arne@vajhoej.dk> - 2016-08-03 21:25 -0400
              Re: How to direct javac to search a jar file? Lew <lewbloch@gmail.com> - 2016-08-05 15:31 -0700

csiph-web