当我从命令提示符运行 java 程序时,该程序不会因为 ClassNotFound
错误而无法运行。但我看到的类存在于类路径上的 jar 文件中。当我从 Eclipse 运行时,同样的程序可以工作。不确定我在这里缺少什么。谢谢。我试图从 Windows dos 提示符运行以下命令:C:\softwares\SpringBatchExample4>java -cp "target/dependency-jars/*:target/spring-batch.jar"org.springframework.batch.core.launch.support.CommandLineJobRunner spring/batch/jobs/job-read-files.xml readJob
。我查看 target\dependency-jars 下的一个 jar 文件以确认该 jar 文件具有 CommandLineJobRunner 类。
最佳答案
从命令行运行 JAR 文件时,您有两个选项用于指定类路径:
- 使用 -classpath 或 -cp 命令行参数,后跟一个空格和所有类路径条目的完整路径列表,以分号 (Windows) 或冒号 (Linux/Unix) 分隔;
- 在适用其他规则的主 JAR list 中使用类路径条目。
关于java - 从命令提示符运行程序时未找到 Classnotfound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32807751/