Java and spring boot: Can you automatically generate dependencies in eclipse or another program?

732 Views Asked by At

I have a problem with an application built in java and spring boot.

1/ How can to generate eclipse project from only src folder? Is it possible to somehow automatically generate dependencies (pom.xml etc.)? I don't have a pom.xml file, just a src folder? Is there any way to automatically generate project from src folder in e.g. eclipse and generate dependencies automatically?

2/ Second question: I would like to move a java application from one server to new another server. I don't have project files. I have the structure as below in Tomcat webapps:

Application structure

Is it possible to generate a project from this strukture in eclipse or intelliJ? I am asking for help and some step-by-step instructions. I'm just learning java

2

There are 2 best solutions below

2
mute_police On

Maven is Separate from Java, Maven is used to inject dependencies into your application so that you may import them freely in your project.

If you are using Spring, you may use the initializer to add dependencies and create a pom.xml , that in the end you may import to eclipse in order to get your project started.

Spring Initializr

0
Mark Bramnik On

It doesn't work like this, actually it works in an opposite direction:

  1. You start with a project with java files.
  2. You use maven or gradle as a build system. Technically it means that you place the sources in some folder which is by convention recognized by these build tools and add some build tools specific files. For example for maven you add pom.xml file.
  3. In the pom.xml (I'll stick to maven) add all the relevant dependencies. Its important to understand that you don't generate these dependencies because you want to be sure that the correct dependencies are added with the verified versions, etc. So you define dependencies by yourself, rather than generate them from your source code.
  4. Build tool prepares the artifact (JAR, WAR, etc.) - whatever is required by your project.
  5. To directly address your second question - if you write everything correctly, the generated artifact should not depend on the environment its intended to be run in. For example, if you hard-code an address of your locally installed database so that this data finds its way into the resulting artifact - this means that the artifact will depend on your environment and this is wrong.
  6. Eclipse / IntelliJ as an IDE can read pom.xml file and parse all the dependencies out of it as like as setting up all the required stuff. So you can open pom.xml right in Eclipse and it will "prepare" an eclipse project for you.