You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by pyaar <um...@rediffmail.com> on 2007/12/13 14:05:22 UTC

Torque Runtime errors:-NoClassDefFoundError Exception

HI all

I am trying to execute the bookstore application which is given in
http://db.apache.org/torque/releases/torque-3.1/tutorial/step4.html 
by executing the command java com.kazmier.Bookstore from my top level
directory, but some error crops up saying "Exception in thread main:
NoClassDefFoundError:org/apache/torque/om/persistent"
As far as i know my classpath has been set properly, as when i try to
execute simple hellworld class in the same package ,it prints the output,
can somebody help me here.My Torque.properties file is as below:-

# Copyright 2001-2005 The Apache Software Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -------------------------------------------------------------------
# $Id: Torque.properties 239636 2005-08-24 12:38:09Z henning $
#
# This is the configuration file for Torque.
#
# Note that strings containing "," (comma) characters must backslash
# escape the comma (i.e. '\,')
#
# -------------------------------------------------------------------

torque.applicationRoot = .

# -------------------------------------------------------------------
#
#  L O G G I N G
#
# -------------------------------------------------------------------
# We use Log4J for all Torque logging and we embed the log4j
# properties within our application configuration.
# -------------------------------------------------------------------

# This first category is required and the category
# must be named 'default'. This is used for all logging
# where an explicit category is not specified.

log4j.category.org.apache.torque = ALL, org.apache.torque
log4j.appender.org.apache.torque = org.apache.log4j.FileAppender
log4j.appender.org.apache.torque.file =
${torque.applicationRoot}/logs/torque.log
log4j.appender.org.apache.torque.layout = org.apache.log4j.PatternLayout
log4j.appender.org.apache.torque.layout.conversionPattern = %d [%t] %-5p %c
- %m%n
log4j.appender.org.apache.torque.append = false

# -------------------------------------------------------------------
#
#  D E F A U L T S
#
# -------------------------------------------------------------------
#
# These values kick in, if you don't explicitly override them in your
# various database settings. At the moment they're only used if you
# configure the SharedPoolDataSourceFactory of the PerUserDataSourceFactory
# as your data source provider. It does not work with JNDI.
#
# The example is shown for SharedPoolDataSource.
#
# -------------------------------------------------------------------

# Time to wait for a connection to the database in milliseconds.
torque.defaults.pool.maxWait = 10000

# Maximum number of idle and active connections cached in a database
# definition.
# Note that, if you have multiple database definitions which access the
# same database URL, they don't share the connections but you have
# multiple pools and each has this maximum number. So if you have a
# connection licensed database engine, you must multiply this number by
# the number of times you use a specific database URL.
torque.defaults.pool.maxIdle = 8
torque.defaults.pool.maxActive = 10

# How often the pool is checked for connection which stayed in the pool
# for too long. Defaults to 5 minutes (5 * 60 * 1000)
# remove property if the idle object evictor should not be run
torque.defaults.pool.timeBetweenEvictionRunsMillis= 300000

# Lifetime of an idle connection in the pool in milliseconds.
# Defaults to one hour (1000 * 60 * 60)
torque.defaults.pool.minEvictableIdleTimeMillis = 3600000

# Sets the driver for the data sources.
torque.defaults.connection.driver =
com.microsoft.jdbc.sqlserver.SQLServerDriver

# Sets the URL for the datasources
torque.defaults.connection.url =
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bookstore;SelectMethod=cursor

# Sets login and password for the data sources.
torque.defaults.connection.user = user
torque.defaults.connection.password = password

# -------------------------------------------------------------------
#
#  T O R Q U E  P R O P E R T I E S
#
# -------------------------------------------------------------------
# These are your database settings. Look in the
# org.apache.torque.pool.* packages for more information.
#
# The parameters to connect to the default database.  You MUST
# configure these properly.
# -------------------------------------------------------------------

torque.database.default=bookstore
torque.database.bookstore.adapter=mssql

# # Using commons-dbcp
torque.dsfactory.bookstore.factory=org.apache.torque.dsfactory.SharedPoolDataSourceFactory
#
torque.dsfactory.bookstore.factory=org.apache.torque.dsfactory.PerUserPoolDataSourceFactory
torque.dsfactory.bookstore.pool.maxIdle=8
torque.dsfactory.bookstore.pool.maxActive=10
torque.dsfactory.bookstore.pool.testOnBorrow=true
torque.dsfactory.bookstore.pool.validationQuery=SELECT 1
torque.dsfactory.bookstore.connection.driver =
com.microsoft.jdbc.sqlserver.SQLServerDriver
torque.dsfactory.bookstore.connection.url =
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bookstore;SelectMethod=cursor
torque.dsfactory.bookstore.connection.user = user
torque.dsfactory.bookstore.connection.password = password


# # Using jndi
#
torque.dsfactory.bookstore.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
# torque.dsfactory.bookstore.jndi.path=jdbc/bookstore
# torque.dsfactory.bookstore.jndi.java.naming.factory.initial =
org.apache.naming.java.javaURLContextFactory
# torque.dsfactory.bookstore.jndi.java.naming.factory.url.pkgs =
org.apache.naming

