英文:
Issue running existing spring boot gradle project
问题
最近,我开始着手处理一个多模块的 Spring Boot Gradle 项目。我对 Gradle 和团队都还不熟悉,但我对 Spring Boot 有一些经验。
项目结构如下:主项目不包含 Java 文件,只有 Gradle 和配置信息,然后它的子项目包含 Spring Boot 项目。在我尝试运行项目时,虽然类存在,但出现了找不到主类的错误。
我知道肯定需要进行一些配置才能运行,但我无法确定如何获取这些详细信息。
这是一个旧项目,没有人有任何详细信息。有人能帮忙解决如何查找 Gradle 文件以获取配置,或者至少如何启动项目吗?
编辑:
好的,所以,我以某种方式决定忽略集成开发环境,而是尝试了一些命令。我发现根文件夹中的 yml 文件在通过 Gradle 构建生成的 jar 中无法识别。如上所述,Spring Boot 项目位于子项目中,而配置(yml 文件)位于根文件夹中。
我在运行 java -jar 时添加了 --spring.config.location 参数,但后来了解到生成的 jar 是没有依赖项的。是否有办法将它们添加到类路径中,或者带着依赖项构建 jar 包呢?
英文:
Recently, I started working on a multi module spring boot gradle project. Am new to gradle and also to the team but I have some experience with Spring boot.
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. While I try to run the project, I get Main Class not found error even though the class exists
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?
Edit:
Okay so, I somehow, decided to ignore IDEs and played around with commands. I came to a point that yml files in root folder is not recognized by jar(created from gradle build). as mentioned above, Spring boot project is in child project, where as config(yml files) in root foler.
I added --spring.config.location to java -jar but then understood the jar is generated without dependencies. Any idea how to add them in classpath or build the jar with dependencies?
答案1
得分: 0
实际上这取决于项目,可能没有主类。
---
如果您的项目是基于 .jar 的:
Gradle 多模块项目通常有一个主 Gradle 模块,然而,主类未必会在主目录中。
它可能在另一个模块中。如果您使用 IntelliJ,在它完成索引项目后,您将在右上角看到可以运行该类的选项(靠近绿色三角形),如果您展开它,您将能够看到 "编辑配置..."。
然后选择之前看到的类,通常如果项目使用 Spring Boot,左侧的配置列表中会有 Spring Boot 图标。
一旦您选择了该类,您将会看到 "环境树",那里会有 "使用模块的类路径" 字段,您将会看到适用于启动的正确模块。
---
如果您的项目是基于 war 存档的:
您将没有任何主类。
顺便提一下,我建议查阅项目的设置或自述文件。
英文:
It actually depends on project, there might not be the main class.
If your project is .jar based:
Gradle multi projects usually have master Gradle module, however, the main class not necessary would be in the main directory.
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 ...'.
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.
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.
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.
专注分享java语言的经验与见解,让所有开发者获益!
评论