为什么我在构建.jar时总是收到无效的标志错误
时总是收到无效的标志错误
为什么我在使用build Jar在Java中制作.jar文件时构建
rm -rf build-jar && mkdir build-jar && javac -d build-jar /Users/user/Desktop/projects/Swings/source/library/* && jar cvf build-jar/window.jar build-jar *
:我总是会收到一个错误:
error: invalid flag: /Users/user/Desktop/projects/Swings/source/library/controller
Usage: javac <options> <source files>
如果我使用.class文件的路径:
rm -rf build-jar && mkdir build-jar && javac -d build-jar /Users/user/Library/Application Support/Code/User/workspaceStorage/ca7d24d42ba31de4cfb244fc0f239d07/redhat.java/jdt_ws/swings_12c4bbf0/bin/* && jar cvf build-jar/window.jar build-jar *
我也会收到一个错误:
zsh: no matches found: Support/Code/User/workspaceStorage/ca7d24d42ba31de4cfb244fc0f239d07/redhat.java/jdt_ws/swings_12c4bbf0/bin/*
我“我对建造罐子的熟悉不太熟悉,这会让我头疼,我不知道该怎么办,另一个问题的解决方案或解决方案对我不起作用(例如 classPath无效标志-Java 等)
我使用IDE VSCODE,并使用VSCODE扩展名为“ Jar Builder”
Why I always received invalid flag error while I'm building .jar
When I using Build Jar to make a .jar file in java:
rm -rf build-jar && mkdir build-jar && javac -d build-jar /Users/user/Desktop/projects/Swings/source/library/* && jar cvf build-jar/window.jar build-jar *
I always receive a error:
error: invalid flag: /Users/user/Desktop/projects/Swings/source/library/controller
Usage: javac <options> <source files>
If I use path to .class file:
rm -rf build-jar && mkdir build-jar && javac -d build-jar /Users/user/Library/Application Support/Code/User/workspaceStorage/ca7d24d42ba31de4cfb244fc0f239d07/redhat.java/jdt_ws/swings_12c4bbf0/bin/* && jar cvf build-jar/window.jar build-jar *
I also receive an error:
zsh: no matches found: Support/Code/User/workspaceStorage/ca7d24d42ba31de4cfb244fc0f239d07/redhat.java/jdt_ws/swings_12c4bbf0/bin/*
I'm not very familiar with building jar, It make me headache, And I don't know what to do, the other question's solution or solution on internet are all not work for me(like Classpath invalid flag - Java, etc.)
I'm using IDE vscode, and using vscode extension "JAR Builder"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“星”扩展是您的外壳做的。当您在外壳中键入
ls *.txt
时,那是不是什么是运行。您的外壳本身可以检测到 *,并且会出去弄清楚您的真正含义。实际最终被执行的是ls a.txt b.txt c.txt
- 星星匹配的所有内容,由空格隔开。这里也发生了同样的事情。因此,为什么您会遇到此错误:您的外壳正在执行:
这是线索: javac无法像这样。您无法指定目录,并期望它知道该怎么做。您需要单独列出每个Java文件,这意味着您需要一条长的命令行。
Java生态系统中没有人使用命令行构建应用程序是有原因的。每个人都使用Maven或Gradle。你应该。它将解决这个问题;您只需将源贴在正确的位置,然后将其从那里弄清楚。拥有尽可能多的包裹。
'star' expansion is a thing your shell does. When you type
ls *.txt
in your shell, that's not what is run. Your shell itself detects that * and will go out and figure out what you really mean. What actually ends up being executed isls a.txt b.txt c.txt
- everything that star matches, separated out by spaces.The same is happening here. Hence, why you get this error: Your shell is executing:
and here's the clue: javac does not work like this. You cannot specify directories and expect it to know what to do. You need to list each java file individually, which means you need one heck of a long command line.
There is a reason nobody in the java ecosystem builds apps with the command line. Everybody uses maven or gradle instead. So should you. It'll solve this problem; you just stick your sources in the right location and maven / gradle figure it out from there. Have as many packages as you want.