我的项目
中有一个自定义结构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
关于未正确配置的任何建议吗?
答案 0 :(得分:0)
发布此帖子后,我很快就可以完成这项工作,但我想看看有人是否有不同的答案。在格式化此帖子以符合stackoverflow标准时,我注意到编译器插件正在将类写入/ Users / username / git / weatherdetails / Development / build。我说等等那是错的。它应该将它们写入/ Users / username / git / weatherdetails / Development / build / classes和/ Users / username / git / weatherdetails / Development / build / test-classes。我用谷歌搜索了如何在pom中更改目标目录并遇到该标记
<directory>Development/build</directory>
我将其添加到构建中并删除了
<outputDirectory>Development/build</outputDirectory>
来自编译器插件的标签,因为我在那里添加了它,以为它正在路径中创建自定义目标文件夹。运行它,它起作用了。所以现在我的构建看起来像这样
<build>
<sourceDirectory>Development/src/main</sourceDirectory>
<testSourceDirectory>Development/src/test</testSourceDirectory>
<!-- if you put just Development, it will erase everything in the development folder -->
<directory>Development/build</directory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</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>
希望这对某人有帮助!