1024programmer Java Run java program under dos command (link mysql as an example)

Run java program under dos command (link mysql as an example)

1 Description I use Alibaba Cloud’s Windows version of the server and want to run a Java program that connects to the database on it, but I don’t know how to run it. I copied the files in eclipse directly to the server. All the .class files have been compiled, but I don’t know how to run them on the server. Problem 1: The class to be run cannot be found. Question

1 Description

I use Alibaba Cloud’s Windows version of the server and want to run a Java program that connects to the database on it, but I don’t know how to run it. I copied the files in eclipse directly to the server. All the .class files have been compiled, but I don’t know how to run them on the server.
Problem 1: The class to be run cannot be found
Write picture description here
Problem 2: The driver cannot be found, that is, the imported jar package cannot be run
Write picture description here

Solution to problem 1:
– Because my DBHelper file contains package
package mydatahelper;
Therefore, the runtime class name is written as mydatahelper.DBHelper. Generally, the running directory must be moved back to before the package name before running.
Solution to problem 2:
– Obviously, we need to import a new package, that is, a jar package. Here I put the jar package containing the mysql driver in the lib folder, which is placed in the same level directory as the mydatahelper folder.

Run as follows:

java -Djava.ext.dirs=./lib mydatahelper.DBHelper 

Final running result

The file directory is as follows:
Write picture description here
Write picture description here
Write picture description here

Reference:
The command line executes a Java program to load the Jar file in the specified directory

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/719569

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索