APIs given as .java, not .jar - java

I am new to Java and trying to import an API from GitHub, to use its functions in my project. API is on GitHub as Java files, but the only documentation I can find on the web is for Jar files.
I just need to access these functions in my code in Eclipse---what do I do?
Thanks!

Your various options include:
Figure out if the jars exist in a maven repository. Typically the project will mention that in their documentation. If so, you can use a package manager like maven or gradle to download that jar into your project.
If the project does not have jars in a public repository, check the Releases tab in github. It may have jars that the project owners have built.
If those are also not there, clone the repo and build the code into a jar yourself. The project would likely have build scripts committed or otherwise docs for how to build it.

Related

How to convert an existing eclipse/vscode Java Project from no build tools used to Maven base

Reference to this post:
How to add referenced library JAR files using relative path for eclipse Java project in vscode
I need to convert this project to use a Build technology since the referenced external JAR libraries could not be pushed the the On-premise BitBucket Git repo. I was told that such libraries must be hosted on a central Project Antifactory based on JFrog (https://www.jfrog.com/), then reference them using the relevant build tool. I decided to use Maven since I am familiar with this tool.
I need your help as follows:
How to convert the existing project to use Maven?
How to change the reference to such JAR files from local to use the JFrog Artifactory?
How to ignore the .class, .jar and other files not related to the source code, how I can ask git to ignore such files since they are now showing s Untraced.
Tarek
Not familiar about the first two questions but VS Code does have the configuration that can exclude extension-generated project settings files in User Settings.json:
"java.configuration.checkProjectSettingsExclusions": true

Recreating GitHub project without dependencies (Java)

I would like to use a GitHub repo inside a Script I'm writing. The Script will run inside an application which requires that the Script has minimal dependencies. By this I mean it can have a dependency on a standalone .jar or library, but not on one that has further dependencies. This is a security measure. My Script needs to have a dependency on a GitHub project, but that project also has its own dependencies. Is there any way to compress that GitHub project and its chain of dependencies into one standalone library or .jar?
I'm using IntelliJ (most recent version) if that helps. The GitHub project I need to use can be one of the following:
https://github.com/RuedigerMoeller/fast-serialization
https://github.com/EsotericSoftware/kryo
I need it to serialize and deserialize large object structures very quickly and frequently, otherwise my program doesn't operate on current data.
EDIT: So I did solve this issue, the solution was to use the Maven Shade plugin to compile an uber or fat .jar of the Maven project. This allowed me to bypass the security measure.
Having a dependency on a GitHub repo is having a source dependency (which might declare itself binaries dependencies in its own repo).
You would need to fork that repo, and transform its maven project in order to generate a fat jar (with for instance the Shade plugin).
And you would need to publish that new artifact to an artifact repository (like your own Nexus) in order for your project to depend on it.

Attach Sources - Maven Dependancies [NetBeans]

I am running NetBean 7.4 on Mac and I am sort of new to Maven dependancies.
I have been given a project that uses Maven to download a framework for networking simulation.
Turned out that the framework has a bug and the teacher gave us a public GitHub repository with all the source code for the framework, so that we can also modify it.
How do I connect the GitHub link (with sources) to NetBeans in order to being able to modify the framework classes? The "Attach Sources..." button that appears on the framework classes asks for a JAR or ZIP (if I download the ZIP from GitHub it doesn't work).
Moreover, it looks like the framework files in the Dependancies folder cannot be modified anyway (read-only files).
Thank you all.
to "connect" 2 different projects, the checked out source's version needs to be equal to the version in maven pom.xml.
So clone the github repository, figure out which branch/tag matches the version in your project and check it out. Then open the project(s). If you did that correctly (and assuming the github project is actually maven), your project's dependencies section will list them with project-like icon. Then the projects are linked.

Reuse a Java Package across different Projects

I'm a Java developer using Eclipse and Maven. There are some modules I created in a project that I'd like to reuse in my future projects. Is there any standard way to accomplish this using Maven?
I don't like the idea of including classpath in other project. I'm looking for a way to publish and share some specific packages using Maven and over the time I should have a consistent Java library for myself.
You can publish those already existing jars in your repo
using mvn clean package install
and then add those as a dependency to your pom file in the new projects, whereever you chose to use them
This is a very common usecase and nicely covered as maven multimodule project. Check the link for a simple example http://docs.codehaus.org/display/MAVENUSER/Multi-modules+projects. For local development it's enough to run mvn install. In a bigger project or shared environment you will need a maven repository.
Update:
Alternative link: Multi-module project builds with Maven and Gradle
If you want to reuse some code, then you would have to make a new artifact and add this one as a dependency to your over deliverables.
As mentioned by tigran this could be nicely done by using maven multi modules architecture but you can just create a new deliverable used other several projects.
If you can build a jar for the classes you want to reuse, you can deploy them to a Maven repository for future reuse by other projects. However, based on the comments I read so far, you want something like source code level sharing. I assume you use Windows platform for your development. You can use junction or symbolic link to link at the source code level between different projects. Also most of modern version control system like Accurev/Clearcase have support for symbolic link.

How do I deploy just the sources jar from a maven project?

We made a number of releases to our nexus repository without source jars attached. I would like to backfill the source jars for these releases.
What I tried to do was
checkout the tagged version that I wanted to upload sources for
update the pom with the attach-sources snippet
do a maven deploy
This failed with a 400 error code because the pom and artifact jar were already in the repository.
Is there any way to upload just the source jar?
you should be able to do this using maven deploy-file (this has the added benefit of generating the various file sums as well), details here (you would be using, among other things, "packaging=jar" and "classifier=source").
I think the simplest thing would be to just upload sources jar using 'curl'. You will not even need to make any changes for that.

Categories