【发布时间】:2019-01-09 23:53:58
【问题描述】:
我的项目中有一个自定义结构
Development -
- src
- test
并且通过 Eclipse 运行测试工作正常,但是当我使用我的 mac 上的终端运行测试(mvn 测试)时,找不到 src 类(在 maven 编译插件期间失败)。我认为这一定是我的 pom 没有将插件引导到正确的文件夹的问题。如果我注释掉这一行,
<outputDirectory>Development/build</outputDirectory>
它工作正常,因为 .class 文件现在被放置在目标文件夹中。我不需要查看 .class 文件的目标文件夹,而是需要 maven 来查看
Development/build
目录,如果我没记错的话。对吧?
我想继续使用我的自定义文件结构并更正我的 pom,以便它通过我的 mac 终端编译和运行单元测试。
<build>
<sourceDirectory>Development/src/main</sourceDirectory>
<testSourceDirectory>Development/src/test</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<outputDirectory>Development/build</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<classesDirectory>Development/build</classesDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>Development/build</directory>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptors>
<descriptor>Development/src/assembly/assembly.xml</descriptor>
</descriptors>
<tarLongFileMode>posix</tarLongFileMode>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
</plugins>
</build>
这是控制台输出
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ weatherdetails ---
[INFO] Deleting /Users/username/git/weatherdetails/target
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (auto-clean) @ weatherdetails ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ weatherdetails ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/username/git/weatherdetails/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ weatherdetails ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2503 source files to /Users/username/git/weatherdetails/Development/build
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ weatherdetails ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/username/git/weatherdetails/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ weatherdetails ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /Users/username/git/weatherdetails/Development/build
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/username/git/weatherdetails/Development/src/test/com/wfc/schedulers/WeeklySchedulerTest.java:[12,26] cannot find symbol
symbol: class WeeklyScheduler
location: package com.wfc.schedulers
关于未正确配置的任何建议?
【问题讨论】:
-
遵循配置范式的约定,不要更改
sourceDirectory>Development/src/main</sourceDirectory>之类的东西,因为它没有任何优势...... -
我今天实际上和我的领导谈过这个问题。我说使用maven的重点是它的文件夹结构是标准的。我们将不得不告诉我们使用的每一项技术,以在 Development/builder 文件夹中查找所有内容,如果您问我,这在某种程度上违背了目的。
-
这东西叫做约定优于配置范式。设置的结果很简单,您需要进行许多配置更改,如果您遵循默认设置(特别是文件夹结构),则不需要这些更改......这使其更易于使用,也便于其他人使用。这样可以节省时间和金钱...
标签: eclipse maven terminal java-7