how to load a class from an installed package in java code

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how to load a class from an installed package in java code

Ignacio Arganda-Carreras-2
Dear all,

I have installed the ClassificationViaClustering classifier using the package manager on my Weka 3.9.1 and now I would like to instantiate it from java code. So far I have not been successful and I can only load the classifier classes that come by default in the weka jar.

This is what I tried:

import weka.core.WekaPackageManager;

WekaPackageManager.loadPackages( true );


Which outputs:

WARNING: core mtj jar files are not available as resources to this classloader (sun.misc.Launcher$AppClassLoader@764c12b6)
[WekaPackageManager] loading package collective-classification
[WekaPackageManager] loading package classificationViaClustering
Registering weka.classifiers.collective.util.Flipper weka.gui.GenericObjectEditor
Refreshing GOE props...


So the package seems to be loaded, but then, when I try to instantiate it, I get a "class not found error":

ClassificationViaClustering classifier = new ClassificationViaClustering();

What am I missing?

Thanks a lot in advance!

ignacio


--
Ignacio Arganda-Carreras, Ph.D.
Ikerbasque Research Fellow
Departamento de Ciencia de la Computacion e Inteligencia Artificial 
Facultad de Informatica, Universidad del Pais Vasco 
Paseo de Manuel Lardizabal, 1 
20018 Donostia-San Sebastian 
Guipuzcoa, Spain

Phone : +34 943 01 73 25
Website: http://sites.google.com/site/iargandacarreras/

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: how to load a class from an installed package in java code

Mark Hall
To get rid of the mtj warnings you will need the weka.jar file in your CLASSPATH. In order to instantiate learning schemes from packages, if you are using the package manager to load them, you will need to remove explicit imports of the scheme in question from your code, use the generic Classifier interface, and then create an object via the static WekaPackageClassLoaderManager.objectForName() method.

Alternatively, if you don't require lots of Weka packages in your application and, as a consequence, third-party library clashes won't be a problem, you can place the ClassificationViaClustering package's jar files into your CLASSPATH explicitly (rather than loading via the package manager). Then you can use explicit imports and normal object instantiation.

Cheers,
Mark.

On 13/06/17, 6:14 AM, "Ignacio Arganda-Carreras" <[hidden email] on behalf of [hidden email]> wrote:

    Dear all,
   
   
    I have installed the ClassificationViaClustering classifier using the package manager on my Weka 3.9.1 and now I would like to instantiate it from java code. So far I have not been successful and I can only load the classifier classes that come by default in the weka jar.
   
   
    This is what I tried:
   
    import weka.core.WekaPackageManager;
   
    WekaPackageManager.loadPackages( true );
   
   
    Which outputs:
   
    WARNING: core mtj jar files are not available as resources to this classloader (sun.misc.Launcher$AppClassLoader@764c12b6)
    [WekaPackageManager] loading package collective-classification
    [WekaPackageManager] loading package classificationViaClustering
    Registering weka.classifiers.collective.util.Flipper weka.gui.GenericObjectEditor
    Refreshing GOE props...
   
    So the package seems to be loaded, but then, when I try to instantiate it, I get a "class not found error":
   
    ClassificationViaClustering classifier = new ClassificationViaClustering();
   
   
    What am I missing?
   
   
    Thanks a lot in advance!
   
   
    ignacio
   
   
   
    --
    Ignacio Arganda-Carreras, Ph.D.
    Ikerbasque Research Fellow
    Departamento de Ciencia de la Computacion e Inteligencia Artificial
    Facultad de Informatica, Universidad del Pais Vasco
    Paseo de Manuel Lardizabal, 1
    20018 Donostia-San Sebastian
    Guipuzcoa, Spain
   
    Phone : +34 943 01 73 25
    Website: http://sites.google.com/site/iargandacarreras/ <http://biocomp.cnb.csic.es/%7Eiarganda/index_EN.html>
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    _______________________________________________
    Wekalist mailing list
    Send posts to: [hidden email]
    List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
    List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
   


_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: how to load a class from an installed package in java code

Ignacio Arganda-Carreras-2
Hello Mark,

It worked like a charm. Thank you very much!



On Tue, Jun 13, 2017 at 4:02 PM, Mark Hall <[hidden email]> wrote:
To get rid of the mtj warnings you will need the weka.jar file in your CLASSPATH. In order to instantiate learning schemes from packages, if you are using the package manager to load them, you will need to remove explicit imports of the scheme in question from your code, use the generic Classifier interface, and then create an object via the static WekaPackageClassLoaderManager.objectForName() method.

Alternatively, if you don't require lots of Weka packages in your application and, as a consequence, third-party library clashes won't be a problem, you can place the ClassificationViaClustering package's jar files into your CLASSPATH explicitly (rather than loading via the package manager). Then you can use explicit imports and normal object instantiation.

Cheers,
Mark.

On 13/06/17, 6:14 AM, "Ignacio Arganda-Carreras" <[hidden email] on behalf of [hidden email]> wrote:

    Dear all,


    I have installed the ClassificationViaClustering classifier using the package manager on my Weka 3.9.1 and now I would like to instantiate it from java code. So far I have not been successful and I can only load the classifier classes that come by default in the weka jar.


    This is what I tried:

    import weka.core.WekaPackageManager;

    WekaPackageManager.loadPackages( true );


    Which outputs:

    WARNING: core mtj jar files are not available as resources to this classloader (sun.misc.Launcher$AppClassLoader@764c12b6)
    [WekaPackageManager] loading package collective-classification
    [WekaPackageManager] loading package classificationViaClustering
    Registering weka.classifiers.collective.util.Flipper weka.gui.GenericObjectEditor
    Refreshing GOE props...

    So the package seems to be loaded, but then, when I try to instantiate it, I get a "class not found error":

    ClassificationViaClustering classifier = new ClassificationViaClustering();


    What am I missing?


    Thanks a lot in advance!


    ignacio



    --
    Ignacio Arganda-Carreras, Ph.D.
    Ikerbasque Research Fellow
    Departamento de Ciencia de la Computacion e Inteligencia Artificial
    Facultad de Informatica, Universidad del Pais Vasco
    Paseo de Manuel Lardizabal, 1
    20018 Donostia-San Sebastian
    Guipuzcoa, Spain

    Phone : <a href="tel:%2B34%20943%2001%2073%2025" value="+34943017325">+34 943 01 73 25
    Website: http://sites.google.com/site/iargandacarreras/ <http://biocomp.cnb.csic.es/%7Eiarganda/index_EN.html>














    _______________________________________________
    Wekalist mailing list
    Send posts to: [hidden email]
    List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
    List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html



_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html



--
Ignacio Arganda-Carreras, Ph.D.
Ikerbasque Research Fellow
Departamento de Ciencia de la Computacion e Inteligencia Artificial 
Facultad de Informatica, Universidad del Pais Vasco 
Paseo de Manuel Lardizabal, 1 
20018 Donostia-San Sebastian 
Guipuzcoa, Spain

Phone : +34 943 01 73 25
Website: http://sites.google.com/site/iargandacarreras/

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html