【问题标题】:Install a jar through maven in Netbeans fail to see the location of pom.mxlNetbeans中通过maven安装jar看不到pom.xml的位置
【发布时间】:2016-09-20 06:28:59
【问题描述】:

我在 Netbeans 中有一个 Maven 项目。

我在本地有一个要插入到项目中的 jar。

通过 cmd 我运行命令

C:\Users\Alia-PC>mvn install:install-file-Dfile=C:\opt\glassfish4\glassfish\dom ains\domain1\applications\myproject\files\rrunner_ja r\Ropt-Updated.jar \ -DgroupId=rcaller -DartifactId=RCaller \-Dversion=2.4 -Dpackaging=jar -e

但我收到 pom.xml 的此错误。

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.094 s
[INFO] Finished at: 2016-05-23T14:27:42+03:00
[INFO] Final Memory: 5M/77M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM
 in this directory (C:\Users\Alia-PC). Please verify you invoked Maven from the
correct directory. -> [Help 1]
org.apache.maven.lifecycle.MissingProjectException: The goal you specified requi
res a project to execute but there is no POM in this directory (C:\Users\Alia-PC
). Please verify you invoked Maven from the correct directory.
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
eStarter.java:84)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        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:497)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
356)
[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/MissingProject
Exception

即使我试着做一个

cd C:\opt\glassfish4\glassfish\domains\domain1\applications\myproject\

谁能告诉我问题的原因以及如何解决?

【问题讨论】:

标签: java maven netbeans jar


【解决方案1】:

这是一个两步过程:

在本地安装 3rd 方 jar:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

使 jar 可用于您的项目:

在您的pom 中指定 jar 依赖项,使用您在本地安装它并从项目目录构建项目时定义的相同细节。

<dependency>
            <groupId>Specified GroupID</groupId>
            <artifactId>Specified ArtifactID</artifactId>
            <version>Specified Version</version>
  </dependency>

这个错误告诉我的是你试图从一个没有定义pom 的项目目录以外的目录构建。

理想的 Maven 文件夹结构:

Project
      |
      ---src
           |
           ---main
                 |
                 ---java
                 ---so on
           ---test
                 |
                 ---so on
      ---Pom.xml

【讨论】:

  • 感谢您的回答。我将项目放在一个文件中,该文件包含一个子文件,其中包含项目的 src 和父文件夹中的另一个子文件夹,其中包含 jar 文件。 pom.xml中存在依赖项
  • 我已经用理想的项目结构更新了我的答案。如您所见,pom 应该位于根目录中。无论如何,您需要从 pom 所在的目录调用 build。
猜你喜欢
  • 2011-12-28
  • 1970-01-01
  • 2012-12-11
  • 1970-01-01
  • 2010-12-04
  • 1970-01-01
  • 2013-01-17
  • 1970-01-01
相关资源
最近更新 更多