jar class 无法解析为类型

jar class cannot be resolved to a type

我在 Spring MVC 中工作,得到了一个可执行的 jar 文件,其中包含很少的 classes 并添加到我的项目中。

我使用构建路径添加了那个 jar 作为外部 jar。

然后我在那个 jar 文件中使用 class 来调用一个 returns 字符串的方法。

我在 maven 安装中遇到错误

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project myproject: Compilation failure: Compilation failure:
    [ERROR] com/mmf/controllers/myprojectController.java:[12,0] The import com.canonical.client.myClass cannot be resolved
    [ERROR] com/mmf/controllers/myprojectController.java:[31,0] myClass cannot be resolved to a type
    [ERROR] com/mmf/controllers/myprojectController.java:[31,0] myClass cannot be resolved to a type

谁能帮我解决这个问题?

要将外部 JAR 文件添加到您的 Maven 项目,您需要在执行 mvn install 之前 运行 以下命令。

mvn install:install-file -Dfile=<actual path for the intended jar file> -DgroupId=<group_id>  -DartifactId=<artifactId> -Dversion=<version of jar file> -Dpackaging=<packaging>

例如,

mvn install:install-file -Dfile=E:\something.jar  -DgroupId=someGroupId -DartifactId=someArtifactId -Dversion=someVersion -Dpackaging=jar

此步骤只需执行一次。执行此操作后,所需的 JAR 文件将添加到本地 maven 存储库,并且从下一次开始,它将在您执行 mvn install.

时使用

您的 jar 在构建时似乎不可用。

您可以在构建路径中包含外部 jar 作为系统的 Maven 依赖项

例如:

<dependency>
    <groupId>org.spring</groupId>
    <artifactId>platform</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/platform-1.0.0.jar</systemPath>
</dependency>

这里是 documentation.