在Eclipse Maven中链接源文件夹时出现错误 [英] Getting error in linking a source folder in eclipse maven

查看:124
本文介绍了在Eclipse Maven中链接源文件夹时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个空的maven项目,并创建了一个文件夹结构src/main/java. 现在,我想将本地存储库中的源链接到此src/main/java.

I created an empty maven project and it created a folder structure src/main/java. Now I want to link source from my local repo to this src/main/java.

如果我转到buildpath->link source,并将文件夹命名为src/main/java,则会得到

If I go to buildpath->link source, and name the folder as src/main/java, I get the

文件夹已存在错误

如果删除文件夹然后执行相同的步骤,则会出现以下错误.

If I delete the folder and then do the same step, I get following error.

前进的最佳方法是什么?

What is the best way to go forward?

我无法在回购位置更改项目结构,将文件夹复制到我的工作区将意味着稍后手动合并更改.

I cannot change the project structure in the repo location and copying the folder to my workspace would mean manually merging changes later.

编辑文件夹结构:

并构建我的 pom.xml 的一部分:

<build>
    <sourceDirectory>java</sourceDirectory>    
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <excludes>
                <exclude>**/old/**/*.java</exclude>
          </excludes>
          <includes>
            <include>java/com/**/*.java</include>            
          </includes>
        </configuration>
      </plugin>
      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <excludes>
                    <exclude>**/old/**/*.java</exclude>                 
                </excludes>
                <archive>
                    <manifest>
                    <addClasspath>true</addClasspath>
                    <classpathPrefix>lib/</classpathPrefix>
                    <mainClass>com.start.Start</mainClass>
                    </manifest>
                </archive>
            </configuration>
       </plugin>
    </plugins>
  </build>

推荐答案

使用buildpath->link source配置项目源时,它只是eclipse的配置.它所做的只是在eclipse .project文件中添加链接的源条目. Maven对此配置一无所知.当尝试使用此配置(通过maven)安装项目时,在已安装的工件中将看不到任何源代码.

When you configure your project source with buildpath->link source it is just a configuration for eclipse. All it does is adding a linked source entry in the eclipse .project file. Maven does not know anything about this configuration. When you try to install your project with this configuration (with maven), you will not see any source code in the installed artifact.

如果必须这样做,请在pom.xml文件中添加以下内容.这将通知Maven您正在使用其他项目文件夹结构. (不建议使用此配置,但可以使用)

If you have to do it this way add following to your pom.xml file. This will inform maven that you are using a different project folder structure. (this configuration is not recomended, but in your case it is usable)

<build>
   <sourceDirectory>Reletive path to source folder</sourceDirectory>
   .....
</build>

在eclipse端,只需给文件夹命名,即您的源主文件夹名称. (如来源")

At eclipse side just give folder the name, that your sources main folder name. (like "Source")

https://maven.apache.org /guides/mini/guide-using-one-source-directory.html

这篇关于在Eclipse Maven中链接源文件夹时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