for a single program in Java that is not part of the Maven project.
Is there a good way to add an external library?
For example, in a program that uses an external library,
import java.io.*;
import org.apache.commons.csv.*;
public class Main {
public static void main(String[]args) {
try{
Reader fr = new FileReader("ppap.csv");
Iterable<CSVRecord> records=CSVFormat.RFC4180.withHeader().parse(fr);
for (CSVRecord rec:records) {
System.out.println(rec.get("a"));
}
}catch(IOExceptione){}
}
}
I am now manually downloading the .jar file to go through the compilation.
Manually specify -classpath during compilation and startup.
This is troublesome, but what kind of method do you use?
Thank you for your cooperation.
For Java projects, you can manage dependencies on Maven or Gradle.With this system, the folder configuration is fixed, so there is little freedom, but it is convenient because you can easily add dependencies and update them.
After installing Maven, run mvn archive type:generate
from the command and enter the package name and Jar filename to create a Maven configuration file (pom.xml) and folder configuration (you may need to press Enter again on Windows).
Choose org.apache.maven.archetypes:maven-archtype-quickstart version:
1:1.0-alpha-1
2:1.0-alpha-2
3:1.0-alpha-3
4:1.0-alpha-4
5: 1.0
6: 1.1
Choose a number : 6: Define value for property 'groupId' : com.example
Define value for property 'artifactId': hogehoge-app
Define value for property 'version' 1.0 - SNAPSHOT:
Define value for property 'package' com.example::
Confirm properties configuration:
groupId—com.example
artifactId—hogehoge-app
version —1.0-SNAPSHOT
package —com.example
Y : —y
After that, you can run a single test in mvn test
or create a Jar file in mvn package
and run mvn exec:java-Dexec.mainClass=com.example.App
to run the main class.
Simply search search.maven.org to add dependencies and add the XML of <dependency>
that appears on the detail screen to <dependencies>
in the pom.xml file.
© 2024 OneMinuteCode. All rights reserved.