Implement pwinty API using Java library - java

I'm trying to get to grips with using pwinty with a site i'm developing and seem to be in way over my head. The library file I (think I) need is: https://github.com/OddPrints/pwinty-java-sdk. I can't seem to find any proper clues on how to go about incorporating this.
Do I need to somehow package the zip into another format? If so, how?
Do I link this to my html using a tag? What then?
Any help would be much appreciated - thanks!

Seems like the author did not publish compiled jars to a central repository like JCenter or maven central.
In order to use it you will have to clone and build the jars from sources.
Should be simple, however, the build needed some tweaks to make it work.
See following steps:
git clone https://github.com/OddPrints/pwinty-java-sdk.git
Edit build.gradle in the newly cloned repo:
https://gist.github.com/galusben/967319bdff5ae6fb0bbc64081a547c47
run './gradlew build -x test'
Make sure you find the sdk jars in your m2: '~/.m2/repository/uk/co/mattburns/pwinty/pwinty-java-sdk/2.3.1'
In your project, if you are using maven simply add the dependency. If you are using gradle you will have to add mavenLocal() to your repositories and add apply plugin: 'maven' gradle example: https://gist.github.com/galusben/e0f71f90da3488ebacc0a46c7412d8fa
Otherwise, just add the jars to your project.

Related

Including dependencies in Java project on Intellij/Maven?

This sounds dumb but is there anyway for me to specify dependencies for my Java project like how I would in a package.json file so that someone else who was to download the project code from my GitHub repo, would be able to run it without any errors or missing libraries?
I have never tried using external Java libraries before, such as apache commons. The most I ever used was JavaFX but on a personal project level. My main concern is that if I were to push my code up to the repo and have someone else clone it. It might not run properly as the imported libraries are not downloaded.
Is there something similar to package.json dependencies where the person who runs the code would automatically download all dependency libraries and have it run on their system?
You can use Maven or Gradle for this purpose. Maven has pom.xml where you can specify all your dependencies. Similarly gradle has build.gradle which does the same job.

How to include reference to library in java gradle project

I am coming from a C# background. I am used to NuGet and Visual Studio project references so the Java ecosystem has confused me quite a bit.
I have a gradle library project. I want to import org.apache.commons.codec.binary.Base64;
However I keep getting cannot resolve errors.
I am using VSCode as my IDE and I would like to include the codec dependancy. How would I achieve this in VSCode/gradle.
I have downloaded the commons-codec-1.14.jar file, but don't know where to put it in the project.
Gradle is a tool that, among other things, manages your dependencies. This means that, you do not need to manually download and add dependencies to your project. Gradle solves this for you.
See the official documenation on how to handle dependencies with Gradle.
You probably have a build.gradle file, in which you need to include your dependency. It would look something like:
dependencies {
implementation 'commons-codec:commons-codec:1.14'
}
This lets Gradle know that you have a dependency to version 1.14 of commons-codec which your codes need to build and run.
This will automatically be downloaded from a remote repository, which you also can specify in your build.gradle file:
repositories {
mavenCentral()
}
This tells gradle to download the dependencies from Maven Central, which probably is the most typical Maven/Gradle repository and most likely hosts most dependencies you would need.

How to use the library of other projects in Java with Gradle

I'm still fairly new to development and don't know how to solve my problem.
I have a project that needs other code for it to work.
I understand that by adding a path n the import section of my java gives access to a library.
I also understand that by adding a compile dependency to my build.gradle file, tells it where that library is.
My question is two part:
What do I do when it fails to resolve dependency?
I have downloaded the source code off of git hub.
I want to be able to add the source to my project.
Now, I don't want to add it directly to my package, but the way gradle does it. Just by pointing to it.
So my real question, how do I get a library into my code without adding the entire source code into the package?
What would I have to do in my import section of my java file?
P.S.
Thanks in advance.
Since I'm still learning the concepts, my question might not be structured in the best manner.
You could create a jarfile from the those sources:
jar cf program.jar -C path/to/classes .
source: https://stackoverflow.com/a/18146453/7625131
further information: https://docs.oracle.com/javase/tutorial/deployment/jar/build.html
After that you just have to reference it using gradle:
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile name: 'gson-2.2.4'
}
source: https://stackoverflow.com/a/20700183/7625131
As Mett highlighted. Create a jar of the project that you cloned from github. Add it in the buildpath of your desired project . If you are using a build automation tool like maven or gradle , then install the jar in your local repository. Then use it as a dependency in your project.

