Note: The following article comes from the network
As
The operating system uses PATH to search for executables, the Java running environment also traversed ClassPath to find classes, even if the HelloWorld is simple, JVM will also traverse each path defined by classpath until the corresponding file is found.
I believe that the system used is not 2K is XP, and then set the path as follows:
My Computer -> Properties -> Advanced -> Environmental Variables
Then add: C: / JDK / LIB after the path of the environment variable: C: / JDK / lib
It can also be configured: C: / JDK / BIN;; c: /jdk/lib/dt.jar; c: /jdk/lib/tools.jar
★ Remember: Environment variables. Remember can not be small, it represents the current path, if there is less error, etc. will say!
Dt.jar is about the class library of the operating environment, Tools.jar is the class library about some tools.
If there is no configuration: C: / JDK / BIN, "Javac 'is not internal or external command will appear, nor is it a running program or batch file." This error.
Below we will write an example program:
Open Editplus, create a new Java file, please enter the following, you want a word without leakage, and select the case:
Public class helloworld {public static void main (string [] args) {system.out.println ("Hello, World!");}}
Then save this file (Ctrl S) to HelloWorld.java, Java is sized, so case sensation must be divided, it is helloworld.java or other.
Run: Start -> Run -> cmd
Switch the directory to the current directory in the console:
Javac HelloWorld.javajava HelloWorld
You will see the output Hello, World!
Javac is a compiled command, which compiles helloWorld.java into HelloWorld.class
Java is an explanation command, and JVM explains the HelloWorld.class.
at this time:
1. If Exception In Thread "Main" java.lang.noclassdeffounderror: HelloWorld is that you didn't add that in the environment variable. (Dot)
2, if Exception in Thread "main" java.lang.nosuchmethoderror: main or helloworld.java: 1: public class helloworld Must Be defined in a file called
"HelloWorld.java".
That is, you don't know how to write this HelloWorld, or if you have not saved as HelloWorld.java. This name must be the same as the name of the public class.
For the problem of environment variables, I will say this, let me say how to compile and run in Editplus, in Tools-> Parameter -> Configuring User Tools
1. Add a tool (add application)
Menu text: Compile Java Program
Procedure: c: /jdk/bin/javac.exe
Parameters: File Name
Initial directory: file directory
2. Add Tools (Add Applications)
Menu text: Run Java Program
Program: c: /jdk/bin/java.exe
Parameters: File Name (excluding extensions)
Initial directory: file directory
The tool set name can be added, such as Debug Java Program.
Then in the Tools drop-down menu, you will see two options of Compile Java Program and Run Java Program, you can use Ctrl 1 compile and Ctrl 2 running programs.
Let's discuss the operating environment of the servlet:
To run the servlet, JSP / Servlet Container, I suggest that beginners use Tomcat.
Tomcat (latest version 5.0): Tomcat-5 / nightly / jakarta-tomcat-5-bin-20030725.zip "> http://cvs.apache.org/builds/jakarta-tomcat-5/nightly/jakarta-tomcat- 5-bin-20030725.zip
Then extract this compression package to:
C: / Tomcat
Then configure environment variables; add three system variables:
Java_Home: C: / JDKTOMCAT_HOME: C: / TomcatclassPath:% java_home% / lib;% Tomcat_Home% / LIB
Tomcat's environment variable is configured, the following verifies whether Tomcat can run:
Go to the C: / Tomcat / bin in the console, run startup, then appear back, and jump a big string, and finally indicate that Server has run.
Enter http: // localhost: 8080 in the browser, the welcome interface, indicating that Tomcat is no problem. Then write your first servlet as above, write your first servlet.
import java.io *;. import javax.servlet *;. import javax.servlet.http *;. public class HelloWorld extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Response.setContentType ("text / html"); PrintWriter out = response.getwriter (); out.println ("
}
Then use Javac HelloWorld.java to compile this file, if there is an import javax.servlet. *
Then you should copy the servlet.jar file in C: / Tomcat / Common / Lib to C: / JDK / JRE / LIB / EXT, compile again, no problem! Then in the C: / Tomcat / WebApps / root inside the Tomcat directory, follow the following file structure:
Root / index.htmlroot / welcom.jsproot / web-inf / lib / myservlet.jar (if your servlet is piloted. JAR file, put it under LIB) root / web-inf / classes / helloworld. Class (placing the helloworld.class file of the above in this)
Then enter http: // localhost: 8080 / servlet / helloWorld, which is returned by the Server Hope: Error 404 - Not Found
What's going on?
Servlet must register with the web.xml file below the directory of C: / Tomcat / WebApps / root / web -in, open this web.xml file with EP, join:
Such structure
Represents the specified servlet class. And the following structure:
Indicates which URL schema that specifies the Helloservlet to map.
After modifying Web.xml, restart Server, then enter http: // localhost: 8080 / servlet / helloworld, then a Hello, World! Waiting for you.