# torque.dsfactory.bookstore.datasource.dataSourceName=jdbc/DBbookstore
#
torque.dsfactory.bookstore.datasource.jndiEnvironment.java.naming.factory.initial
= org.apache.naming.java.javaURLContextFactory
#
torque.dsfactory.bookstore.datasource.jndiEnvironment.java.naming.factory.url.pkgs
= org.apache.naming
# torque.dsfactory.bookstore.datasource.maxIdle=8
# torque.dsfactory.bookstore.datasource.maxActive=10

# # ConnectionPoolDataSource
#
torque.dsfactory.bookstore.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
# torque.dsfactory.bookstore.jndi.path=jdbc/DBbookstore
# torque.dsfactory.bookstore.jndi.java.naming.factory.initial =
org.apache.naming.java.javaURLContextFactory
# torque.dsfactory.bookstore.jndi.java.naming.factory.url.pkgs =
org.apache.naming
#
torque.dsfactory.bookstore.datasource.classname=org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS
# torque.dsfactory.bookstore.datasource.driver =
com.microsoft.jdbc.sqlserver.SQLServerDriver
# torque.dsfactory.bookstore.datasource.url =
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bookstore;SelectMethod=cursor
# torque.dsfactory.bookstore.datasource.user = user
# torque.dsfactory.bookstore.datasource.password = password

# Determines if the quantity column of the IDBroker's id_table should
# be increased automatically if requests for ids reaches a high
# volume.

torque.idbroker.clever.quantity=true

# Determines whether the managers cache instances of the business objects.
# And also whether the MethodResultCache will really cache results.

torque.manager.useCache = true
------------------------------------------------------------------------------------------------------

Bookstore.java file is as under


package com.kazmier;

import java.util.*;
import org.apache.torque.*;
import org.apache.torque.Torque;
import org.apache.torque.util.Criteria;
import org.apache.torque.om.Persistent;




