vs9*_*s97 4 java import spring jar maven
我在将 JAR 库中的类导入我的项目时遇到问题。请看截图。
我在 Eclipse 和 IntelliJ 中都尝试了几种方法,直接添加和通过 Maven 添加。这些都没有帮助,我仍然得到一个红色下划线。
在 IntelliJ 中,我尝试过:
在 Eclipse 我试过:
这是我的 pom.xml 来获取本地 jar。
<dependency>
<groupId>uk.co.pervasive_intelligence.simulator</groupId>
<artifactId>protocol</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>C:\Users\Vas-DELL\Desktop\simulator-1.2.2.jar</systemPath>
</dependency>
Run Code Online (Sandbox Code Playgroud)
奇怪的是,我能够看到罐子和罐子里的类(截图)。但仍然无法导入它们。如果还有什么我可以提供的,请告诉我。
在项目文件夹的根目录中创建一个 lib/ 目录。把你的罐子放在那里。将此添加到您的 pom.xml:
<dependency>
<groupId>uk.co.pervasive_intelligence.simulator</groupId>
<artifactId>protocol</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/simulator-1.2.2.jar</systemPath>
</dependency>
Run Code Online (Sandbox Code Playgroud)
不要使用 \ 作为路径分隔符(即使您使用的是 Windows)
运行mvn clean package命令行
您也可以尝试在本地存储库中手动安装依赖项:
mvn install:install-file -Dfile=simulator-1.2.2.jar -DgroupId=uk.co.pervasive_intelligence.simulator -DartifactId=protocol -Dversion=1.0 -Dpackaging=jar
然后将其添加到您的 pom 中:
<dependency>
<groupId>uk.co.pervasive_intelligence.simulator</groupId>
<artifactId>protocol</artifactId>
<version>1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
编辑:
jar 文件不具有标准 java 库的结构。为了将该 jar 用作库,类的包应作为 jar 文件的基(或根目录)中的文件夹存在。例如:
/META-INF
/MANIFEST.MF
/uk
/co
/pervasive_intelligence
/simulator
/BaseComponent.class
/SimulatorApplication.class
/SimulatorException.class
....
Run Code Online (Sandbox Code Playgroud)
作为一个库 jar 文件,那么 MANIFEST.MF 的内容可以很简单
Manifest-Version: 1.0
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
| 归档时间: |
|
| 查看次数: |
8333 次 |
| 最近记录: |