Api to download and load the necessary dependencies into the classloader.
This library is used to not have too large jar files. The dependencies are downloaded at startup if they have not yet been downloaded otherwise they are downloaded from the central repository of maven or a selected repository.
These instructions could be use in any type of java project.
First you need to retrieve CLibrary.
You can download the jar file in the releases.
Or get it from github packages: https://github.com/Cleymax/CLibrary/packages
Or get it from my personal repository:
- Maven
<!-- Add to repositories -->
<repository>
<id>cleymax-releases</id>
<url>https://repo.cleymax.fr/repository/maven-releases/</url>
</repository>
<!-- Add to dependencies -->
<dependency>
<groupId>fr.cleymax</groupId>
<artifactId>CLibrary</artifactId>
<version>1.0.3</version>
<scope>compile</scope>
</dependency>
- Gradle
// Add to repositories
maven {
name = 'cleymax-releases'
url = 'https://repo.cleymax.fr/repository/maven-releases/'
}
// Add to dependencies
compile 'fr.cleymax:CLibrary:1.0.3'
Example, you need Gson in your project. Add the annotation @Dependency
on any class to load Gson .
import fr.cleymax.clibrary.CLibrary;
import fr.cleymax.clibrary.Dependency;
@Dependency(groupId = "com.google.code.gson", artifactId = "gson", version = "2.8.6")
public class Main {
public static void main(String[] args)
{
final CLibrary library = new CLibrary(Main.class); //Initialize a new instance of `CLibrary`.
library.loads(); //Load all dependencies of the class that is set as a parameter when initializing the `CLibrary' instance.
}
}
You can load several dependencies in one class.
import fr.cleymax.clibrary.CLibrary;
import fr.cleymax.clibrary.Dependencies;
import fr.cleymax.clibrary.Dependency;
@Dependencies({
@Dependency(groupId = "com.google.code.gson", artifactId = "gson", version = "2.8.6"),
@Dependency(groupId = "com.googlecode.json-simple", artifactId = "json-simple", version = "1.1.1")
})
public class Main {
public static void main(String[] args)
{
final CLibrary library = new CLibrary(Main.class); //Initialize a new instance of `CLibrary`.
library.loads(); //Load all dependencies of the class that is set as a parameter when initializing the `CLibrary' instance.
}
}
You can choose where the dependencies are stored and downloaded.
final CLibrary library = new CLibrary(Main.class, new File("dependancies/"));
You can initialize an instance of CLibrary
without any parameters. But the method CLibrary#loads()
can no longer be used!
final CLibrary library = new CLibrary();
You can choose the repository or you have to download the dependency. Note that if the file cannot be uploaded with the custom repository then it will try to upload to maven's central repository.
@Repository(url = "https://repo.cleymax.fr/repository/maven-releases/")
@Dependency(groupId = "com.google.code.gson", artifactId = "gson", version = "2.8.6")
- @Cleymax - Idea & Initial work Discord: Cleymax#7002
See also the list of contributors who participated in this project.
- IntelliJ IDEA - IDE
- Maven - Project Management
CLibrary is licensed under the MIT license.