Re: Loading cayenne mapped class from URLClassLoader

From: rigel (zetata..mail.com)
Date: Mon Nov 24 2008 - 18:24:11 EST

  • Next message: rigel: "RE: Loading cayenne mapped class from URLClassLoader"

    Michael Gentry wrote:
    >
    > PlainTextPasswordEncoder ... Is this class somehow not in your JAR?
    >

    No, it's present under the jar named cayenne-server-3.0M4.jar.

    It follows the stacktrace produced when I load the JDBC driver too into the
    URLClassLoader.
    As you can notice the ClassNotFound arise from driverClass =
    Class.forName(driverClassName,
    true,Thread.currentThread().getContextClassLoader()); into
    "DriverDataSource.java:62".

    Also PlainTextPasswordEncoder use the same call to retrieve its
    ClassLoader, but just yesterday I noticed that URLClassLoader inherit from
    ClassLoader and not vice versa, probably for security reason. For this
    reason when I call "ClassLoader.getSystemClassLoader()" or
    "Thread.currentThread().getContextClassLoader()" I get only the clean
    classpath at startup, as direct consequence every JAR appears isolated from
    others when using standard ClassLoader invokation.

    So when using URLClassLoader the only way I found to turn around this
    problem is to put a call of Class.forName(className) without specifying any
    ClassLoader directly into the first catch of the main try for
    Class.forName(String,boolean,ClassLoader) call. As note with Cayenne 2 this
    supplementary call into the catch works well without any interference.

    JDBC driver loaded via URLClassLoader

    Loading lib:
    http://localhost:80/users/antares/libs/postgresql-8.2-504.jdbc4.jar
    Loading lib: http://localhost:80/users/antares/libs/ashwood-2.0.jar
    Loading lib: http://localhost:80/users/antares/libs/asm-3.0.jar
    Loading lib: http://localhost:80/users/antares/libs/asm-commons-3.0.jar
    Loading lib:
    http://localhost:80/users/antares/libs/commons-collections-3.1.jar
    Loading lib: http://localhost:80/users/antares/libs/commons-logging-1.1.jar
    Loading lib:
    http://localhost:80/users/antares/libs/geronimo-jpa_3.0_spec-1.0.jar
    Loading lib: http://localhost:80/users/antares/libs/velocity-1.3.jar
    Loading lib: http://localhost:80/users/antares/libs/cayenne-agent-3.0M4.jar
    Loading lib: http://localhost:80/users/antares/libs/cayenne-client-3.0M4.jar
    Loading lib:
    http://localhost:80/users/antares/libs/cayenne-modeler-3.0M4.jar
    Loading lib: http://localhost:80/users/antares/libs/cayenne-server-3.0M4.jar
    Loading lib: http://localhost:80/users/antares/libs/w3d-base.jar
    Loading lib: http://localhost:80/users/antares/libs/w3d-orm.jar
    24-nov-2008 23.48.02 org.apache.cayenne.conf.RuntimeLoadDelegate
    startedLoading
    INFO: started configuration loading.
    24-nov-2008 23.48.02 org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataDomain
    INFO: loaded domain: dbw3d
    24-nov-2008 23.48.02 org.apache.cayenne.conf.RuntimeLoadDelegate loadDataMap
    INFO: loaded .
    24-nov-2008 23.48.02 org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataNode
    INFO: loading .
    24-nov-2008 23.48.02 org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataNode
    INFO: using factory: org.apache.cayenne.conf.DriverDataSourceFactory
    24-nov-2008 23.48.02 org.apache.cayenne.conf.DriverDataSourceFactory load
    INFO: loading driver information from 'dbw3dNode.driver.xml'.
    24-nov-2008 23.48.02
    org.apache.cayenne.conf.DriverDataSourceFactory$DriverHandler init
    INFO: loading driver org.postgresql.Driver
    24-nov-2008 23.48.02
    org.apache.cayenne.conf.DriverDataSourceFactory$LoginHandler init
    INFO: loading user name and password.
    java.lang.ClassNotFoundException:
    org.apache.cayenne.conf.PlainTextPasswordEncoder
            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
    org.apache.cayenne.conn.DataSourceInfo.getPasswordEncoder(DataSourceInfo.java:207)
            at
    org.apache.cayenne.conf.DriverDataSourceFactory$LoginHandler.init(DriverDataSourceFactory.java:324)
            at
    org.apache.cayenne.conf.DriverDataSourceFactory$DriverHandler.startElement(DriverDataSourceFactory.java:191)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
    Source)
            at
    org.apache.cayenne.conf.DriverDataSourceFactory.load(DriverDataSourceFactory.java:130)
            at
    org.apache.cayenne.conf.DriverDataSourceFactory.getDataSource(DriverDataSourceFactory.java:78)
            at
    org.apache.cayenne.conf.RuntimeLoadDelegate.shouldLoadDataNode(RuntimeLoadDelegate.java:299)
            at
    org.apache.cayenne.conf.ConfigLoader$NodeHandler.init(ConfigLoader.java:337)
            at
    org.apache.cayenne.conf.ConfigLoader$DomainHandler.startElement(ConfigLoader.java:223)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
    Source)
            at org.apache.cayenne.conf.ConfigLoader.loadDomains(ConfigLoader.java:79)
            at
    org.apache.cayenne.conf.DefaultConfiguration.initialize(DefaultConfiguration.java:164)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:157)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:139)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:119)
            at
    org.apache.cayenne.conf.Configuration.getSharedConfiguration(Configuration.java:89)
            at
    org.apache.cayenne.access.DataContext.createDataContext(DataContext.java:162)
            at it.wipidea.w3d.SomeClass.init(SomeClass.java:42)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at NetLoader.start(NetLoader.java:63)
            at NetLoader.main(NetLoader.java:74)
    24-nov-2008 23.48.02 org.apache.cayenne.access.QueryLogger logPoolCreated
    INFO: Created connection pool: jdbc:postgresql://localhost/w3d
            Driver class: org.postgresql.Driver
            Min. connections in the pool: 1
            Max. connections in the pool: 1
    24-nov-2008 23.48.02 org.apache.cayenne.access.QueryLogger logConnectFailure
    INFO: *** Connecting: FAILURE.
    java.sql.SQLException: Can not load JDBC driver named
    'org.postgresql.Driver': org.postgresql.Driver
            at
    org.apache.cayenne.conn.DriverDataSource.loadDriver(DriverDataSource.java:62)
            at
    org.apache.cayenne.conn.DriverDataSource.setDriverClassName(DriverDataSource.java:256)
            at org.apache.cayenne.conn.DriverDataSource.(DriverDataSource.java:101)
            at org.apache.cayenne.conn.DriverDataSource.(DriverDataSource.java:87)
            at org.apache.cayenne.conn.PoolManager.(PoolManager.java:106)
            at
    org.apache.cayenne.conf.DriverDataSourceFactory.getDataSource(DriverDataSourceFactory.java:83)
            at
    org.apache.cayenne.conf.RuntimeLoadDelegate.shouldLoadDataNode(RuntimeLoadDelegate.java:299)
            at
    org.apache.cayenne.conf.ConfigLoader$NodeHandler.init(ConfigLoader.java:337)
            at
    org.apache.cayenne.conf.ConfigLoader$DomainHandler.startElement(ConfigLoader.java:223)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
    Source)
            at org.apache.cayenne.conf.ConfigLoader.loadDomains(ConfigLoader.java:79)
            at
    org.apache.cayenne.conf.DefaultConfiguration.initialize(DefaultConfiguration.java:164)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:157)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:139)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:119)
            at
    org.apache.cayenne.conf.Configuration.getSharedConfiguration(Configuration.java:89)
            at
    org.apache.cayenne.access.DataContext.createDataContext(DataContext.java:162)
            at it.wipidea.w3d.SomeClass.init(SomeClass.java:42)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at NetLoader.start(NetLoader.java:63)
            at NetLoader.main(NetLoader.java:74)
    24-nov-2008 23.48.02 org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataNode
    INFO: Error: DataSource load failed
    java.sql.SQLException: Can not load JDBC driver named
    'org.postgresql.Driver': org.postgresql.Driver
            at
    org.apache.cayenne.conn.DriverDataSource.loadDriver(DriverDataSource.java:62)
            at
    org.apache.cayenne.conn.DriverDataSource.setDriverClassName(DriverDataSource.java:256)
            at org.apache.cayenne.conn.DriverDataSource.(DriverDataSource.java:101)
            at org.apache.cayenne.conn.DriverDataSource.(DriverDataSource.java:87)
            at org.apache.cayenne.conn.PoolManager.(PoolManager.java:106)
            at
    org.apache.cayenne.conf.DriverDataSourceFactory.getDataSource(DriverDataSourceFactory.java:83)
            at
    org.apache.cayenne.conf.RuntimeLoadDelegate.shouldLoadDataNode(RuntimeLoadDelegate.java:299)
            at
    org.apache.cayenne.conf.ConfigLoader$NodeHandler.init(ConfigLoader.java:337)
            at
    org.apache.cayenne.conf.ConfigLoader$DomainHandler.startElement(ConfigLoader.java:223)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
    Source)
            at org.apache.cayenne.conf.ConfigLoader.loadDomains(ConfigLoader.java:79)
            at
    org.apache.cayenne.conf.DefaultConfiguration.initialize(DefaultConfiguration.java:164)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:157)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:139)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:119)
            at
    org.apache.cayenne.conf.Configuration.getSharedConfiguration(Configuration.java:89)
            at
    org.apache.cayenne.access.DataContext.createDataContext(DataContext.java:162)
            at it.wipidea.w3d.SomeClass.init(SomeClass.java:42)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at NetLoader.start(NetLoader.java:63)
            at NetLoader.main(NetLoader.java:74)
    24-nov-2008 23.48.02 org.apache.cayenne.conf.RuntimeLoadDelegate initAdapter
    INFO: no adapter set, using automatic adapter.
    24-nov-2008 23.48.02 org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLinkDataMap
    INFO: loaded map-ref: dbw3dMap.
    java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at NetLoader.start(NetLoader.java:63)
            at NetLoader.main(NetLoader.java:74)
    Caused by: org.apache.cayenne.ConfigurationException: [v.3.0M4 May 18 2008
    15:29:33] Error during Configuration initialization. [v.3.0M4 May 18 2008
    15:29:33] Load failures. Main configuration class:
    org.apache.cayenne.conf.DefaultConfiguration, details:
            domain.node.name=dbw3dNode, domain.node.datasource=dbw3dNode.driver.xml,
    reason: DataSource load failed - Can not load JDBC driver named
    'org.postgresql.Driver': org.postgresql.Driver
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:166)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:139)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:119)
            at
    org.apache.cayenne.conf.Configuration.getSharedConfiguration(Configuration.java:89)
            at
    org.apache.cayenne.access.DataContext.createDataContext(DataContext.java:162)
            at it.wipidea.w3d.SomeClass.init(SomeClass.java:42)
            ... 6 more
    Caused by: org.apache.cayenne.ConfigurationException: [v.3.0M4 May 18 2008
    15:29:33] Load failures. Main configuration class:
    org.apache.cayenne.conf.DefaultConfiguration, details:
            domain.node.name=dbw3dNode, domain.node.datasource=dbw3dNode.driver.xml,
    reason: DataSource load failed - Can not load JDBC driver named
    'org.postgresql.Driver': org.postgresql.Driver
            at
    org.apache.cayenne.conf.RuntimeLoadDelegate.finishedLoading(RuntimeLoadDelegate.java:454)
            at org.apache.cayenne.conf.ConfigLoader.loadDomains(ConfigLoader.java:80)
            at
    org.apache.cayenne.conf.DefaultConfiguration.initialize(DefaultConfiguration.java:164)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:157)
            ... 11 more

    Michael Gentry wrote:
    >
    > From your stack trace:
    >
    > INFO: loading user name and password.
    > java.lang.ClassNotFoundException:
    > org.apache.cayenne.conf.PlainTextPasswordEncoder
    > 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
    > org.apache.cayenne.conn.DataSourceInfo.getPasswordEncoder(DataSourceInfo.java:207)
    >
    >
    > It appears that it can't find the PlainTextPasswordEncoder class,
    > which should be present. It is the default encoder. Is this class
    > somehow not in your JAR?
    >
    > Thanks!
    >
    > /dev/mrg
    >
    >

    -- 
    View this message in context: http://www.nabble.com/Loading-cayenne-mapped-class-from-URLClassLoader-tp20654024p20672220.html
    Sent from the Cayenne - User mailing list archive at Nabble.com.
    



    This archive was generated by hypermail 2.0.0 : Mon Nov 24 2008 - 18:24:44 EST