猿问

在定制sourceDirectory的情况下Eclipse Maven构建路径问题

我已经将现有的Java项目转换为Maven项目,并且在使用命令行时,Maven可以完美构建所有内容。


当我将同一个项目导入Eclipse并进行编译时(通过右键单击该项目->作为Maven构建运行,它仍然可以毫无问题地进行编译。


但是,我看不到源文件夹。当我检查构建路径时,它会发出警告-缺少构建路径条目。


我没有使用standard,src/main/java因为我有一个无法更改的项目预先存在的文件夹结构。


这是我的pom(注意sourceDirectory标签):


<project xmlns="http://maven.apache.org/POM/4.0.0"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycom</groupId>

  <artifactId>maven</artifactId>

  <version>17.4</version>

  <name>maven</name>

  <properties>

    <projecrt.rootDir>../../java</projecrt.rootDir>

  </properties>

  <build>

    <finalName>re</finalName>

    <sourceDirectory>${projecrt.rootDir}</sourceDirectory>

    <plugins>

      <plugin>    

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-jar-plugin</artifactId>

        <version>2.4</version>

        <configuration>

          <archive>               

            <manifestEntries>

              <Build-Version>${buildversion}</Build-Version>

            </manifestEntries>

          </archive>

        </configuration>

      </plugin>

    </plugins>

  </build>  

</project>

这是我的目录结构:


Src/java

----maven/pom.xml

----com/mycom/<...> // application code


子衿沉夜
浏览 257回答 2
2回答

小怪兽爱吃肉

您可以使用此build-helper-maven-plugin并以这种方式在您的pom文件中对其进行配置<project>&nbsp; ...&nbsp; <build>&nbsp; &nbsp; <plugins>&nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.codehaus.mojo</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>build-helper-maven-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>3.0.0</version>&nbsp; &nbsp; &nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <id>add-source</id>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <phase>generate-sources</phase>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>add-source</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <sources>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <source>some directory</source>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </sources>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; &nbsp; &nbsp; </executions>&nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; </plugins>&nbsp; </build></project>现在,当您执行mvn eclipse:eclipse此操作时,自定义源文件夹将被添加到文件中的类路径条目中.project。因此,您无需进行任何手动配置,您的配置将仅在运行时得到构建。如果将测试放在自定义源文件夹中,则也可以对测试源执行相同的操作。希望这可以帮助。

烙印99

将Java项目导入Eclipse工作空间后,就可以指定实际的src文件夹:单击“打开Java透视图”窗口>“打开透视图”>“其他...”>“ Java”以更改为Java透视图。在“项目布局”组中,将选择更改为“创建单独的源文件夹和输出文件夹”,然后编辑“配置默认...”,以将源文件夹名称从“ src”修改为“ sources”。在项目(project => property => java build path)的设置中,您还可以更改/添加src文件夹:
随时随地看视频慕课网APP

相关分类

Java
我要回答