简体   繁体   English

使用 maven 创建 eclipse 源文件 src/main/java 和 src/main/groovy

[英]Creating eclipse source files src/main/java and src/main/groovy with maven

I am trying to get a specific kind of file structure in eclipse for my work.我正在尝试在 eclipse 中为我的工作获取一种特定类型的文件结构。 This is the structure I want:这是我想要的结构:

文件结构2

The problem I am having is that everytime I use mvn eclipse:eclipse the structure of the files gets broken like this:我遇到的问题是每次我使用mvn eclipse:eclipse文件的结构都会像这样被破坏:

文件结构1

I have tried most of the answers that I've found on Stack Overflow and elsewhere.我已经尝试了在 Stack Overflow 和其他地方找到的大多数答案。 I've tried making the fileStructure2 to a maven Archetype and it sort of worked, but as soon as I ran mvn eclipse:eclipse it broke again:我已经尝试将 fileStructure2 制作为 maven Archetype 并且它有点工作,但是一旦我运行mvn eclipse:eclipse它又坏了:

弧测试

I learned the basics of the archetype creation just today so I am not a master at that either and there might be something that is missing from the creation of the archetypes.我今天才学习了原型创建的基础知识,所以我也不是这方面的大师,原型的创建可能缺少一些东西。 I used mvn archetype:create-from-project in the FileStructure2 directory and then used mvn install archetype:update-local-catalog in the archetype directory which resulted the archetype to be added in the list of archetypes and I just created a new project with cmd and then ran mvn eclipse:eclipse which resulted in the above picture.我在 FileStructure2 目录中使用mvn archetype:create-from-project ,然后在原型目录中使用mvn install archetype:update-local-catalog这导致原型被添加到原型列表中,我刚刚创建了一个新项目cmd 然后运行mvn eclipse:eclipse得到上图。 I have not changed anything in the archetype folders that were created, I just used the basic ones that were created with running the archetype:create.我没有更改创建的原型文件夹中的任何内容,我只是使用了通过运行原型创建的基本文件夹:create。

Most of the other posts i've found are really old and none of them have the structure I want, or it is only for src/main/java which I get working as intended but it is just the src/main/groovy file that switches the location to a normal folder instead of a source folder.我发现的大多数其他帖子都很旧,而且没有一个具有我想要的结构,或者它仅适用于我按预期工作的 src/main/java,但它只是 src/main/groovy 文件将位置切换到普通文件夹而不是源文件夹。

I am thinking it is my pom.xml that needs some modifications.我认为这是我的 pom.xml 需要一些修改。 at the moment it looks like this:目前它看起来像这样:

<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>FileStructure</groupId>
  <artifactId>FileStructure</artifactId>
  <version>0.0.1-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.5.0</version>
            <type>pom</type> <!-- required JUST since Groovy 2.5.0 -->
        </dependency>
    </dependencies>  
</project>

I have not added any maven compiler plugins since I don't 100% know what they do and still break the structure no matter what I've tried.我没有添加任何 maven 编译器插件,因为我不是 100% 知道它们在做什么,并且无论我尝试了什么仍然会破坏结构。

I am using apache-maven-3.8.5 which is downloaded with chocolatey.我正在使用通过巧克力下载的 apache-maven-3.8.5。 My eclipse jre and jdk versions are 1.8.0_333 but my java home is jdk11 since sonarQube can't use that old versions.我的 eclipse jre 和 jdk 版本是 1.8.0_333,但我的 java home 是 jdk11,因为 sonarQube 不能使用那个旧版本。 My groovy is downloaded from the eclipse marketplace and it's compiler version is 2.5.我的 groovy 是从 eclipse 市场下载的,它的编译器版本是 2.5。 My eclipse is a SAP netweaver.我的eclipse是一个SAP netweaver。 Eclipse Java EE IDE for Web Developers.面向 Web 开发人员的 Eclipse Java EE IDE。 Version: Oxygen.3a Release (4.7.3a)版本:Oxygen.3a 版本 (4.7.3a)

I have converted the projects to maven and groovy via Eclipse's own methods.我已经通过 Eclipse 自己的方法将项目转换为 maven 和 groovy。

Eclipse Groovy Development Tools will do this. Eclipse Groovy 开发工具将执行此操作。 There is a guide here with steps to achieve your desired result:这里有一个指南,其中包含实现所需结果的步骤:

https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-Maven-plugin https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-Maven-plugin

There is an archetype as well but it is not pre-built: https://github.com/groovy/groovy-eclipse/tree/master/extras/groovy-eclipse-quickstart还有一个原型,但它不是预先构建的: https ://github.com/groovy/groovy-eclipse/tree/master/extras/groovy-eclipse-quickstart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM