简体   繁体   English

运行现有 spring 启动 gradle 项目的问题

[英]Issue running existing spring boot gradle project

Recently, I started working on a multi module spring boot gradle project.最近,我开始研究一个多模块 spring 启动 gradle 项目。 Am new to gradle and also to the team but I have some experience with Spring boot.我是 gradle 和团队的新手,但我对 Spring 启动有一些经验。

The structute is like Main Project do not contain java files and has only gradle and config info, then its sub project contain spring boot project.该结构就像主项目不包含 java 文件,只有 gradle 和配置信息,然后它的子项目包含 spring 引导项目。 While I try to run the project, I get Main Class not found error even though the class exists当我尝试运行该项目时,我得到 Main Class not found 错误,即使 class 存在

I know there must be some configuration done in order to run this but I am unable to identify how to get the details.我知道必须进行一些配置才能运行它,但我无法确定如何获取详细信息。

This is an old project and no one has any details.这是一个老项目,没有人知道任何细节。 Can someone help on how to dig gradle files to get the configuration or atleast start the project?有人可以帮助了解如何挖掘 gradle 文件以获取配置或至少启动项目吗?

Edit:编辑:

Okay so, I somehow, decided to ignore IDEs and played around with commands.好吧,不知何故,我决定忽略 IDE 并玩弄命令。 I came to a point that yml files in root folder is not recognized by jar(created from gradle build).我发现 jar 无法识别根文件夹中的 yml 文件(从 gradle 构建创建)。 as mentioned above, Spring boot project is in child project, where as config(yml files) in root foler.如上所述,Spring 引导项目位于子项目中,其中根文件夹中的配置(yml 文件)。

I added --spring.config.location to java -jar but then understood the jar is generated without dependencies.我将 --spring.config.location 添加到 java -jar 但后来了解到 jar 是在没有依赖关系的情况下生成的。 Any idea how to add them in classpath or build the jar with dependencies?知道如何将它们添加到类路径中或构建具有依赖关系的 jar 吗?

It actually depends on project, there might not be the main class.它实际上取决于项目,可能没有主要的 class。

If your project is.jar based:如果你的项目是基于.jar:

Gradle multi projects usually have master Gradle module, however, the main class not necessary would be in the main directory. Gradle 多项目通常有主 Gradle 模块,但是,主 class 不必在主目录中。

This could be in another module.这可能在另一个模块中。 If you have Intellij after it finishes indexing project you will see at the top right corner run the class (near green triangle) if you would expand it instead you will be able to see 'Edit configuration...'.如果您在完成索引项目后拥有 Intellij,您将在右上角看到运行 class(靠近绿色三角形),如果您将其展开,您将能够看到“编辑配置...”。

Then select class, you were seeing before, typically if the project uses Spring Boot there will Spring Boot icon in configuration list on the left.然后 select class,你之前看到过,通常如果项目使用 Spring 启动,在左侧的配置列表中会出现 Z38008DD81C2F4D7985ECF6 的启动列表。

As soon as you select the class you will have 'Environment tree', there will be field 'Use classpath of Module', you will see the right module for start.只要你 select class 你将有“环境树”,会有“使用模块的类路径”字段,你会看到正确的模块开始。


If your project war archive-based:如果您的项目基于战争档案:

You won't have any main classes.你不会有任何主要课程。

As a side note, I advise to check out setup or readme files of the projects.作为旁注,我建议查看项目的设置或自述文件。

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

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