Home > Mobile >  Maven: how to find dependencies
Maven: how to find dependencies

Time:07-28

Maybe I am misunderstanding Maven's dependency principles but this is my question:

I have a little Java program that requires these imports

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.StringReader;
import java.io.StringWriter;

Now instead of importing these at the top of the code, I would just go into the POM file of my Maven project and add the dependencies. But on https://mvnrepository.com/ how do I find the correct imports? Is there another way besides looking on that site?

Thank you.

CodePudding user response:

Now instead of importing these at the top of the code, I would just go into the POM file of my Maven project and add the dependencies.

No. You are conflating two different things:

  • Managing dependencies (downloading and placing libraries within your project)
  • Using dependencies (calling the library’s classes and methods from within your code)

Managing dependencies

To use a library, you need to obtain a physical copy, a file, usually a .jar file. You can manually download a copy. Or you can use Maven or Gradle to download a copy on your behalf. The Maven or Gradle approach is generally recommended over the manual approach.

Once downloaded, you need to place the file where it can be found within your project. Again, you can do this manually, or you can use Maven or Gradle to make the file available to your project. Again, the Maven or Gradle approach is generally recommended over the manual approach.

Using dependencies

After having obtained and placed a copy of the library, you are ready to access its classes and methods.

  • Related