Using the ziti-sdk-jvm

I am working through the postgres example… and are now at the final stage… to test the connection using a jdbc connection

In my configuration, I am working from a remote server… rather than a local machine… so I dont have access to an IDE to connect it to the ziti SDK using gradel

Is there a way to just manually mock it up … and configure the java compiler to connect to the ziti SDK

I don’t program in Java and are not really sure how to fix the path configuration

PS… I have cloned the ziti sdk on the server… so I must be 95% there

I’m sorry I missed this for so long. Did you end up sorting the problem?

all ok… I have found this problematic to setup… though I am not a Java developer

I wanted to compile the example to showcase it in a demo…

What I found is that you need to compile the whole SDK to use it… which is where I became stuck.

I did find a way to sort through most of the things… as I needed to learn how to use gradle.

for this to work… I needed to comment out most of the samples… there was some issue … but dont remember this specifics. I never really got it to fully compile the SDK cleanly.

However, I did manage to create a dirty snapshot that I could use in the class path… but… I did something wrong… and when I tried to run the app… there was some type of path problem

javac -classpath /home/opc/demo/ziti-sdk-jvm/ziti/build/libs/ziti-0.23.13-dirty-SNAPSHOT-full.jar

This is as far as I got… then I decided to stop… as it was taking too much time to build a once off demo…

Though… it would be nice to know if there are any tips I can try to get this over the line.

One alternative is to install eclipse… and build it all locally… but the demo is all on the server… so my preference is to avoid eclipse…

I would really like to use javac to compile the app… but I dont really know how to use it… as I am a first timer for java.

Let me know if you have any suggestions

No you definitely should NOT he trying to compile the sdk to use it. You should be using maven, Gradle, etc to pull the official artifact from the artifact repository. I think I have an old video where I showed accessing postgres via java. I’ll see if that is a good starter for you.

1 Like

Can you give me a link to the artifact repository. I think this is all I need

Yeah start with this project

That’s using Gradle to pull the sdk dependencies. The video is more about setting up the postgres environment than the Java sample but that’s here

When I go to the Java SDK repository… I am not sure where to find the artifact repository to download the jar file

When I go to the releases sections… it only has source code…

:grinning: today’s reading lesson then is to learn about Gradle, the Java build tool and dependency management in general.

This file specifies to the project for where gradle can get the dependencies.

1 Like

ahh… that will help… thanks… I will give this a go and will revert back

Making progress… :slight_smile:

I believe I now have a compiled app

steps taken were

cd /home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres

gradle build

However… I don’t know how to run it…

When I executed the following commands

cd build/classes/java/main/jdbc/postgres
java App

I received this error

Error: Could not find or load main class App
Caused by: java.lang.NoClassDefFoundError: jdbc/postgres/App (wrong name: App)

I don’t have much idea of what this means

any tips on how to resolve this would be totally awesome

Made a few inroads… as when I move to the libs folder… and run the folllowing command… it provides a different error message

java -classpath ./:jdbc-sample-postgres.jar jdbc.postgres.App

Exception in thread “main” java.lang.NoClassDefFoundError: org/openziti/Ziti

at jdbc.postgres.App.main(

Caused by: java.lang.ClassNotFoundException: org.openziti.Ziti

at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(

at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(

at java.base/java.lang.ClassLoader.loadClass(

I will try adding in the OpenZiti path… but dont really know what this is right now

Definitely stuck now…

I thought to use gradle build in the ziti directory to generate the jar… as I could not find it to include in the path

I believe I had this work… or at least… to some level of success…

However, when I run the following command

java -cp /home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres/build/libs/jdbc-sample-postgres.jar /home/opc/demo/ziti-sdk-jvm/ziti/build/libs/ziti-0.23.13-dirty-SNAPSHOT-full.jar jdbc.postgres.App

I get this error now

Error: Could not find or load main class

Caused by: java.lang.ClassNotFoundException: /home/opc/demo/ziti-sdk-jvm/ziti/build/libs/ziti-0/23/13-dirty-SNAPSHOT-full/jar

@dovholuknf … any suggestions on next steps to resolve this

I think i sort of made sense of this… and changed the command to the following

java -cp “/home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres/build/libs/jdbc-sample-postgres.jar;/home/opc/demo/ziti-sdk-jvm/ziti/build/libs/ziti-0.23.13-dirty-SNAPSHOT-full.jar” jdbc.postgres.App

Error: Could not find or load main class jdbc.postgres.App
Caused by: java.lang.ClassNotFoundException: jdbc.postgres.App

I think this resolved one problem… but creates another

Any tips?

ok… learning a few things. now… I found this in the gradle config… which is supposed to source the dependencies from the Maven repo.

so… I should not need to compile the ziti folder (phew)… I get this now

But… then why does it not pull through the ziti dependences?

Any tips

The mavenCentral() alias means that dependencies are fetched from the central Maven 2 repository.

repositories {

I found the source jar here… nice

I think I found the problem :slight_smile:

In the file… the import uses an upper case Ziti

import org.openziti.Ziti

However… in the maven repo it is a lower case ziti

one more go

Don’t change that… it causes the compile to fail :slight_smile:

Ok… think I am getting closer

This is the maven repo… for mavenCentral… but does not list openziti

I modified the file to include the URL … but must be doing something wrong

url = uri(“Central Repository: org/openziti/ziti/0.23.12”)

Actually… I found it

seems I worked something out… you use the -jar flag… not -cp :slight_smile:

java -jar /home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres/build/libs/*.jar jdbc.postgres.App

This now gives me another error… but I have a sense I am getting closer…

no main manifest attribute, in /home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres/build/libs/jdbc-sample-postgres.jar