nostr-java icon indicating copy to clipboard operation
nostr-java copied to clipboard

Java 17 LTS as minimum

Open maxbrito500 opened this issue 1 year ago • 4 comments

Hello,

Can you please change the settings on the project pom.xml to target Java 17 since that is the LTS?

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>

On most VM/servers when deploying are conservative and only make JDK 17 available by default.

I've tested and compiled OK, did not went further yet.

Thanks.

maxbrito500 avatar Aug 10 '24 14:08 maxbrito500

you can target compile/deploy 17 as per your needs. downgrading the version in repository pom is not necessary (nor desirable).

avlo avatar Aug 10 '24 19:08 avlo

Thanks, it was just because the README mentioned 19 as the supported version. For my case I've done as you mention.

Was trying to use the library but was unfortunately not able to use it, the only thing working at the moment is the generation of private/public keys but all the rest was with a lot of errors about missing classes.

The documentation for setting up Maven also took me a while to setup. Maybe possible to correct:

<properties>
        <nostr-java.version>0.6.1-SNAPSHOT</nostr-java.version>
    </properties>
<dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-base</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-crypto</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-event</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-examples</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-id</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-test</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-util</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-connection</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-command-interface</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-command-provider</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-client</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-api</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-encryption</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-encryption-nip04</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-encryption-nip44</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-context</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-context-interface</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-controller</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>

This is the most developed library in java for Nostr. I would like to help adding patches and fix where possible but I couldn't solve the current problems that were appearing, it was just incomplete.

Had to write a standalone library to sign nostr events: https://github.com/nostrium/java/blob/main/src/main/java/online/nostrium/utils/NostrSign.java

But still using your library where possible: https://github.com/nostrium/java/blob/main/src/main/java/online/nostrium/utils/NostrUtils.java#L26

I'll be needing the basic features in either case such as sending messages to the relays and retrieving other info. Instead of writing something separated would prefer to submit contributions here.

maxbrito500 avatar Aug 10 '24 20:08 maxbrito500

you should have no issue compiling (and all successful unit/integration tests1) using java 19.0.2

$ java -version
java version "19.0.2" 2023-01-17
Java(TM) SE Runtime Environment (build 19.0.2+7-44)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)

and maven version 3.9.4:


$ mvn -version
Apache Maven 3.9.4 (dfbb324ad4a7c8fb0bf182e6d91b0ae20e3d2dd9)
Maven home: /.../.sdkman/candidates/maven/3.9.4
Java version: 19.0.2, vendor: Oracle Corporation, runtime: /.../jdk-19.0.2
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-118-generic", arch: "amd64", family: "unix"

w/ pom maven.compiler version set to 17:

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>

1ClientTest test is known/expected to fail if no local relay running

[ERROR] ClientTest.disconnect:77 expected: <2> but was: <0>

avlo avatar Aug 10 '24 21:08 avlo

also, your pom nostr-java module dependencies might be more than required for your use case.

see superconductor/pom.xml, lines 92-106 for a working reference

avlo avatar Aug 10 '24 21:08 avlo

These libraries are still so complicated to make work. Had to move into another machine, discover that the code cannot be compiled because it fails to find these libraries.

I'm not an expert on Maven. For all other libraries just need to add the dependency lines and it works as expected. I've followed the instructions on the main page but it assumes a lot of information that I don't know. These libraries are NOT on https://mvnrepository.com/ so where can I find them?

Can you please make the documentation more clear to follow? My thanks in advance, I'd submit a change request but I honestly have no clue how to improve this and I'm sure many others will have the same difficulty.

maxbrito500 avatar Aug 26 '24 08:08 maxbrito500

many dozens of developers compile, use and build upon these libraries without issue, including myself. since any single person's development environment and settings may vary in ways that are non-standard, which is commonly the reason problems like yours arise, to minimize ambiguities and help troubleshoot your problem, please submit below information:

  1. Description: A detailed description of the issue.
  2. Environment Settings: java version, maven version, environment path and classpath settings.
  3. Steps to reproduce: Clear and specific steps to replicate the issue.
  4. Expected behavior: Description of what expected results should be.
  5. Actual behavior: Description of what the software is doing instead.

avlo avatar Aug 26 '24 19:08 avlo

Brito, It's hosted on jitpack, not mvnreposirory.

-- Sent with Tuta; enjoy secure & ad-free emails: https://tuta.com

26 Aug 2024, 10:13 by @.***:

These libraries are still so complicated to make work. Had to move into another machine, discover that the code cannot be compiled because it fails to find these libraries.

I'm not an expert on Maven. For all other libraries just need to add the dependency lines and it works as expected. I've followed the instructions on the main page but it assumes a lot of information that I don't know. These libraries are NOT on > https://mvnrepository.com/> so where can I find them?

Can you please make the documentation more clear to follow? My thanks in advance, I'd submit a change request but I honestly have no clue how to improve this and I'm sure many others will have the same difficulty.

— Reply to this email directly, > view it on GitHub https://github.com/tcheeric/nostr-java/issues/176#issuecomment-2309615159> , or > unsubscribe https://github.com/notifications/unsubscribe-auth/ABQMG7D3LXQ5YMY2SNRE44LZTLPSXAVCNFSM6AAAAABMJ36RTGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBZGYYTKMJVHE> . You are receiving this because you are subscribed to this thread.> Message ID: > <tcheeric/nostr-java/issues/176/2309615159> @> github> .> com>

tcheeric avatar Aug 26 '24 19:08 tcheeric

Thank you @avlo and @tcheeric, that hint was enough to understand what to get fixed. It is now working and I'm a happy user. Will support this library by sharing the notes from newbie perspective.

Inside pom.xml

Define the value for the most recent version available:

    <properties>
        <nostr-java.version>0.6.1-SNAPSHOT</nostr-java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

Add Jitpack to the repositories:

    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>

Finally add the dependencies:

        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-api</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-event</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>
        <dependency>
            <groupId>nostr-java</groupId>
            <artifactId>nostr-java-id</artifactId>
            <version>${nostr-java.version}</version>
        </dependency>

After this is possible to use the library. For example:

        Identity RECIPIENT = Identity.generateRandomIdentity();
        
        System.out.println("NSEC: " + RECIPIENT.getPrivateKey().toBech32String());
        System.out.println("NPUB: " + RECIPIENT.getPublicKey().toBech32String());

I'll propose a pull request. I think this ticket can be closed. Thank you for the quick help.

maxbrito500 avatar Aug 26 '24 20:08 maxbrito500