如何让stdlib.jar在Intellij Idea中工作?

发布于 2025-01-19 11:41:58 字数 3149 浏览 0 评论 0原文

我已经使用了我没有库的问题。但是,我注意到安装已经拧紧了我的git bash显示设置,所以我卸载了所有内容。

后来,我从 Jetbrains网站显然所有以前的设置都被覆盖,因为我无法再使用库。因此,我降级回到书籍现场提供的版本,但是,我仍然无法使用STD库。

我已经尝试添加我发现的库.jar文件的版本:

Intellij Idea,按照路径:“ file> project设置> + gt; + gt; jar or directories> jar or Directories> file> project> libraries> + gt; + gt; java> java'',并选择相应的目录/file,没有运气,因为我有“找不到符号”错误消息:

Barnsley.java:16: error: cannot find symbol
        StdDraw.setScale(-0.1, 1.1);              // leave a 10% border
        ^
  symbol:   variable StdDraw
  location: class Barnsley

对于代码中的每一个提及的std库。我还尝试编辑环境系统变量,并创建了一个名为“ classPath”的变量,并将其链接到stdlib.jar文件,然后从第一周分配开始,然后与Hello.zip文件随附的.Lift文件夹。同样,没有运气,因为我一直收到相同的错误消息。

接下来,我键入:

javac -cp stdlib.jar barnsley.java

在命令行中,尽管该命令本身并没有导致任何错误消息,但是当我尝试运行程序时,当我尝试运行该程序时,键入:

java -cp stdlib.jar Barnsley 10000

显示此错误消息:显示此错误消息:

错误:找不到或加载主要类Barnsley 引起的

:从标准库网页到我保留程序文件的同一目录。

我知道有些(也许很多人)以前或在其他论坛上都问过同样的问题或类似的问题,但是我已经在谷歌搜索和寻找解决方案已经三天了,如您所见,没有什么我发现的报告的解决方案对我有帮助,这就是为什么我决定自己再次询问的原因。

感谢您阅读我的帖子和/或提供您可以提供的任何帮助。

ps。:错误消息中的barnsley.java文件对应于 booksite的网页。

[编辑 - 2022年4月7日]: 我尝试遵循@crazycoder的建议,因此我创建了一个名为“ SRC”的文件夹,从hello..zip文件随附的stdlib.jar文件中提取了所有文件,然后将barnsley.java移至该文件夹。接下来,接下来,我尝试按照他提到的网页,如以下屏幕截图所示:

和以某种方式,在编译时会收到相同的错误消息:

我不知道出了什么问题:c任何帮助都将不胜感激。

[编辑 - 2022年4月7日晚些时候]:

发生了一些奇怪的事情。我下载了@CrazyCorder提供的文件,并警告了没有安装Amazon Corretto的警告,我决定忽略。

我尝试从命令行运行程序,没有运气,因为我收到的错误消息与往常一样。因此,我注意到项目结构中没有分配给SDK插槽的JDK,我选择使用JDK 18(遵循“ file> project; project> project”),这是我以前拥有的一个安装在我的计算机上,但这并没有真正改变。

最后,我试图从IDE运行它,那是它最终起作用的时候!!!因此,谢谢您,@crazycoder:di仍然不知道为什么它从命令行不起作用,但是...

I​ had used the IntelliJ IDEA installer provided in the booksite for Computer Science: An Interdisciplinary Approach and I had no problem to use the library. However, I noticed that installation had screwed my Git bash display settings, so I uninstalled everything.

Later, I installed the latest version of IntelliJ (2021.3.3), from the JetBrains website and apparently all the previous settings were overwritten, since I could no longer use the library. So, I downgraded back to the version provided in the booksite, however, I still can't use the Std library.

I've tried adding the versions of the library .jar files that I found:

Together and independently to the module and libraries, via IntelliJ IDEA, following the paths: "File > Project settings > Modules > + > JARs or directories" and "File > Project settings > Libraries > + > Java" , respectively, and choosing the corresponding directory/file, with no luck, since I've got the "cannot find symbol" error message:

Barnsley.java:16: error: cannot find symbol
        StdDraw.setScale(-0.1, 1.1);              // leave a 10% border
        ^
  symbol:   variable StdDraw
  location: class Barnsley

For literally every single mention of the Std libraries in the code. I​ also tried editing the environment system variables and created a variable named "CLASSPATH" and linked it to the Stdlib.jar file and then, to the .lift folder that came with the hello.zip file, from the first week assignment. Again, no luck, because I kept getting the same error message.

Next up, I typed:

javac -cp stdlib.jar Barnsley.java

In the command line, and although that command itself didn't lead to any error message, when I tried to run the program, typing:

java -cp stdlib.jar Barnsley 10000

This error message showed up:

Error: Could not find or load main class Barnsley
Caused by: java.lang.ClassNotFoundException: Barnsley

I also vainly tried copying and pasting every .java file from Standard libraries webpage to the same directory where I keep the program files.

I know some (maybe lots of people) have asked the same or a similar question before, either here or in other forums, but I've been googling and looking for a solution for three days now and, as you can see, none of the reported solutions that I've found have been of help to me, that's why I decided to ask again, on my own.

Thank you for reading my post and/or for any help you can provide.

PS.: The Barnsley.java file in the error messages corresponds to the one provided in the 5th section of this webpage from the booksite.

[Edit - April 7th, 2022]:
I tried to follow @CrazyCoder advice, so I created a folder named "src", extracted all the files from the stdlib.jar file that came with the hello.zip file into src and also moved Barnsley.java to that folder. Next, Next, I tried to follow the instructions from the webpage he mentioned, as shown in the following screenshot:
New roject settings

And somehow, got the same error message when compiling:
Error message screenshot

I don't know what went wrong :C Any assistance would be highly appreciated.

[Edit - Later on April 7th, 2022]:

Something weird happened. I downloaded the file provided by @CrazyCorder and there was a warning about Amazon Corretto not being installed, that I decided to ignore.

I tried to run the program from the command line, with no luck, because I got the same error message as always. So, I noticed that there was no JDK assigned to the SDK slot in the Project structure, and I chose to use JDK 18 (following the path "File > Project structure > Project"), which is the one that I had previously installed on my computer, but that didn't really change a thing.

Lastly, I tried to run it from the IDE and that's when it finally worked!!! So, thank you, @CrazyCoder :D I still don't know why it doesn't work from the command line, though...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与往事干杯 2025-01-26 11:41:58

我还徒劳地尝试将标准库网页中的每个 .java 文件复制并粘贴到我保存程序文件的同一目录中。

这工作得很好,您需要将 stdlib.jar 中的所有 .java 文件放入 源根目录(在项目视图中以蓝色标记)。 Barnsley.java 需要位于同一目录中。

工作正常

带有 .class 文件的 jar 将无法像您一样在依赖项/类路径中工作 无法从 Java 中的默认包导入类

将类保留在默认包中是一个非常糟糕的选择,这是该库/课程的创建者的错误。多年来,这个简单的疏忽已经引起了严重的头痛。

I also vainly tried copying and pasting every .java file from Standard libraries webpage to the same directory where I keep the program files.

This works just fine, you need to place all the .java files from the stdlib.jar into the sources root directory (marked in blue in the project view). Barnsley.java needs to be in the same directory.

works fine

The jar with .class files will not work in the dependencies/classpath as you cannot import classes from the default package in Java.

It was an extremely poor choice to keep the classes in the default package and it's the fault of the creators of this library/course. This simple oversight has caused major headaches over the years.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文