Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not found JDK 11 java.net.http.HttpClient #419

Closed
caseylai opened this issue Jan 17, 2023 · 3 comments
Closed

Not found JDK 11 java.net.http.HttpClient #419

caseylai opened this issue Jan 17, 2023 · 3 comments

Comments

@caseylai
Copy link

I have a simple PL/Java program of using JDK 11 (also tried 17) java.net.http.HttpClient to request another restful service. Successfully compiling by maven and install_jar and set_classpath in PostgreSQL, but when executing the function, an error is thrown for 'java.lang.NoClassDefFoundError: java/net/http/HttpClient'.

Have tried to add java.net.http jmod path to pljava.module_path, but not solve it. Could anyone help?

@jcflack
Copy link
Contributor

jcflack commented May 29, 2023

I believe (without actually trying it just now) that the solution will be to include --add-modules java.net.http in pljava.vmoptions.

PL/Java does not (yet) treat your code as modular; effectively, it puts your code on the class path, not the module path. That would normally give your code the "unnamed module" behavior where dependencies don't have to be declared.

PL/Java itself, however, is modular, so there is a restricted module graph in effect before your code is loaded, and your code can only use the modules that graph includes. So --add-modules to include the modules you want in the graph should do the trick.

@jcflack
Copy link
Contributor

jcflack commented Jun 9, 2023

The existing modules documentation in PL/Java , I see, does not explain this very well. I will add to it.

jcflack added a commit that referenced this issue Jun 10, 2023
PL/Java code loaded with install_jar is treated as
unnamed-module, legacy classpath code. Such code is
advertised as having access to all readable modules,
without having to declare dependencies (as it can't
declare dependencies; it would have to be a named
module to do that).

Ah, but what are "all readable modules"? Only the ones
enumerated at JVM startup, using as root modules
PL/Java itself and anything named with --add-modules.
So that option must be used if any Java modules will
be needed beyond the ones PL/Java itself depends on.

This added documentation addresses #419.
jcflack added a commit that referenced this issue Jun 13, 2023
PR #446, #443, #442, #441, #445, #444.

Addresses issues:

Bug #416 crash with SQL_ASCII database and bad vmoptions
Doc #419 better document the use of --add-modules in vmoptions
Bug #425 install_jar from http URLs, add test to CI
Feature #426 allow functions declared on an interface as well as a class
Track PG #434 postgres/postgres@b9b21ac broke unpackaged ALTER UPDATE
Track JDK #435 check and reject Java 20 builds with JDK-8309515 bug
@jcflack
Copy link
Contributor

jcflack commented Jun 14, 2023

Resolved in 1.6.5 by adding documentation for --add-modules.

@jcflack jcflack closed this as completed Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants