Memo: [Java] How to check groupId etc. described in pom.xml

background

I'm always developing in Spring (Eclipse), and when I use an external library, I don't understand why I added an external jar on the Java build path screen and it became usable ~: slight_smile: I did it.

While writing various things in Java recently, that? If that work It means adding to pom.xml to specify the library that the program depends on. I have come to understand. 背景.png So let's graduate from adding an external jar: thumbs up_tone3: I thought that? I don't know ** <groupId> ** just from the downloaded jar: frowning2: That's why I will write down what I checked.

To specify which libraries depend on Add the ** <dependency> ** tag inside the ** <dependencies> ** tag of pom.xml. Like this By the way, this is the description of jsch used in the previous Getting Raspberry Pi data by SFTP.

pom.xml


    <dependencies>
		<dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.54</version>
        </dependency>
    </dependencies>

There are three elements in the ** <dependency> ** tag: ** <groupId> <artifactId> <version> **. By specifying these correctly, the dependencies will be recognized.

** How to check the values specified for groupId, artifactId, version **

Then how should I write that element? You can't write it properly. Maven's default repository is ** here **. The values specified for groupId and artifactId are included in this.

Then I will look for jsch immediately. com.jcraft ... and oh! Is true. was. 1.png

However, the library I want to use is from a huge number of repositories. It's too hard to find out where it's in ...: disappointed_relieved: 2.png

I found a nice page when I thought about it! ** The Central Repository **. A repository search engine. 3.png

I will search for jsch immediately. Oh! came out. And it even has a download page: thumbs up_tone2: nice ~: two_hearts: 4.png

** Add library to pom.xml **

As an example, let's try with the library called postgresql used in this project called ConnectDB. Add data to sample.java by connecting to PostgreSQL. I am writing the code of the contents. It's a necessary library for that, but as usual I added this library with ** Add jar **. 5.png Exclude from the build path. 6.png

Of course, if you execute it as it is, an error will occur. 7.png

Search for postgresql in The Central Repository earlier. Oh! was. There was 42.2.4 in Latest! 8.png

Now, add groupId, artifactId, and version to pom.xml.

pom.xml


		<!-- postgresql_adding_at_self_ -->
		<dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
			<version>42.2.4</version>
		</dependency>

Alright, let's run it. It was good. I was able to execute it properly. 9.png

** Postscript **

Recently, I feel that the vague points have become vague lines ...: open_mouth: A configuration file is a mysterious thing (a mass of weakness) in which a huge number of mysterious characters are listed. I was wondering, but I finally realized that configuration files are useful, not just Java. I hope it will be helpful for those who are not good at configuration files like me.

Recommended Posts

Memo: [Java] How to check groupId etc. described in pom.xml
How to generate / verify ID token in Java Memo
How to learn JAVA in 7 days
How to use classes in Java?
How to name variables in Java
How to concatenate strings in java
How to check Java installed on Mac
How to implement date calculation in Java
How to implement Kalman filter in Java
Multilingual Locale in Java How to use Locale
How to do base conversion in Java
How to implement coding conventions in Java
How to embed Janus Graph in Java
How to get the date in java
[Personal memo] How to interact with a random number generator in Java
How to read log4j configuration file in Java project summarized in jar file Memo
(Memo) How to solve dummy output in Ubuntu 20.04
How to check the logs in the Docker container
How to display a web page in Java
How to get Class from Element in Java
How to hide null fields in response in Java
[Java] How to substitute Model Mapper in Jackson
How to solve an Expression Problem in Java
[Java] Memo on how to write the source
How to write Java String # getBytes in Kotlin?
How to check Rails commands in the terminal
How to check the latest version of io.spring.platform to describe in pom.xml of Spring (STS)
How to call functions in bulk with Java reflection
How to create a Java environment in just 3 seconds
[Java] How to omit the private constructor in Lombok
How to input / output IBM mainframe files in Java?
How to create a data URI (base64) in Java
How to convert A to a and a to A using AND and OR in Java
How to convert a file to a byte array in Java
How to Git manage Java EE projects in Eclipse
Summary of how to implement default arguments in Java
How to put old Java (8 series) in macOS 10.15 Catalina
Notes on how to use regular expressions in Java
How to get the class name / method name running in Java
How to correctly check the local HTML file in the browser
[Java] How to use Map
How to read your own YAML file (*****. Yml) in Java
[AWS] How to check logs
How to lower java version
[Java] How to use Map
How to uninstall Java 8 (Mac)
How to use java Optional
How to minimize Java images
How to write java comments
Easy way to check method / field list in Java REPL
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to display Wingdings
How to store a string from ArrayList to String in Java (Personal)
[Java] How to use string.format
What happened in "Java 8 to Java 11" and how to build an environment
How to use Java Map
How to call and use API in Java (Spring Boot)
How to set Java constants
How to use Java enums (Enum) in MyBatis Mapper XML