0

I am tring to compile (javac) the Tomcat examples specifically the echo endpoint.java examples /WEB-INF/classes folder has an echoendpoint.class file. I must assume it came precompiled in the zip file for tomcat9 since I cant seem to get it to compile. It can't find the package javax.websocket.

error: package javax.websocket does not exist

I can find all kinds of Oracle documentation on the javax websocket package but cant figure out where to download the jar file(s. I am using jdk 1.8.0_161

I am an old school programmer and really don't like all these tools that try to do things for me (eclipse, maven). I like to know exactly what is going on and be in control. So I am doing everything from the command line and editing with sublime3 my environment variables show:

LLUSERSPROFILE=C:\ProgramData APPDATA=C:\Users\Owner\AppData\Roaming CATALINA_BASE=D:\tomcat9\apache-tomcat-9.0.7
CATALINA_HOME=D:\tomcat9\apache-tomcat-9.0.7
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=DESKTOP-NMIG0RS ComSpec=C:\WINDOWS\system32\cmd.exe
FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
FPS_BROWSER_USER_PROFILE_STRING=Default HOMEDRIVE=C:
HOMEPATH=\Users\Owner JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161
LOCALAPPDATA=C:\Users\Owner\AppData\Local
LOGONSERVER=\\DESKTOP-NMIG0RS NUMBER_OF_PROCESSORS=12
OneDrive=C:\Users\Owner\OneDrive OS=Windows_NT
Path=C:\ProgramData\Oracle\Java\javapath;C:\Program Files
(x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS
Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program
Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program
Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files
(x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program
Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program
Files\PuTTY\;C:\Program Files (x86)\Skype\Phone\;C:\Program
Files\Java\jdk1.8.0_161\bin;C:\Program
Files\nodejs\;C:\Users\Owner\AppData\Local\Microsoft\WindowsApps;C:\Users\Owner\Downloads\java_ee_sdk-7u3-web\glassfish4\bin;C:\Program
Files\Microsoft VS
Code\bin;C:\Users\Owner\AppData\Roaming\npm;C:\Program Files\nodejs;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC 

I tried adding D:\tomcat9\apache-tomcat-9.0.7\lib to the class path on the javac command thinking it might pick up tomcat-websocket.jar or websocket-api.jar but that didnt help either. so I have a multipart question:

  1. where can I get the required Jar files?
  2. why doesn't Oracle include ALL their jars in their jdk download? I seems to me that they should include at least all the Javax jars.
  3. why doesn't apache include a .bat file for building all their examples?
craigcaulfield
  • 3,381
  • 10
  • 32
  • 40
  • 1. javax packages are part of the jre afaik, 2. Idk, they decided not to? 3. look at 2. Consider looking at https://stackoverflow.com/help/how-to-ask – David Apr 14 '18 at 23:15

1 Answers1

0

Adding a directory to the CLASSPATH only adds the .class files that may be found there and in subdirectories (with a particular package structure). If you want to add websocket-api.jar to the CLASSPATH then you'll have to do it like this:

C:> javac -cp D:\tomcat9\apache-tomcat-9.0.7\lib\websocket.jar myClass.java

Tools like Eclipse and Maven already understand these dependencies and can take away all of the typing that you'll ed up doing if you need to include 20, 30, or 100 different libraries on which your project depends.

To answer your questions directly:

  1. Where can I get the required JAR files?

The one you are looking for in this particular case actually comes bundled with Tomcat, but you can also get them from Oracle, too. The problem is that the Websocket API is a part of the Java EE APIs and if you didn't know that, you might not know that's what you need to download.

  1. Why doesn't Oracle include ALL their jars in their JDK download?

Because there are huge numbers of APIs and not everybody needs all of them. When you install Microsoft's Visual Studio, do you want it to install the Visual COBAL++ pre-processor, the Fortran# compiler, and the Microsoft Bob Simulator as well? Probably not.

  1. Why doesn't apache include a .bat file for building all their examples?

Because it's insanely inconvenient when real, useful build tools exist. The Tomcat project uses Apache Ant to build everything, including the examples web application. You are much better off using Ant than you are building from a .bat file. Yes, it's complicated. It's complicated because building Tomcat is complicated. Building the examples web application less so, but being able to issue a <javac> task that understands where the dependent JAR files are is much better than having to re-roll the whole javac command every time something changes.

If you want to compile the examples web application conveniently, you should download Apache Ant and run this command:

C:> ant compile-webapp-examples

If you make changes to the web application, you'll get your changes compiled, too.

It's worth pointing-out that this isn't something that is inherently a part of some Java-based conspiracy to confuse "old school programmers". Before working (almost entirely) in Java, I've had a long history in C and other languages. Anything past a single-source-file C project practically requires a makefile, and many of the projects I was involved with also had lots of other steps in a build-from-source activity. Things like running a compiler-compiler (lex/yacc, etc.) before the C compiler is invoked, etc. Also, most C compilers only compile a single file at a time. So if you have 100 source files, you need 100 lines in a naive build-script. Then, you need the link step which might actually be many steps. If you need 2, 30, or 100 different dependent libraries, you will need to go and acquire them from their respective sources and then mention them all in the linking step (the C compiler doesn't include libssl or libwhatever or, sometimes, even libc). So it's not straightforward, either.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
  • the comment size limit just saved everyone from dealing with my soapbox rant on "modern" programming tools I guess I will get that posted somewhere else and just provide a link in some future comment. – Latitia Lee Apr 17 '18 at 17:02
  • @LatitiaLee Usually a simple "get off my lawn" gets the point across. – Christopher Schultz Apr 17 '18 at 18:42