IntelliJ plugin: maven, gradle and travis-ci

Currently, my built structure for a plugin in is a bit messy: I'm using the normal IDEA project file to build the plugin locally. When I push it to the repo and travis-ci is building it, it uses the maven pom.xml because for travis to work, it always has to download the complete IDEA sources.
Although this works, this has several drawbacks:
I need to keep two built mechanisms up to date. This is
When a new IDEA version is out (every few weeks), I need to change the SDK in maven and in my IDEA settings
When I add a new library, change resources, etc. I need to do this for two the two settings as well
I ran into problems when I kept the IDEA Maven plugin turned on because it saw the pom.xml and interfered with my local built. Turning it off means, I cannot download libraries with Maven which has the feature of tracking dependencies.
I saw that Gradle has an 'idea' plugin and after googling, I got the impression that Gradle is the preferred choice these days. I have seen Best way to add Gradle support to IntelliJ IDEA and I'm sure I can use the answers there to turn my pom.xml into a valid build.gradle.
However, maybe someone else has already done this or can provide a better approach. What I'm looking for is a unified way to build my plugin locally and on Travis-CI.
Some Details
For compiling an IDEA plugin, you need its SDK which you can access through an installation of IDEA or a download of the complete package. Locally, I'm using my installation for the SDK. With Travis, my maven built has the rule to download the tar.gz and extract it.
It turns out that in particular for building an IntelliJ plugin, Gradle seems to have many advantages. This is mainly due to the great IntelliJ plugin for Gradle which makes compiling plugins so much easier. With Gradle, I could turn my >220 lines of Maven build into a few lines of easily readable Gradle code. The main advantages are that
It takes care of downloading and using the correct IDEA SDK while you only have to specify the IDEA version.
It can publish your plugin to your Jetbrains repository and make it instantly available to all users
It fixes items in your plugin.xml, e.g. you can use one central version number in gradle.build and it will keep plugin.xml up-to-date or it can include change-notes
It seamlessly integrates with Travis-CI
How to use Gradle with an existing IDEA plugin
Do it manually. It's much easier.
Create an empty build.gradle file
Look at an example and read through the README (there are many build.gradle of projects at the end) to see what each intellij property does.
Adapt it to your plugin by
Setting the intellij.version you want to build against
Setting your intellij.pluginName
Define where your sources and resources are
Define your plugin version
Define a Gradle wrapper that enables people (and Travis) to build your plugin without having Gradle
Create the gradle wrapper scripts with gradle wrapper
Test and fix your build process locally with ./gradlew assemble
If everything works well, you can push build.gradle, gradlew, gradlew.bat and the gradle-folder to your repo.
Building with Travis-CI
For Travis you want to use the gradlew script for building. To do so, you need to make it executable in the travis run. An example can be found here.

Elasticsearch without Maven

Recently I have begun working on a Java Spring project that does not use Maven and I need to build elasticsearch functionality into the program but I cannot find any information about how to import elasticsearch without the use of Maven.
Has anyone ever had to do something similar?
Is it maybe possible to just use Maven on this one part of the project?
Thank you for any help.
Maven just provide you a way to manage your dependencies. So, if you manage your dependencies in directly downloading JARs, you just have to download all the dependencies you needs and include them in your classpath.
As #Camille Gerin-Roze said , all you need is to download the ElasticSearch dependencies and add them to the classpath.
A place to start is :
https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch/2.3.5
And using the "Download Jar" link
If you scroll down and read the part that says "Compile Dependencies (32)" , it will tell you what other dependencies you need to download manually and add to the class path.
Please note that each of these dependencies may or may not have co dependencies that you may need to download and add to the classpath as well.

Categories

Resources