public class BookStore
{
  public static void main(String[] args)
  {


    try
    {

      /*
       * Initializing Torque
       */
      Torque.init("Torque.properties");

      /*
       * Creating new objects.  These will be inserted
       * into your database automatically when the
       * save method is called.
       */
      Publisher addison = new Publisher();
      addison.setName("Addison Wesley Professional");
      addison.save();

      Author bloch = new Author();
      bloch.setFirstName("Joshua");
      bloch.setLastName("Bloch");
      bloch.save();

      /*
       * An alternative method to inserting rows
       * in your database.
       */
      Author stevens = new Author();
      stevens.setFirstName("W.");
      stevens.setLastName("Stevens");
      AuthorPeer.doInsert(stevens);

      /*
       * Using the convenience methods to handle
       * the foreign keys.
       */
      Book effective = new Book();
      effective.setTitle("Effective Java");
      effective.setISBN("0-618-12902-2");
      effective.setPublisher(addison);
      effective.setAuthor(bloch);
      effective.save();

      /*
       * Inserting the foreign-keys manually.
       */
      Book tcpip = new Book();
      tcpip.setTitle("TCP/IP Illustrated, Volume 1");
      tcpip.setISBN("0-201-63346-9");
      tcpip.setPublisherId(addison.getPublisherId());
      tcpip.setAuthorId(stevens.getAuthorId());
      tcpip.save();

      /*
       * Selecting all books from the database and
       * printing the results to stdout using our
       * helper method defined in BookPeer
       * (doSelectAll).
       */
      System.out.println("Full booklist:\n");
      List booklist = BookPeer.doSelectAll();
      printBooklist(booklist);

      /*
       * Selecting specific objects.  Just search for
       * objects that match this criteria (and print
       * to stdout).
       */
      System.out.println("Booklist (specific ISBN):\n");
      Criteria crit = new Criteria();
      crit.add(BookPeer.ISBN, "0-201-63346-9");
      booklist = BookPeer.doSelect(crit);
      printBooklist(booklist);

      /*
       * Updating data.  These lines will swap the
       * authors of the two books.  The booklist is
       * printed to stdout to verify the results.
       */
      effective.setAuthor(stevens);
      effective.save();

      tcpip.setAuthor(bloch);
      BookPeer.doUpdate(tcpip);

      System.out.println("Booklist (authors swapped):\n");
      booklist = BookPeer.doSelectAll();
      printBooklist(booklist);

      /*
       * Deleting data.  These lines will delete the
       * data that matches the specified criteria.
       */
      crit = new Criteria();
      crit.add(BookPeer.ISBN, "0-618-12902-2");
      BookPeer.doDelete(crit);

      crit = new Criteria();
      crit.add(BookPeer.ISBN, "0-201-63346-9");
      crit.add(BookPeer.TITLE, "TCP/IP Illustrated, Volume 1");
      BookPeer.doDelete(crit);

      /*
       * Deleting data by passing Data Objects instead of
       * specifying criteria.
       */
      AuthorPeer.doDelete(bloch);
      AuthorPeer.doDelete(stevens);
      PublisherPeer.doDelete(addison);

      System.out.println("Booklist (should be empty):\n");
      booklist = BookPeer.doSelectAll();
      printBooklist(booklist);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  /*
   * Helper method to print a booklist to standard out.
   */
  private static void printBooklist(List booklist)
    throws Exception
  {
    Iterator i = booklist.iterator();
    while (i.hasNext())
    {
      Book book = (Book) i.next();
      System.out.println(book);
    }
  }
}
-- 
View this message in context: http://www.nabble.com/Torque-Runtime-errors%3A-NoClassDefFoundError-Exception-tp14315608p14315608.html
Sent from the Apache DB - Torque Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: Torque Runtime errors:-NoClassDefFoundError Exception

Posted by Thomas Fischer <fi...@seitenbau.net>.
As far as I know, jars must appear explicitly in the classpath, it does not
suffice to add the directory of the jars.

>From http://db.apache.org/torque/releases/torque-3.3/tutorial/step6.html,
the following should work:

java -cp
classes:lib/avalon-framework-4.1.4.jar:lib/commons-beanutils-core-1.7.0.jar:lib/commons-collections-3.1.jar:lib/commons-configuration-1.2.jar:lib/commons-dbcp-1.2.1.jar:lib/commons-lang-2.1.jar:lib/commons-logging-1.0.4.jar:lib/commons-pool-1.2.jar:lib/jcs-20030822.182132.jar:lib/mysql-connector-java-5.0.4.jar:lib/torque-3.3-RC2.jar:lib/village-2.0.jar
 com.kazmier.Bookstore

   Thomas

pyaar <um...@rediffmail.com> schrieb am 17.12.2007 06:44:47:

>
> HI all,
> i am using mssql server 2000,torque 3.2 to execute the sample bookstore
> application given in
> http://db.apache.org/torque/releases/torque-3.1/tutorial/step4.html
>
> i have set the classpath property in the environment variable as
> CLASSPATH:-C:\Torque\torque-gen-3.2\bookstore\lib;C:\Torque\torque-gen-3.
> 2\bookstore\bin\classes;
>
> where bookstore is the application
> is there anything more to add?
>
> LIB directory contains all the jars including the runtime
> jar(torque-3.2.jar) and the dependent jars like
> commons-lang,commons-collections etc
>
> compilation is working fine for me with build successful message through
the
> command ant -f build-torque.xml compile
>
> but when i run the command java com.kazmier.Bookstore then the following
> error comes
>
> C:\Torque\torque-gen-3.2\bookstore>java com.kazmier.Bookstore
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/torque/om/
> Persistent
>         at java.lang.ClassLoader.defineClass1(Native Method)
>         at java.lang.ClassLoader.defineClass(Unknown Source)
>         at java.security.SecureClassLoader.defineClass(Unknown Source)
>         at java.net.URLClassLoader.defineClass(Unknown Source)
>         at java.net.URLClassLoader.access$100(Unknown Source)
>         at java.net.URLClassLoader$1.run(Unknown Source)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(Unknown Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
>
>
> as far as i know the torque runtime jar contains the class "
> org.apache.torque.om.Persistent" ,then why is this error.please somebody
> help
> --
> View this message in context:
http://www.nabble.com/Torque-Runtime-errors%3A-
> NoClassDefFoundError-Exception-tp14315608p14370087.html
> Sent from the Apache DB - Torque Users mailing list archive at
Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: Torque Runtime errors:-NoClassDefFoundError Exception

Posted by pyaar <um...@rediffmail.com>.
HI all,
i am using mssql server 2000,torque 3.2 to execute the sample bookstore
application given in
http://db.apache.org/torque/releases/torque-3.1/tutorial/step4.html  

i have set the classpath property in the environment variable as
CLASSPATH:-C:\Torque\torque-gen-3.2\bookstore\lib;C:\Torque\torque-gen-3.2\bookstore\bin\classes;

where bookstore is the application
is there anything more to add?

LIB directory contains all the jars including the runtime
jar(torque-3.2.jar) and the dependent jars like
commons-lang,commons-collections etc

compilation is working fine for me with build successful message through the
command ant -f build-torque.xml compile

but when i run the command java com.kazmier.Bookstore then the following
error comes

C:\Torque\torque-gen-3.2\bookstore>java com.kazmier.Bookstore
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/torque/om/
Persistent
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)


as far as i know the torque runtime jar contains the class "
org.apache.torque.om.Persistent" ,then why is this error.please somebody
help
-- 
View this message in context: http://www.nabble.com/Torque-Runtime-errors%3A-NoClassDefFoundError-Exception-tp14315608p14370087.html
Sent from the Apache DB - Torque Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Runtime errors:-NoClassDefFoundError Exception

Posted by Thomas Fischer <fi...@seitenbau.net>.
> I am trying to execute the bookstore application which is given in
> http://db.apache.org/torque/releases/torque-3.1/tutorial/step4.html
> ...
> As far as i know my classpath has been set properly

Definitely not. Make sure the Torque runtime jar and the jar it depends on
is in your classpath. This can either be achieved by using the -cp argument
to the java command or by adding it to the CLASSPATH environment variable.

    Thomas



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org