英文:
javac: no source files
问题
我尝试修复关于堆栈页面的问题,其中相同的问题,但任何方法都没有帮助我。
首先,我改变了路径:
cd C:\PROJECTS FOR FOXMINDED\TASK 12 - Service Layer\src\main\java\com\foxminded\university\cli
在`cli`包中,我有我的`CheckSum.java`。
然后我尝试了以下命令:
javac -classpath "C:\PROJECTS FOR FOXMINDED\TASK 12 - Service
Layer\src\main\java\com\foxminded\university\cli\CheckSum.java"
但是我得到了以下错误:
javac: 文件找不到: c:\home\files*.java
用法: javac <选项> <源文件>
使用 -help 以获取可能选项的列表
在我的系统变量中,我有:
Path:D:\Java\jdk1.8.0_202\bin
CLASSPATH:D:\Java\jdk1.8.0_202\lib
我用`dir`命令检查了一下,确认我的Java文件存在于这个包中。
非常感谢您的帮助!
提前致谢。
当我在必要的路径中运行`javac CheckSum.java`时,我收到以下错误:
CheckSum.java:3: 错误: 无法找到包picocli
import picocli.CommandLine;
CheckSum.java:4: 错误: 无法找到包picocli.CommandLine
import picocli.CommandLine.Command;
CheckSum.java:5: 错误: 无法找到包picocli.CommandLine
import picocli.CommandLine.Option;
CheckSum.java:6: 错误: 无法找到包picocli.CommandLine
import picocli.CommandLine.Parameters;
CheckSum.java:14: 错误: 找不到符号
@Command(name = "checksum", mixinStandardHelpOptions = true, version = "checksum 4.0",
符号: 类Command
CheckSum.java:18: 错误: 找不到符号
@Parameters(index = "0", description = "The file whose checksum to calculate.")
符号: 类Parameters
位置: 类CheckSum
CheckSum.java:21: 错误: 找不到符号
@Option(names = {"-a", "--algorithm"}, description = "MD5, SHA-1, SHA-256, ...")
符号: 类Option
位置: 类CheckSum
CheckSum.java:27: 错误: 找不到符号
int exitCode = new CommandLine(new CheckSum()).execute(args);
符号: 类CommandLine
位置: 类CheckSum
8 个错误
而类`CheckSum.java`:
@Command(name = "checksum", mixinStandardHelpOptions = true, version = "checksum 4.0", description = "Prints the checksum (MD5 by default) of a file to STDOUT.")
class CheckSum implements Callable<Integer> {
@Parameters(index = "0", description = "The file whose checksum to calculate.")
private File file;
@Option(names = {"-a", "--algorithm"}, description = "MD5, SHA-1, SHA-256, ...")
private String algorithm = "MD5";
public static void main(String[]args) {
int exitCode = new CommandLine(new CheckSum()).execute(args);
System.exit(exitCode);
}
@Override
public Integer call() throws Exception { // your business logic goes here...
byte[] fileContents = Files.readAllBytes(file.toPath());
byte[] digest = MessageDigest.getInstance(algorithm).digest(fileContents);
System.out.printf("%0" + (digest.length*2) + "x%n", new BigInteger(1, digest));
return 0;
}
英文:
I tried to fix my problem with stack pages where the same problem but anything helps me.
Firstly, I changed the path :
cd C:\PROJECTS FOR FOXMINDED\TASK 12 - Service Layer\src\main\java\com\foxminded\university\cli
In the package cli
I have my CheckSum.java
Then I tried to
javac -classpath "C:\PROJECTS FOR FOXMINDED\TASK 12 - Service
Layer\src\main\java\com\foxminded\university\cli\CheckSum.java"
but I gain this :
javac: file not found: c:\home\files*.java
Usage: javac <options> <source files>
use -help for a list of possible options
In my System variables I have :
Path : D:\Java\jdk1.8.0_202\bin
CLASSPATH : D:\Java\jdk1.8.0_202\lib
I checked if my file java exists in this package with command dir
and I saw it here.
I will be appreciate for your help!
Thanks in advance.
When I am running javac CheckSum.java in necessary path, I receive :
CheckSum.java:3: error: package picocli does not exist
import picocli.CommandLine;
CheckSum.java:4: error: package picocli.CommandLine does not exist
import picocli.CommandLine.Command;
CheckSum.java:5: error: package picocli.CommandLine does not exist
import picocli.CommandLine.Option;
CheckSum.java:6: error: package picocli.CommandLine does not exist
import picocli.CommandLine.Parameters;
CheckSum.java:14: error: cannot find symbol
@Command(name = "checksum", mixinStandardHelpOptions = true, version = "checksum 4.0",
symbol: class Command
CheckSum.java:18: error: cannot find symbol
@Parameters(index = "0", description = "The file whose checksum to calculate.")
symbol: class Parameters
location: class CheckSum
CheckSum.java:21: error: cannot find symbol
@Option(names = {"-a", "--algorithm"}, description = "MD5, SHA-1, SHA-256, ...")
symbol: class Option
location: class CheckSum
CheckSum.java:27: error: cannot find symbol
int exitCode = new CommandLine(new CheckSum()).execute(args);
symbol: class CommandLine
location: class CheckSum
8 errors
And the class CheckSum.java
:
@Command(name = "checksum", mixinStandardHelpOptions = true, version = "checksum 4.0",description = "Prints the checksum (MD5 by default) of a file to STDOUT.")
class CheckSum implements Callable<Integer> {
@Parameters(index = "0", description = "The file whose checksum to calculate.")
private File file;
@Option(names = {"-a", "--algorithm"}, description = "MD5, SHA-1, SHA-256, ...")
private String algorithm = "MD5";
public static void main(String[]args) {
int exitCode = new CommandLine(new CheckSum()).execute(args);
System.exit(exitCode);
}
@Override
public Integer call() throws Exception { // your business logic goes here...
byte[] fileContents = Files.readAllBytes(file.toPath());
byte[] digest = MessageDigest.getInstance(algorithm).digest(fileContents);
System.out.printf("%0" + (digest.length*2) + "x%n", new BigInteger(1, digest));
return 0;
}
}
答案1
得分: 1
在Windows上运行javac的格式如下:
javac -cp path1;path2;path3 *.java
其中:
path1
是指向包含库文件等内容的目录或jar文件的路径(__不是__java文件或class文件)。对于基本的Hello World程序,通常不需要使用任何库,因此根本不需要设置classpath。
path2
类似;这里强调你需要使用冒号(在Windows上是分号)来分隔路径。
*.java
是你想要编译的源文件。
你的命令设置了一个java文件作为classpath(实际上没有起到作用),然后指定了0个要实际编译的文件,因此产生了你观察到的错误。
解决方法:当你已经进入到CheckSum
文件所在的文件夹,并且想要编译它时,你只需要运行:
javac CheckSum.java
无需设置classpath。
英文:
The format for running javac on Windows is as follows:
javac -cp path1;path2;path3 *.java
where:
path1
is the path to a directory or a jar file (not a java file or a class file), with libraries and such you use. For basic hello world, you would be using no such libraries, thus you don't need the classpath at all.
path2
is similar; It's up there to show you that you have to use colons to separate them (semicolons on windows).
*.java
is the source file(s) you want to compile.
Your command sets up a java file as the classpath (this does nothing), and then specifies 0 files for actual compilation, thus producing the error you observe.
The fix: to compile your CheckSum
file when you've already cd-ed into that folder, all you need is:
javac CheckSum.java
no need for a classpath.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论