"java.lang.NoClassDefFoundError: com/rapidminer/operator/text/io/SingleDocumentIn"

murtoza
murtoza New Altair Community Member
edited November 5 in Community Q&A
Dear group members,

I am new to RM. I am trying to integrate RM in to my java program and also I integrated it. I created a NetBeans project that has only one class containing the following code. I can successfully run the project from NetBeans but unfortunately when I run it from the jar (java -jar RapidMinerText.jar) , it gives "java.lang.NoClassDefFoundError" exception  >:(

I used the execution mode EMBEDDED_WITHOUT_UI.

The code:
package rapidminertext;

import java.util.logging.Level;
import java.util.logging.Logger;

public class RapidMinerText {

   public static void main(String[] args) {


       com.rapidminer.RapidMiner.setExecutionMode(com.rapidminer.RapidMiner.ExecutionMode.EMBEDDED_WITHOUT_UI);
       System.setProperty("rapidminer.home", "/rapidminer");
       System.setProperty(com.rapidminer.RapidMiner.PROPERTY_RAPIDMINER_INIT_PLUGINS_LOCATION, "/rapidminer/lib/plugins");
       com.rapidminer.RapidMiner.init();

       try {
           com.rapidminer.Process p = new com.rapidminer.Process();
           com.rapidminer.operator.Operator doc = com.rapidminer.tools.OperatorService.createOperator(
                   com.rapidminer.operator.text.io.SingleDocumentInputOperator.class);
           doc.setParameter("text", "this is a text.");
           System.out.println("\tcreated: " + doc.getOperatorDescription());

           p.getRootOperator().getSubprocess(0).addOperator(doc);


           doc.getOutputPorts().getPortByName("output").connectTo(
                   p.getRootOperator().getSubprocess(0).getInnerSinks().getPortByName("result 1"));

           System.out.println(p.getRootOperator().createProcessTree(0));

           com.rapidminer.operator.IOContainer run = p.run();

           System.out.println(run.toString());

       } catch (Exception ex) {
           Logger.getLogger(RapidMinerText.class.getName()).log(Level.SEVERE, null, ex);
       }
   }
}

The output of the program:
2011-08-10 11:30:56 CONFIG: Locale not specified explicitly. Set default locale to US. (RapidMiner.init())
2011-08-10 11:30:56 CONFIG: Initializing I18N (RapidMiner.splashMessage())
2011-08-10 11:30:56 CONFIG: Ensuring RapidMiner Home is set (RapidMiner.splashMessage())
2011-08-10 11:30:56 INFO: rapidminer.home is '/rapidminer'. (Launcher.ensureRapidMinerHomeSet())
2011-08-10 11:30:56 CONFIG: Reading Configuration Files (RapidMiner.splashMessage())
2011-08-10 11:30:56 CONFIG: Reading configuration resource com/rapidminer/resources/rapidminerrc. (ParameterService.loadAllRCFiles())
2011-08-10 11:30:56 CONFIG: Neither system property 'rapidminer.config.dir' nor environment variable 'RAPIDMINER_CONFIG_DIR' not set. Ignored. (ParameterService.getGlobalConfigDir())
2011-08-10 11:30:56 CONFIG: Trying rcfile '/Users/murtoza/.RapidMiner5/5_1_006_rapidminerrc'...skipped (ParameterService.loadRCFile())
2011-08-10 11:30:56 CONFIG: Read rcfile '/Users/murtoza/.RapidMiner5/5_1_006_rapidminerrc.Mac OS X'. (ParameterService.loadRCFile())
2011-08-10 11:30:56 CONFIG: Trying rcfile '/RapidMinerText/rapidminerrc'...skipped (ParameterService.loadRCFile())
2011-08-10 11:30:56 CONFIG: Trying rcfile '/RapidMinerText/rapidminerrc.Mac OS X'...skipped (ParameterService.loadRCFile())
2011-08-10 11:30:56 CONFIG: Property rapidminer.rcfile not specified...skipped (ParameterService.loadAllRCFiles())
2011-08-10 11:30:56 CONFIG: Registering Plugins (RapidMiner.splashMessage())
2011-08-10 11:30:56 CONFIG: Scanning plugins in /rapidminer/lib/plugins. (Plugin.findAndRegisterPlugins())
2011-08-10 11:30:57 CONFIG: Loading renderers from 'Text Processing'. (RendererService.init())
2011-08-10 11:30:57 CONFIG: Reading parse rules from jar:file:/rapidminer/lib/plugins/rapidminer-Text%20Processing-5.1.001.jar!/com/rapidminer/resources/parserulesTextProcessing.xml (XMLImporter.importParseRules())
2011-08-10 11:30:57 CONFIG: Initializing Operators (RapidMiner.splashMessage())
2011-08-10 11:30:57 CONFIG: Loading operators from 'OperatorsCore.xml'. (OperatorService.registerOperators())
2011-08-10 11:30:57 CONFIG: Loading operator documentation from jar:file:/RapidMinerText/dist/lib/rapidminer.jar!/com/rapidminer/resources/i18n/OperatorsCoreDocumentation.xml. (OperatorDocBundle$XMLControl.newBundle())
2011-08-10 11:30:59 WARNING: Password in XML file looks like unencrypted plain text. (ParameterTypePassword.decryptPassword())
2011-08-10 11:31:00 CONFIG: Loading operators from '/rapidminer/lib/plugins/rapidminer-Text Processing-5.1.001.jar'. (OperatorService.registerOperators())
2011-08-10 11:31:00 CONFIG: Loading operator documentation from jar:file:/rapidminer/lib/plugins/rapidminer-Text%20Processing-5.1.001.jar!/com/rapidminer/resources/i18n/OperatorsDocTextProcessing.xml. (OperatorDocBundle$XMLControl.newBundle())
2011-08-10 11:31:00 CONFIG: Number of registered operator classes: 461; number of registered operator descriptions: 462; number of replacements: 433 (OperatorService.init())
2011-08-10 11:31:00 CONFIG: Loading operator usage statistics. (UsageStatistics.load())
2011-08-10 11:31:00 CONFIG: Initializing XML Transformation Rules (RapidMiner.splashMessage())
2011-08-10 11:31:00 CONFIG: Reading parse rules from jar:file:/RapidMinerText/dist/lib/rapidminer.jar!/com/rapidminer/resources/parserules.xml (XMLImporter.importParseRules())
2011-08-10 11:31:00 CONFIG: Loading JDBC Drivers (RapidMiner.splashMessage())
2011-08-10 11:31:00 CONFIG: Loading JDBC driver information from 'resource jdbc_properties.xml'. (DatabaseService.loadJDBCProperties())
2011-08-10 11:31:00 INFO: JDBC driver com.mysql.jdbc.Driver not found. Probably the driver is not installed. (JDBCProperties.registerDrivers())
2011-08-10 11:31:00 INFO: JDBC driver org.postgresql.Driver not found. Probably the driver is not installed. (JDBCProperties.registerDrivers())
2011-08-10 11:31:00 INFO: JDBC driver net.sourceforge.jtds.jdbc.Driver not found. Probably the driver is not installed. (JDBCProperties.registerDrivers())
2011-08-10 11:31:00 INFO: JDBC driver org.hsqldb.jdbcDriver not found. Probably the driver is not installed. (JDBCProperties.registerDrivers())
2011-08-10 11:31:00 WARNING: Missing database driver class name for 'ODBC Bridge (e.g. Access)' (JDBCProperties.<init>())
2011-08-10 11:31:00 INFO: JDBC driver net.sourceforge.jtds.jdbc.Driver not found. Probably the driver is not installed. (JDBCProperties.registerDrivers())
2011-08-10 11:31:00 INFO: JDBC driver com.ingres.jdbc.IngresDriver not found. Probably the driver is not installed. (JDBCProperties.registerDrivers())
2011-08-10 11:31:00 INFO: JDBC driver ca.ingres.jdbc.IngresDriver not found. Probably the driver is not installed. (JDBCProperties.registerDrivers())
2011-08-10 11:31:00 INFO: JDBC driver oracle.jdbc.driver.OracleDriver not found. Probably the driver is not installed. (JDBCProperties.registerDrivers())
2011-08-10 11:31:00 CONFIG: Neither system property 'rapidminer.config.dir' nor environment variable 'RAPIDMINER_CONFIG_DIR' not set. Ignored. (ParameterService.getGlobalConfigDir())
2011-08-10 11:31:00 CONFIG: Initializing Data Repository (RapidMiner.splashMessage())
2011-08-10 11:31:00 CONFIG: Loading repositories from /Users/murtoza/.RapidMiner5/repositories.xml (RepositoryManager.load())
2011-08-10 11:31:00 CONFIG: Adding repository IMServiceLocalRepository (RepositoryManager.addRepository())
2011-08-10 11:31:00 CONFIG: Initializing Renderers (RapidMiner.splashMessage())
2011-08-10 11:31:00 CONFIG: Loading renderers from 'file:/RapidMinerText/dist/lib/rapidminer.jar!/com/rapidminer/resources/ioobjects.xml'. (RendererService.init())
2011-08-10 11:31:00 CONFIG: Loading renderers from 'ioobjects.xml'. (RendererService.init())
2011-08-10 11:31:00 CONFIG: Initializing XML Serialization (RapidMiner.splashMessage())
Exception in thread "main" java.lang.NoClassDefFoundError: com/rapidminer/operator/text/io/SingleDocumentInputOperator
at rapidminertext.RapidMinerText.main(RapidMinerText.java:18)
Caused by: java.lang.ClassNotFoundException: com.rapidminer.operator.text.io.SingleDocumentInputOperator
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 1 more
Anyone please help me. How can I solve it.

Thanks

Answers

  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    I always put out this information when someone integrates RapidMiner into his project, just to be on the safe side, so no offense intended :) :
    Please note that to be allowed to use RapidMiner for your project, it must to be published under the same license as RapidMiner, which is the AGPL.

    Now that we have this out of the way, your problem looks like you're missing the text extension jar in your own jar file. You have to make sure it's in the folder you specified (lib/plugins) if you need the extension to run your program. You can for example build it via ant and then consult netbeans documentation to find out how to include it in your jar.

    Regards,
    Marco
  • murtoza
    murtoza New Altair Community Member
    Dear Marco,

    Many many thanks for the hint to solve the problem.
    Marco Boeck wrote:

    Now that we have this out of the way, your problem looks like you're missing the text extension jar in your own jar file. You have to make sure it's in the folder you specified (lib/plugins) if you need the extension to run your program. You can for example build it via ant and then consult netbeans documentation to find out how to include it in your jar.
    This is the first time I work on ant coz I always use NetBeans. After googled a lot, I wrote the following build.xml for the ant and it works for me. I don't know how to modify the netbeant's build.xml file as that file is very big and complex. I think if I work with RM, I need to work in ant environment.
    <project name="RapidMinerText" basedir="." default="main">
       
        <property name="src.dir"    value="src"/>

        <property name="build.dir"  value="build"/>
        <property name="classes.dir" value="${build.dir}/classes"/>
        <property name="jar.dir"    value="jar"/>

        <property name="main-class"  value="rapidminertext.RapidMinerText"/>

    <property name="lib.rapidminer.dir"    value="/rapidminer/lib"/>
    <property name="lib.rapidminer.plugins.dir"    value="/rapidminer/lib/plugins"/>


    <path id="classpath">
            <fileset dir="${lib.rapidminer.dir}" includes="**/*.jar"/>
            <fileset dir="${lib.rapidminer.plugins.dir}" includes="**/*.jar"/>
        </path>

        <target name="clean">
            <delete dir="${build.dir}"/>
        </target>

        <target name="compile">
            <mkdir dir="${classes.dir}"/>
            <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
        </target>

        <target name="jar" depends="compile">
            <mkdir dir="${jar.dir}"/>
           
            <fileset id="rm_jars" dir="${lib.rapidminer.dir}">
        <include name="*.jar" />
        </fileset>
            <path id="rm_cp"> <fileset refid="rm_jars" /> </path>
            <pathconvert property="rm_classpath" refid="rm_cp" pathsep=" " dirsep="/">
          <map from="${lib.rapidminer.dir}" to="${lib.rapidminer.dir}" />
        </pathconvert>

            <fileset id="rm_plugins_jars" dir="${lib.rapidminer.plugins.dir}">
        <include name="*.jar" />
        </fileset>
            <path id="rm_plugins_cp"> <fileset refid="rm_plugins_jars" /> </path>
            <pathconvert property="rm_plugins_classpath" refid="rm_plugins_cp" pathsep=" " dirsep="/">
          <map from="${lib.rapidminer.plugins.dir}" to="${lib.rapidminer.plugins.dir}" />
        </pathconvert>
       
            <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
                <manifest>
                    <attribute name="Main-Class" value="${main-class}"/>
                    <attribute name="Class-Path" value="${rm_plugins_classpath} ${rm_classpath}"/>
                </manifest>
            </jar>
        </target>
       

        <target name="run" depends="jar">
          <java fork="true" classname="${main-class}">
                <classpath>
                    <path refid="classpath"/>
                    <path location="${jar.dir}/${ant.project.name}.jar"/>
                </classpath>
            </java>
        </target>

        <target name="clean-build" depends="clean,jar"/>

        <target name="main" depends="clean,run"/>
    </project>
    Thank you again for your help.