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.
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.
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.
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:
I found a nice page when I thought about it! ** The Central Repository **. A repository search engine.
I will search for jsch immediately. Oh! came out. And it even has a download page: thumbs up_tone2: nice ~: two_hearts:
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 **. Exclude from the build path.
Of course, if you execute it as it is, an error will occur.
Search for postgresql in The Central Repository earlier. Oh! was. There was 42.2.4 in Latest!
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.
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