* Main class can't be loaded
[not found] <1808942210.186489004.1631002686769.JavaMail.root@zimbra65-e11.priv.proxad.net>
@ 2021-09-07 8:23 ` phiroc
2021-09-07 10:16 ` spellcard199
0 siblings, 1 reply; 3+ messages in thread
From: phiroc @ 2021-09-07 8:23 UTC (permalink / raw)
To: kawa
Hello,
Let's say a file called mod1.scm contains the following definition:
(define (fun1 x y)
(list x y))
...and has been compiled to a Java class, thus:
kawa -C mod1.scm
Why does the following message appear when you run the class?
"the main class can't be loaded"
java -cp . mod1
Many thanks.
Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Main class can't be loaded
2021-09-07 8:23 ` Main class can't be loaded phiroc
@ 2021-09-07 10:16 ` spellcard199
2021-09-07 11:07 ` phiroc
0 siblings, 1 reply; 3+ messages in thread
From: spellcard199 @ 2021-09-07 10:16 UTC (permalink / raw)
To: phiroc; +Cc: kawa
Hello. First of all the java classpath needs both:
- kawa.jar
- your classes' directory
So the java command becomes:
java -cp "/path/to/kawa.jar:." mod1
If you try to run the above command it should give another error:
Error: Main method not found in class mod1, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
To solve this recompile using the --main flag
(https://www.gnu.org/software/kawa/Compiling.html):
kawa --main -C mod1.scm
Now it should work.
P.S. Why we need kawa.jar in classpath:
On my OS the full error was:
Error: Could not find or load main class mod1
Caused by: java.lang.NoClassDefFoundError: gnu/expr/RunnableModule
gnu.expr.RunnableModule is a class in the Kawa codebase.
The output of javap on mod1.class is:
public class mod1 extends gnu.expr.ModuleBody implements java.lang.Runnable,gnu.expr.RunnableModule {
public static mod1 $instance;
public final void run(gnu.mapping.CallContext);
public static {};
public mod1();
public static void main(java.lang.String[]);
}
You can see that this java code depends on several classes defined in Kawa:
- gnu.expr.ModuleBody
- gnu.expr.RunnableModule
- gnu.mapping.CallContext
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Tuesday, September 7th, 2021 at 10:23 AM, phiroc--- via Kawa <kawa@sourceware.org> wrote:
> Hello,
>
> Let's say a file called mod1.scm contains the following definition:
>
> (define (fun1 x y)
>
> (list x y))
>
> ...and has been compiled to a Java class, thus:
>
> kawa -C mod1.scm
>
> Why does the following message appear when you run the class?
>
> "the main class can't be loaded"
>
> java -cp . mod1
>
> Many thanks.
>
> Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Main class can't be loaded
2021-09-07 10:16 ` spellcard199
@ 2021-09-07 11:07 ` phiroc
0 siblings, 0 replies; 3+ messages in thread
From: phiroc @ 2021-09-07 11:07 UTC (permalink / raw)
To: spellcard199; +Cc: kawa
Very thorough explanation, spellcard199. Many thanks.
Philippe
----- Mail original -----
De: "spellcard199" <spellcard199@protonmail.com>
À: phiroc@free.fr
Cc: kawa@sourceware.org
Envoyé: Mardi 7 Septembre 2021 12:16:08
Objet: Re: Main class can't be loaded
Hello. First of all the java classpath needs both:
- kawa.jar
- your classes' directory
So the java command becomes:
java -cp "/path/to/kawa.jar:." mod1
If you try to run the above command it should give another error:
Error: Main method not found in class mod1, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
To solve this recompile using the --main flag
(https://www.gnu.org/software/kawa/Compiling.html):
kawa --main -C mod1.scm
Now it should work.
P.S. Why we need kawa.jar in classpath:
On my OS the full error was:
Error: Could not find or load main class mod1
Caused by: java.lang.NoClassDefFoundError: gnu/expr/RunnableModule
gnu.expr.RunnableModule is a class in the Kawa codebase.
The output of javap on mod1.class is:
public class mod1 extends gnu.expr.ModuleBody implements java.lang.Runnable,gnu.expr.RunnableModule {
public static mod1 $instance;
public final void run(gnu.mapping.CallContext);
public static {};
public mod1();
public static void main(java.lang.String[]);
}
You can see that this java code depends on several classes defined in Kawa:
- gnu.expr.ModuleBody
- gnu.expr.RunnableModule
- gnu.mapping.CallContext
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Tuesday, September 7th, 2021 at 10:23 AM, phiroc--- via Kawa <kawa@sourceware.org> wrote:
> Hello,
>
> Let's say a file called mod1.scm contains the following definition:
>
> (define (fun1 x y)
>
> (list x y))
>
> ...and has been compiled to a Java class, thus:
>
> kawa -C mod1.scm
>
> Why does the following message appear when you run the class?
>
> "the main class can't be loaded"
>
> java -cp . mod1
>
> Many thanks.
>
> Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-07 11:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1808942210.186489004.1631002686769.JavaMail.root@zimbra65-e11.priv.proxad.net>
2021-09-07 8:23 ` Main class can't be loaded phiroc
2021-09-07 10:16 ` spellcard199
2021-09-07 11:07 ` phiroc
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).