将独立jar导入本地maven存储库

时间:2016-05-12 11:19:04

标签: java eclipse maven jar compiler-errors

我正在使用以下命令将第三方jar导入到我的本地Maven存储库中,以便构建我的项目:

mvn install:install-file -Dfile=C:\Users\MNXE\plugins\myArtifactTest-generate\myArtifactTest-generate-plugin\lib\autoitx4java.jar -DgroupId=com.autoit.code -DartifactId=autoitx4java -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true

我的pom文件中对此jar的依赖关系如下:

    <dependency>
        <groupId>com.autoit.code</groupId>
        <artifactId>autoitx4java</artifactId>
        <version>1.0.0</version>
    </dependency>

以下是尝试安装Maven项目时我的错误的完整堆栈跟踪。无论我尝试安装jar,还是在Eclipse的构建路径中包含jar,似乎都没有用。我继续收到编译错误:

C:\Users\MNXE\plugins\myArtifactTest-generate>mvn install -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] OO sample content project
[INFO] myArtifactTest-generate-plugin
[INFO] myArtifactTest-generate-cp
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building OO sample content project 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ myArtifactTest
-generate ---
[INFO] Installing C:\Users\MNXE\plugins\myArtifactTest-generate\pom.xml to C:\Us
ers\MNXE\.m2\repository\myGroupTest-generate\myArtifactTest-generate\1.0.0\myArt
ifactTest-generate-1.0.0.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myArtifactTest-generate-plugin 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- oo-action-plugin-maven-plugin:10.20.8:generate-action-plugin (generat
e-contentpack-plugin) @ myArtifactTest-generate-plugin ---
[INFO]
[INFO] --- maven-plugin-plugin:2.9:descriptor (default-descriptor) @ myArtifactT
est-generate-plugin ---
[WARNING] Using platform encoding (Cp1250 actually) to read mojo metadata, i.e.
build is platform dependent!
[INFO] Applying mojo extractor for language: java
[INFO] Mojo extractor for language: java found 4 mojo descriptors.
[INFO] Applying mojo extractor for language: bsh
[INFO] Mojo extractor for language: bsh found 0 mojo descriptors.
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ myArtifact
Test-generate-plugin ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\MNXE\plugins\myArtifactTest-
generate\myArtifactTest-generate-plugin\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ myArtifactTest-
generate-plugin ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1250, i.e. b
uild is platform dependent!
[INFO] Compiling 5 source files to C:\Users\MNXE\plugins\myArtifactTest-generate
\myArtifactTest-generate-plugin\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/MNXE/plugins/myArtifactTest-generate/myArtifactTest-generate-p
lugin/src/main/java/SampleActions.java:[9,20] package autoitx4java does not exis
t
[ERROR] /C:/Users/MNXE/plugins/myArtifactTest-generate/myArtifactTest-generate-p
lugin/src/main/java/SampleActions.java:[123,38] cannot find symbol
  symbol:   class AutoItX
  location: class SampleActions
[ERROR] /C:/Users/MNXE/plugins/myArtifactTest-generate/myArtifactTest-generate-p
lugin/src/main/java/SampleActions.java:[128,41] cannot find symbol
  symbol:   class AutoItX
  location: class SampleActions
[ERROR] /C:/Users/MNXE/plugins/myArtifactTest-generate/myArtifactTest-generate-p
lugin/src/main/java/SampleActions.java:[133,39] cannot find symbol
  symbol:   class AutoItX
  location: class SampleActions
[INFO] 4 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] OO sample content project ......................... SUCCESS [0.817s]
[INFO] myArtifactTest-generate-plugin .................... FAILURE [6.999s]
[INFO] myArtifactTest-generate-cp ........................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.994s
[INFO] Finished at: Thu May 12 11:33:43 CEST 2016
[INFO] Final Memory: 17M/213M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.
1:compile (default-compile) on project myArtifactTest-generate-plugin: Compilati
on failure: Compilation failure:
[ERROR] /C:/Users/MNXE/plugins/myArtifactTest-generate/myArtifactTest-generate-p
lugin/src/main/java/SampleActions.java:[9,20] package autoitx4java does not exis
t
[ERROR] /C:/Users/MNXE/plugins/myArtifactTest-generate/myArtifactTest-generate-p
lugin/src/main/java/SampleActions.java:[123,38] cannot find symbol
[ERROR] symbol:   class AutoItX
[ERROR] location: class SampleActions
[ERROR] /C:/Users/MNXE/plugins/myArtifactTest-generate/myArtifactTest-generate-p
lugin/src/main/java/SampleActions.java:[128,41] cannot find symbol
[ERROR] symbol:   class AutoItX
[ERROR] location: class SampleActions
[ERROR] /C:/Users/MNXE/plugins/myArtifactTest-generate/myArtifactTest-generate-p
lugin/src/main/java/SampleActions.java:[133,39] cannot find symbol
[ERROR] symbol:   class AutoItX
[ERROR] location: class SampleActions
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on p
roject myArtifactTest-generate-plugin: Compilation failure
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:213)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBu
ild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
eStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
352)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compila
tion failure
        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(Abstrac
tCompilerMojo.java:858)
        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.ja
va:129)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
BuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:209)
        ... 19 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureExc
eption
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command

[ERROR]   mvn <goals> -rf :myArtifactTest-generate-plugin
C:\Users\MNXE\plugins\myArtifactTest-generate>

2 个答案:

答案 0 :(得分:1)

我认为您的jar文件名中缺少版本号。您的jar文件名应为autoitx4java- 1.0.0 .jar

答案 1 :(得分:1)

这并不是您想要做的,但会让您获得相同的结果。 您可以使用更通用的方法 - 安装本地Sonatype Nexus存储库服务器并将工件上传到其中,而不是遇到本地maven分发库repo(基本上只是缓存)的麻烦。这比你正在尝试的要容易得多。此外,您将获得其他一些好处:

  • 您可以在整个团队中使用相同的Nexus存储库
  • 您可以创建maven任务来上传自定义的新版本 工件
  • 您不需要在每台计算机上配置maven分发。 相反,您只需在pom.xml中配置您的nexus存储库地址,就像任何其他maven存储库一样。

从Maven意识形态的角度来看,您需要的是您自己的Nexus存储库。 否则,如果您想创建自定义构建过程并使用任何自定义库,那么您选择的是Gradle,而不是Maven。 Gradle为您提供所有maven好处+更多自由。例如,在Gradle中,很容易将本地库与Maven Central中的任何库一起用于项目构建。