You need to set your classpath so that the Java compiler knows where to find the org.eclipse.* classes. You can do that with a command line switch or an environment variable.
Answer from benzado on Stack OverflowCompiling Java
Can somebody teach me how to compile Java Programs from the command line?
Is Spring Boot mandatory to learn for Java developers?
Are remote jobs available for Java developers?
What are the OOP concepts in Java?
Videos
You need to set your classpath so that the Java compiler knows where to find the org.eclipse.* classes. You can do that with a command line switch or an environment variable.
Ok, Stephen C I did this job by hand. I used only Notepad++ (I promise)
- Start Notepad++ and create file HelloWorldSWT.java
- Copy example from author
- Save it!
- Open cmd and go to the directory with HelloWorldSWT.java
Run the command
javac HelloWorldSWT.javaOk, go to the Eclipse directory and find the correct jar
swt-3.4.2-win32-win32-x86.jarRun this again
D:\workspaces\spf_workspace\hand-made>javac -cp "D:\Program files\eclipse3_5\plugins\org.eclipse.swt.win32.win32.x86_3.5.1.v3555a.jar" HelloWorldSWT.java
All process take 2 minutes.
Don't try to run this:
`D:\workspaces\spf_workspace\hand-made>java -cp "D:\Program files\eclipse3_5\plugins\org.eclipse.swt.win32.win32.x86_3.5.1.v3555a.jar;." HelloWorldSWT`
Note: I add current dir . to classpath too.
(before I start, I should say that I already know that the problem is me and not the IDE)
Im a bit confused... normally in Java, does the compiler compile the class file into an exe or an immediately runnable file without needing java installed or do you need java installed to run this file. I heard that Java is cross platform, but do you still need Java installed on the device that you are running the compiled class file from? Also, if it isn't supposed to compile into an exe, how would you create an exe such as the equivalent of Py-installer, where you don't need java installed, or it prompts you to install java. Cheers - Vip3rNB
To compile the file, open your terminal and type
javac filename.java
To run the generated class file, use
java filename
But to do this you need to have the Java JDK installed in your computer. You can install it with the instructions in How do I install Java?.
OpenJDK works best for me. It's simple and I have never faced any problem with it. Just follow these simple steps:
From Terminal install open jdk
sudo apt-get install openjdk-7-jdkWrite a java program and save the file as filename.java
Now to compile use this command from the terminal
javac filename.javaIf everything works well then a new "filename.class" file should be created.
To run your program that you've just compiled type the command below in terminal:
java filename
NOTE
You can use any text editor (like gedit) ,
replace the filename with watever name you want
you need to be on same directory as the "present working directory" (got by running pwd) while running the command from terminal.
I have no idea how to compile from the command line. My previous teacher neglected to teach us this, and I only know how to use Eclipse. Alright, so my issue was more about getting the PATH variable and file placement, not so much the actual commands