允许Maven在Ubuntu中自动创建目录

And*_*tin 3 ubuntu maven

我在 Ubuntu 12.04 中运行 Maven 3.0.4。我有 Java 版本 1.7.0_25。我正在尝试使用该mvn package命令,但我不断遇到错误,这些错误总是沿着以下路线:

Failure executing javac, but could not parse the error:
javac: directory not found: /......../target/[some folder]
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚这最初是什么,但现在从一些基本的谷歌搜索中了解到这是因为目标目录必须存在。处理这个问题的一般建议方法是创建一个 ant 脚本来为你做这件事(我认为)。

但是,我不知道实际需要创建哪些文件夹。这不是我正在编译的项目,只是我下载的项目。是否仍然可以使用 Ant 脚本,如果可以,任何人都可以指出我正确的方向,因为我以前从未使用过 ant 脚本,更不用说创建了一个,并且可以准确地称为 Ubuntu“菜鸟”!

根据要求提供完整的 Maven 输出

目录为:

flume-sources - containing
    flume.conf
    pom.xml
    src
      main
        java
          com
            cloudera
              flume
                source
                  TwitterSource.java
                  TwitterSourceConstants.java
Run Code Online (Sandbox Code Playgroud)

Maven 错误是:

andrew@andrew-VirtualBox:~/flume-sources$ mvn package
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building flume-sources 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ flume-sources ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/andrew/flume-sources/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ flume-sources ---
[INFO] Compiling 2 source files to /home/andrew/flume-sources/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Failure executing javac, but could not parse the error:
javac: directory not found: /home/andrew/flume-sources/target/classes
Usage: javac <options> <source files>
use -help for a list of possible options

[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.470s
[INFO] Finished at: Mon Jul 08 12:35:58 BST 2013
[INFO] Final Memory: 9M/59M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project flume-sources: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] javac: directory not found: /home/andrew/flume-sources/target/classes
[ERROR] Usage: javac <options> <source files>
[ERROR] use -help for a list of possible options
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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 read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
andrew@andrew-VirtualBox:~/flume-sources$ 
Run Code Online (Sandbox Code Playgroud)

Hil*_*kus 5

不,您不需要手动或使用 ant 脚本创建文件夹。

如果target运行 mvn 时该文件夹不存在,它将创建它

所以我的猜测是你有权限问题

运行 maven 的用户无法在 /home/andrew/flume-sources 中创建文件夹

作为测试,以 root 身份运行 mvn

 sudo mvn package
Run Code Online (Sandbox Code Playgroud)

如果可行,那么这就是我所说的,您将需要 1)chown文件夹,以便运行 maven 的用户可以在其中创建文件夹 (rw) 或 2) 从拥有该文件夹的同一用户运行 mvn(我是猜测是andrew