calling a java program from CentOS 7 terminal

CodeMed

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.

Robin Jonsson

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

getting a Java program to write to CentOS 7 terminal

From Dev

ClassNotFound Exception when running java from CentOS 7 terminal

From Dev

calling javac from CentOS 7

From Dev

Running java program from terminal

From Dev

CentOS 7 no terminal on boot

From Java

Calling a mapreduce job from a simple java program

From Java

Calling a Java Program from a Cocoa Application

From Dev

Calling a java program from a kernel mode driver

From Dev

Install FBExport in the CentOS 7 terminal

From Dev

Create a command line interface to a Java program, run from terminal

From Java

How to run Java program from any arbitrary directory inside Terminal

From Java

Run java script utilizing acm.program package from terminal

From Dev

How to communicate with a Unix terminal from a Java program on Windows

From Dev

Run Java Maven program from Linux terminal: ClassNotFoundException

From Dev

Hand response from one calling java program to another

From Dev

Proper/easy way of calling methods from a program on remote server in java?

From Dev

Calling Java Methods from JNI results in program crash

From Dev

Calling a Java program from a batch file with parameters containing Danish characters

From Dev

open terminal failed: missing or unsuitable terminal: unknown when running shell script from Java program

From Dev

Centos 7 - custom keyboard layout through terminal

From Dev

'Detach' from program terminal Ubuntu

From Dev

Excute program from anywhere in terminal

From Dev

terminal: program input from file

From Dev

Shortcuts for Terminal for running a Java Program

From Dev

Calling a function in program from a dictionary

From Dev

Calling minizinc from cpp program

From Dev

Calling a program from another in python

From Dev

Calling a command line program in Java

From Dev

Program accepting input from stdin but not from terminal

Related Related

  1. 1

    getting a Java program to write to CentOS 7 terminal

  2. 2

    ClassNotFound Exception when running java from CentOS 7 terminal

  3. 3

    calling javac from CentOS 7

  4. 4

    Running java program from terminal

  5. 5

    CentOS 7 no terminal on boot

  6. 6

    Calling a mapreduce job from a simple java program

  7. 7

    Calling a Java Program from a Cocoa Application

  8. 8

    Calling a java program from a kernel mode driver

  9. 9

    Install FBExport in the CentOS 7 terminal

  10. 10

    Create a command line interface to a Java program, run from terminal

  11. 11

    How to run Java program from any arbitrary directory inside Terminal

  12. 12

    Run java script utilizing acm.program package from terminal

  13. 13

    How to communicate with a Unix terminal from a Java program on Windows

  14. 14

    Run Java Maven program from Linux terminal: ClassNotFoundException

  15. 15

    Hand response from one calling java program to another

  16. 16

    Proper/easy way of calling methods from a program on remote server in java?

  17. 17

    Calling Java Methods from JNI results in program crash

  18. 18

    Calling a Java program from a batch file with parameters containing Danish characters

  19. 19

    open terminal failed: missing or unsuitable terminal: unknown when running shell script from Java program

  20. 20

    Centos 7 - custom keyboard layout through terminal

  21. 21

    'Detach' from program terminal Ubuntu

  22. 22

    Excute program from anywhere in terminal

  23. 23

    terminal: program input from file

  24. 24

    Shortcuts for Terminal for running a Java Program

  25. 25

    Calling a function in program from a dictionary

  26. 26

    Calling minizinc from cpp program

  27. 27

    Calling a program from another in python

  28. 28

    Calling a command line program in Java

  29. 29

    Program accepting input from stdin but not from terminal

HotTag

Archive