简体   繁体   English

Intellij-idea类导入

[英]Intellij-idea class import

there is a class called "Agent.class" that I wanna use inside of a java source file, and the .class file is in the same location as the .java file. 我想在java源文件中使用一个名为“Agent.class”的类,而.class文件与.java文件位于同一位置。 the location is ./my/test/ 位置是./my/test/

when I tried to import this class by typing "import my.test.", Intellij-idea doesn't show autocomplete for the Agent.class but just the .java file. 当我尝试通过键入“import my.test。”来导入此类时,Intellij-idea不显示Agent.class的自动完成,而只显示.java文件。

inside the java file, a line of code Agent ag = new Agent(); 在java文件中,一行代码代理ag = new Agent(); failed because the compiler can't resolve the object "Agent". 失败,因为编译器无法解析对象“代理”。

What am I wrong here with the Intellij settings? Intellij设置在这里我错了什么?

.class files are produced from compiled .java files, you need to have the Agent.java file in order to import Agent class to your own class. .class文件是从已编译的.java文件生成的,您需要拥有Agent.java文件才能将Agent类导入到您自己的类中。 If you have the jar containing Agent class you can try this in Intellij: 如果您有包含Agent类的jar,可以在Intellij中尝试:

  • ctrl+shift+alt+s to open Project Structure window ctrl+shift+alt+s打开“项目结构”窗口
  • go to Libraries tab 转到“ Libraries选项卡
  • press the add ( + ) button 按添加( + )按钮
  • select the path where your jar is and add it to your Module 选择jar的路径并将其添加到模块中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM