2

I would like to know how to use the command line to run the Java single-file-source code.

I know that I cannot refer to outside classes per rules.

But I saw an YouTube video. The author is able to use external JAR library when he runs single-file-source code.

See this YouTube video @ 6:00 minute https://www.youtube.com/watch?v=U7Rp9hq0_Zk

He types:

java -cp mysql-connector-java-8.0.19.jar Database.java

I don't know how the database really works. I'm not there yet.

But if you guys can show me a quick example, that would be great.

Thanks!

4
  • java -cp mysql-connector-java-8.0.19.jar Database.java is already an example. The point is that you can set the class path to a place where all your dependencies are (in their case, mysql-connector-java-8.0.19.jar). Basically, I'm really not sure what you don't understand. That video is a great example of how to use external libraries when running single source files. Commented Jul 25, 2021 at 7:39
  • That's an incorrect example. Java is run against classes not source files. Also why would the entry point be in the same (only) classpath as the driver? It would not. Please describe what you want to do. Commented Jul 25, 2021 at 8:55
  • 2
    @g00se modern versions of java can do this Commented Jul 25, 2021 at 9:28
  • Ah right - i'll give it a go. I have a jdk 16. Nonetheless my second point holds Tried it - wild! Not a class file in sight Commented Jul 25, 2021 at 9:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.