Jeeva
Jeeva

Reputation: 1057

How to install my own Java library?

I created a Java class for helping me to use some common debuggin stuffs, for example to get the type of value, I have a method call typeOf()

Help help = new Help();
String s = "Something";
help.alert(help.typeOf(s));

above is a sample code in my class

Now every time I start a project, I need copy the class file to my project, so I want to know is there any way I can install this in my OS, then can import it to any of project whenever I needed.

In C you can move the header file to a location, then you can #include it whenever you want

Upvotes: 1

Views: 409

Answers (1)

ישו אוהב אותך
ישו אוהב אותך

Reputation: 29794

If you using gradle, you can learn it from Building your own Android library but need to publish your library to jCenter or Maven Central.

Fortunately, you can make the library as a local artifact using maven plugin in the library. Read more at Deploying an Artifact to the Local Cache in Gradle

In your project, you need to add mavenLocal() to the repositories in your root build.gradle:

repositories {
  mavenCentral()
  mavenLocal()
}

And add the dependencies to your project build.gradle:

dependencies {
  ...
  compile 'com.your.library:x.y.z'
  ...
}

But if your project is shared in your local network, you need to use Repository management like Artifactory by JFrog or Nexus Repository Manager by Sonatype.

Upvotes: 2

Related Questions