Hello World: Command Line

This example contains an HTML file and a servlet class:

index.html

/WEB-INF/classes/io/happycoding/servlets/HelloWorldServlet.java


This is a companion discussion topic for the original entry at https://happycoding.io/examples/java-server/hello-world-command-line

In the first line of the servlet file, why do we write “package io.happycoding.servlets” ?
Why not “package WEB-INF.classes.io.happycoding.servlets”?

It all comes down to the classpath. Java will be looking for classes inside the WEB-INF/classes directory, so all of our package names are relative to that.

I like to start with a couple command line examples like this one, but after you understand the fundamentals I’d probably use something like Maven to handle all of the classpath stuff for you!

1 Like