Reputation: 9205
I am using the code from this tutorial to test the JDBC connection. I changed the name of the class to TestJDBC and I altered the database name and query, but otherwise it is identical. When I run the class as a Java application from within eclipse on my devbox, the program runs properly. However, when I copy the file to /home/username/
on a remote CentOS 7
server, typing java TestJDBC.java
into the terminal produces the following error:
Error: Could not find or load main class TestJDBC.java
I also the same error when I try java TestJDBC
and when I upload the .class
file in addition to just the .java
file. What else do I need to do in order to call the Java class from the CentOS 7
terminal?
Note that javac TestJDBC.java
results in -bash: javac: command not found
. And I did try java somepackage.TestJDBC
with same results of Error: Could not find or load main class TestJDBC.java
as above.
ANSWER NOTE: The answer required getting the development version of openJDK using yum. The PATH variable was not part of the solution. However, I am marking the answer below as accepted because the user who submitted it contributed substantially to the solution.
Upvotes: 0
Views: 8047
Reputation: 2851
You should be able to run it after compiling it
javac TestJDBC.java
java TestJDBC
Note that you do not need to add .class
when running it from the commandline.
If this still does not work, please paste your code.
EDIT after request
So you've now stated that you're missing javac
from your PATH. I'll show you how to add it:
$> export JAVA_HOME=/path/to/jdk/jdk.1.8.0_20
$> export PATH=$PATH:$JAVA_HOME/bin
Verify by running
javac -version
It should print something like
javac 1.8.0_20
Upvotes: 1