public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Haley <aph@redhat.com>
To: Tushar kant <tusharkant15@gmail.com>
Cc: java@gcc.gnu.org
Subject: Re: Dynamic Class Loading in GCJ
Date: Thu, 25 Dec 2008 10:39:00 -0000	[thread overview]
Message-ID: <495362BF.3070504@redhat.com> (raw)
In-Reply-To: <32ae3bf80812241718h46f5851dp7a040d95f42c4d19@mail.gmail.com>

Tushar kant wrote:
> Hi! I'm writing an application in Java  using GCJ and would like to
> add a plug-in feature to it. I have searched the internet a lot but
> couldn't find a way to dynamically load .class\.so files dynamically.
> I would really appreciate it if someone could help me on this.

Here's a really simple example:

foo.java:

import java.net.*;

public class foo
{
  public static void main(String[] argv)
    throws Exception
  {
    ClassLoader l
      = (new URLClassLoader
	 (new URL[] {new URL("gcjlib://"
			     + System.getProperty("user.dir")
			     + "/libpop.so")}));
    Class<?> C = l.loadClass("pop");
    C.newInstance();
  }
}

pop.java:

public class pop
{
  pop()
  {
    System.out.println("Cooee!");
  }
}

 $ gcj foo.java  -o foo --main=foo
 $ gcj -findirect-dispatch -Wl,-Bsymbolic -shared pop.java -o libpop.so -fpic

 $ ./foo
Cooee!

Gcj has lots of other class loading mechanisms that you might find useful.
All this, and more, is explained in the gcj documentation.

  parent reply	other threads:[~2008-12-25 10:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-25  1:18 Tushar kant
2008-12-25  2:39 ` BGB
2008-12-25 10:39 ` Andrew Haley [this message]
     [not found] <32ae3bf80812232130q1bebdb8td3ece71a1e8ef593@mail.gmail.com>
2008-12-24 17:39 ` David Daney

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=495362BF.3070504@redhat.com \
    --to=aph@redhat.com \
    --cc=java@gcc.gnu.org \
    --cc=tusharkant15@gmail.com \
    /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).