leaningtech / cheerpj-meta

Run Java 8 applications, libraries, applets, Java Web Start, and Oracle Forms on the web without legacy plugins.
https://labs.leaningtech.com/cheerpj
445 stars 21 forks source link

Classes from multiple jars #139

Closed ddyer0 closed 2 years ago

ddyer0 commented 2 years ago

This is probably a documentation issue - I can't seem to build an app that uses classes from two jars, linked only by the class names or instances. The main jar is "Lobby.jar", the secondary jar is "Game.jar" I compiled lobby.jar with --deps "Game.jar"

On the desktop, the linkage is by calling Class.forName("online.game.Game"), but I also tried using a reference to the actual class; ie result = online.Game.class;

The cheerpj version gets a java.lang.NoClassDefFoundError for both ways to find the class.

alexp-sssup commented 2 years ago

You need to compile both JARs with the other JAR as --deps. It is also safe to just pass all JARs to --deps all the time.

Make sure to pass both JARs as well to cheerpjRunMain.

This is documented here: https://docs.leaningtech.com/cheerpj/Getting-Started

ddyer0 commented 2 years ago

Looking again at the referenced document, there are two different syntaxes for --deps. One is ~/cheerpj_2.2/cheerpjfy.py --deps my_dependency_archive.jar my_application_archive.jar and the other is ~/cheerpj_2.2/cheerpjfy.py --deps one.jar:two.jar:three.jar $f

I'm using the second.

alexp-sssup commented 2 years ago

The syntax's are not different.

In the first case one 1 jar is passed as a dependency. In the second case 3 jars are, in which case they are separated by :

alexp-sssup commented 2 years ago

Please share the exact cheerpjRunMain that you are using, that is most likely the source of the mistake.

You can also consider to run without jar.js files. They are only an optimization.

ddyer0 commented 2 years ago

problem solved - I had

~/cheerpj_2.2/cheerpjfy.py name.jar --deps dep.jar instead of ~/cheerpj_2.2/cheerpjfy.py --deps deps.jar name.jar

which seemed to work and did not elicit any complaints.

ddyer0 commented 2 years ago

You can also consider to run without jar.js files. They are only an optimization.

Wow! My app consists of about 100 jar files, so skipping all the compilation (except as an optimization) will be a big plus. I just tried it and it works.

ddyer0 commented 2 years ago

This alternative of "just skip the javascript" really streamlines the workflow, and removes a lot of opportunity for operator error. I suggest you relegate it to a separate section devoted to optimization and delivery. It's just soooo much cleaner to have just the jars.