public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: spellcard199 <spellcard199@protonmail.com>
To: phiroc@free.fr
Cc: kawa@sourceware.org
Subject: Re: Main class can't be loaded
Date: Tue, 07 Sep 2021 10:16:08 +0000	[thread overview]
Message-ID: <MYd_Gb-pKFcf0C6Z1W7_lmjooWlifaGFeDK3GICxr75M9RqZa4FqI8ITQaaoVz0mHKmeluD5h0YUwNiPshEe2sRRe9WmDnvOvzDQcP88D4g=@protonmail.com> (raw)
In-Reply-To: <1198267183.186506390.1631002998103.JavaMail.root@zimbra65-e11.priv.proxad.net>

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

  reply	other threads:[~2021-09-07 10:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1808942210.186489004.1631002686769.JavaMail.root@zimbra65-e11.priv.proxad.net>
2021-09-07  8:23 ` phiroc
2021-09-07 10:16   ` spellcard199 [this message]
2021-09-07 11:07     ` phiroc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='MYd_Gb-pKFcf0C6Z1W7_lmjooWlifaGFeDK3GICxr75M9RqZa4FqI8ITQaaoVz0mHKmeluD5h0YUwNiPshEe2sRRe9WmDnvOvzDQcP88D4g=@protonmail.com' \
    --to=spellcard199@protonmail.com \
    --cc=kawa@sourceware.org \
    --cc=phiroc@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).