Results 1 to 6 of 6
  1. #1
    kintaru is offline Member
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default compiling issues

    Hi everybody, well as i am posting in this forum it seems obvious that i am new to java, so if my question is silly just excuse my lack of knowledge
    well, i ve been working on some tutorials on Apache felix website, and i ve done the whole thing, every single step was fine but once my file "Activator.java" compiled i tried to run the .class version of it and here we go:

    C:\classes\tutorial\exp1>javac Activator.java

    C:\classes\tutorial\exp1>java Activator
    Exception in thread "main" java.lang.NoClassDefFoundError: Activator (wrong name
    : tutorial/exp1/Activator)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :791)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:14
    2)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:480)

    my code starts by calling the following classes:


    package tutorial.exp1;

    import org.osgi.framework.BundleActivator;
    import org.osgi.framework.BundleContext;
    import org.osgi.framework.ServiceListener;
    import org.osgi.framework.ServiceEvent;

    and as shown above my structure is: c:/classes/tutorial/exp1/
    under this root u find both the Activator.java and Activator.class since the file gets compiled smoothly with not a single prob at all, and in this same folder i have saved my manifest.mf and i ve made a jar file out of the whole stuff and started it on felix and got it detected by my nokia pc suite and everything was fine the only prob is the fact i cant run the .class file

    plz how to deal with this issue? by the way here s the result of the classic HelloWorldApp.class


    C:\classes\tutorial\exp1>cd..

    C:\classes\tutorial>cd C:\classes\tutorial\Lesson

    C:\classes\tutorial\Lesson>java HelloWorldApp
    Bitch please!!

    C:\classes\tutorial\Lesson>

    as u can see it works fine.. well the message ain t the same as the classic one though :p, so the problem has to do with that very Activator.java code i suppose!
    Last edited by kintaru; 05-14-2012 at 09:16 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default Re: compiling issues

    Time to learn about packages and paths. The code is in a package which changes the class name to include the package (as shown in the error message: wrong name: tutorial/exp1/Activator)

    To execute that class, go to the folder that contains the tutorial folder and use the full classname:
    java tutorial.exp1.Activator
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    kintaru is offline Member
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default Re: compiling issues

    Thanks alooooot, actually it returns nomore of those scary errors, still it doesnt work it says it can't find the public static void main(String[] args).
    but it s nowhere on the original code on apache website!
    /*
    * Apache Felix OSGi tutorial.
    **/

    package tutorial.example1;

    import org.osgi.framework.BundleActivator;
    import org.osgi.framework.BundleContext;
    import org.osgi.framework.ServiceListener;
    import org.osgi.framework.ServiceEvent;

    /**
    * This class implements a simple bundle that utilizes the OSGi
    * framework's event mechanism to listen for service events. Upon
    * receiving a service event, it prints out the event's details.
    **/
    public class Activator implements BundleActivator, ServiceListener
    {
    /**
    * Implements BundleActivator.start(). Prints
    * a message and adds itself to the bundle context as a service
    * listener.
    * @param context the framework context for the bundle.
    **/
    public void start(BundleContext context)
    {
    System.out.println("Starting to listen for service events.");
    context.addServiceListener(this);
    }

    /**
    * Implements BundleActivator.stop(). Prints
    * a message and removes itself from the bundle context as a
    * service listener.
    * @param context the framework context for the bundle.
    **/
    public void stop(BundleContext context)
    {
    context.removeServiceListener(this);
    System.out.println("Stopped listening for service events.");

    // Note: It is not required that we remove the listener here,
    // since the framework will do it automatically anyway.
    }

    /**
    * Implements ServiceListener.serviceChanged().
    * Prints the details of any service event from the framework.
    * @param event the fired service event.
    **/
    public void serviceChanged(ServiceEvent event)
    {
    String[] objectClass = (String[])
    event.getServiceReference().getProperty("objectCla ss");

    if (event.getType() == ServiceEvent.REGISTERED)
    {
    System.out.println(
    "Ex1: Service of type " + objectClass[0] + " registered.");
    }
    else if (event.getType() == ServiceEvent.UNREGISTERING)
    {
    System.out.println(
    "Ex1: Service of type " + objectClass[0] + " unregistered.");
    }
    else if (event.getType() == ServiceEvent.MODIFIED)
    {
    System.out.println(
    "Ex1: Service of type " + objectClass[0] + " modified.");
    }
    }
    }

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default Re: compiling issues

    If the code does not have a main() method it can not be executed directly using the java command. You need to do some more reading or research to see how to use the class.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    kintaru is offline Member
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default Re: compiling issues

    Thank u very much :)

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,405
    Rep Power
    20

Similar Threads

  1. Compiling
    By yavo in forum New To Java
    Replies: 1
    Last Post: 12-24-2011, 01:23 PM
  2. Compiling help!
    By cloverrea in forum New To Java
    Replies: 9
    Last Post: 10-12-2011, 05:05 AM
  3. About compiling
    By edh in forum Advanced Java
    Replies: 2
    Last Post: 06-16-2011, 09:47 AM
  4. dos compiling error msg.
    By gatehrdy in forum New To Java
    Replies: 22
    Last Post: 09-01-2010, 12:06 AM
  5. how to get compiling
    By philgrek in forum New To Java
    Replies: 1
    Last Post: 05-25-2010, 11:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •