I am trying to test in hadoop. have the code as:
System.setProperty("test.build.data","/folder");
config = new Configuration();
cluster = new MiniDFSCluster(config,1,true,null);
but in new MiniDFSCluster(config,1,true,null), it throws exception:
java.io.IOException: Cannot run program "du": CreateProcess error=2, The system cannot find the file specified.
at java.lang.ProcessBuilder.start(ProcessBuilder.java:470)
at org.apache.hadoop.util.Shell.runCommand(Shell.java:149)
at org.apache.hadoop.util.Shell.run(Shell.java:134)
at org.apache.hadoop.fs.DU.<init>(DU.java:53)
at org.apache.hadoop.fs.DU.<init>(DU.java:63)
at org.apache.hadoop.hdfs.server.datanode.FSDataset$FSVolume.<init>(FSDataset.java:333)
at org.apache.hadoop.hdfs.server.datanode.FSDataset.<init>(FSDataset.java:689)
at org.apache.hadoop.hdfs.server.datanode.DataNode.startDataNode(DataNode.java:302)
at org.apache.hadoop.hdfs.server.datanode.DataNode.<init>(DataNode.java:216)
at org.apache.hadoop.hdfs.server.datanode.DataNode.makeInstance(DataNode.java:1283)
at org.apache.hadoop.hdfs.server.datanode.DataNode.instantiateDataNode(DataNode.java:1238)
at org.apache.hadoop.hdfs.MiniDFSCluster.startDataNodes(MiniDFSCluster.java:417)
at org.apache.hadoop.hdfs.MiniDFSCluster.<init>(MiniDFSCluster.java:280)
at org.apache.hadoop.hdfs.MiniDFSCluster.<init>(MiniDFSCluster.java:124)
at ebay.Crawler.TestAll.testinit(TestAll.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:599)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified.
at java.lang.ProcessImpl.<init>(ProcessImpl.java:92)
at java.lang.ProcessImpl.start(ProcessImpl.java:41)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:463)
... 33 more
Could someone please give me some hint how to solve this?
Thank you very much.
Looks like the du command is not there on the system or is not in the PATH. If using Hadoop on Windows then Cygwin has to be installed. Anyway, which du will give the location of du binary.
I suspect you're using a Cloudera distribution of Hadoop. Version 1.0.0 of 'vanilla' Hadoop does work on Windows - at least create and writing to a file does.
If you need to run unit tests in a local Windows environment, try using Maven profile properties to set a version of 1.0.0 in you local Maven config, and in the POM specify the 'remote' config. The global setting will override the POM-specific one.
settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>windows</id>
<properties>
<hadoop.version>1.0.0</hadoop.version>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>windows</activeProfile>
</activeProfiles>
</settings>
pom.xml
<properties>
<hadoop.version>0.20.2-cdh3u2</hadoop.version>
</properties>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>${hadoop.version}</version>
</dependency>
Related
My Spring Boot Project trying connect to MYSQL database with driver mysql-connector-java.
I have import newest mysql driver and spring-boot-starter-data-jpa
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
I have configured database connection in application.properties file
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_example
spring.datasource.username=somethingfunny
spring.datasource.password=somethingfunny
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
#spring.jpa.show-sql: true
MYSQL version is 8.0.26
Spring boot version 2.6.2
When run project with Intellij I get error
Caused by: org.springframework.beans.BeanInstantiationException:
Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory
method 'dataSource' threw exception; nested exception is
java.lang.IllegalStateException: Cannot load driver class:
com.mysql.cj.jdbc.Driver at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
~[spring-beans-5.3.14.jar:5.3.14] at
org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
~[spring-beans-5.3.14.jar:5.3.14] ... 35 common frames omitted Caused
by: java.lang.IllegalStateException: Cannot load driver class:
com.mysql.cj.jdbc.Driver at
org.springframework.util.Assert.state(Assert.java:97)
~[spring-core-5.3.14.jar:5.3.14] at
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:241)
~[spring-boot-autoconfigure-2.6.2.jar:2.6.2] at
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:193)
~[spring-boot-autoconfigure-2.6.2.jar:2.6.2] at
org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:48)
~[spring-boot-autoconfigure-2.6.2.jar:2.6.2] at
org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:90)
~[spring-boot-autoconfigure-2.6.2.jar:2.6.2] at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
Method) ~[na:na] at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
~[na:na] at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:na] at
java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
~[spring-beans-5.3.14.jar:5.3.14] ... 36 common frames omitted
I have refered the post about Cannot load driver class: com.mysql.jdbc.Driver (NOT com.mysql.cj.jdbc.Driver), I cannot apply for my project because my project get error when using com.mysql.cj.jdbc.Driver but not com.mysql.jdbc.Driver.
I also refered this post Cannot load driver class: com.mysql.cj.jdbc.Driver. But i can not find correct answer(the answer is marked corrected) for this error.
How to fix this error ?
1) Use this dependency in pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
2) Use this property in your application.properties file
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
I have fix this issue. In Intellij right click to project, choose maven, choose reload project. Now Intellij will add mysql driver to the project
Going off of one of the above answers https://stackoverflow.com/a/70514438/14111809, but with a Gradle instead of Maven (in IntelliJ IDE), this fixed the issue for me:
Have you checked which version of MySQL connector do you have?
Since you haven't specified the version in your pom.xml, there is a chance that it pulled version 5 and now it is complaining about that .cj which is required for version 8.
That might be the reason why is it working without .cj ( com.mysql.jdbc.Driver ), because it pulled the version 5.
Manually add the version in your pom.xml and keep .cj as it is.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
After that make sure that you pull your dependencies.
But make sure that you check in your project if you do have ONLY version 8 after "mvn clean install".
As of the picture that you shared "mysql version", that means nothing, the exception is regarding mysql-connector jar, it has nothing to do with the workbench, you can still have workbench version 5, and use mysql-connector jar version 8, it will make no difference.
In any version of mysql workbench ( 5 or 8 ):
mysql-connector 8 jar = requires .cj
mysql-connector 5 jar = does not require .cj
The only thing that you need to do is define the version of mysql-connector-java in your pom.xml
Fix the line that sets jdbc driver class as below: I don't think it matters but driver-class-name is more common. And check if your build file is up to date. Might as well try re-building using pom.xml
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
I am using log4j 2.16 for my EJBs. Im meaning to add the log4j-core (and log4j-api if necessarily ) as module in jBoss eap 7 but I keep getting the ModuleNotFoundException exception.
here is my configurations :
src/main/ressource/META-INF/jboss-deployement-structure.xml
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.lg.log4j2"/>
</dependencies>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
pom.xml
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.16.0</version>
<scope>provided</scope>
</dependency>
jboss-eap-7.0 - 22\modules\system\layers\base\org\lg\main
<module xmlns="urn:jboss:module:1.1" name="org.lg.log4j2">
<resources>
<resource-root path="log4j-api.jar"/>
<resource-root path="log4j-core.jar"/>
</resources>
</module>
the two jar exist in the current folder.
EJBXX.jar.failed
WFLYSRV0179: Failed to load module: deployment.EJBXX.jar:main
Caused by: org.jboss.modules.ModuleNotFoundException: org.lg.log4j2:main\"}}"
I am not sure about my solution so please correct me if there is another way to achieve it.
N.B: I spot this error in my jBoss console :
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Your module is in the wrong directory. It needs to be in org/lg/log4j2/main. You’re also likely missing some module dependencies too.
I am trying to assemble a Dropwizard integration test with the following app rule:
public static final DropwizardAppRule<MyConfiguration> RULE = new DropwizardAppRule<MyConfiguration>(
MyApplication.class, ResourceHelpers.resourceFilePath("config_for_test.yml"));
When I run the test I get the following error:
java.lang.IllegalArgumentException: resource config_for_test.yml not found.
The full stack trace is:
java.lang.ExceptionInInitializerError
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1082)
at java.lang.reflect.Field.getFieldAccessor(Field.java:1063)
at java.lang.reflect.Field.get(Field.java:387)
at org.junit.runners.model.FrameworkField.get(FrameworkField.java:69)
at org.junit.runners.model.TestClass.getAnnotatedFieldValues(TestClass.java:156)
at org.junit.runners.ParentRunner.classRules(ParentRunner.java:215)
at org.junit.runners.ParentRunner.withClassRules(ParentRunner.java:203)
at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:163)
at org.junit.runners.ParentRunner.run(ParentRunner.java:308)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: resource config_for_test.yml not found.
at io.dropwizard.testing.ResourceHelpers.resourceFilePath(ResourceHelpers.java:23)
at de.emundo.sortimo.resource.TaskAdditionTest.<clinit>(TaskAdditionTest.java:28)
... 18 more
Caused by: java.lang.IllegalArgumentException: resource ../config_for_test.yml not found.
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:145)
at com.google.common.io.Resources.getResource(Resources.java:197)
at io.dropwizard.testing.ResourceHelpers.resourceFilePath(ResourceHelpers.java:21)
... 19 more
According to another stackoverflow entry I should just use the parent folder ../config_for_test.yml. However, this does not solve the problem.
Ok, I just found a solution on my own. So Dropwizard will look in ${basedir}/src/test/resources for the configuration file as this is maven's default directory to look for any files. On the other hand, when the application is run the default directory is just ${basedir}. Hence, the following approaches will help:
Just use ../../../config_for_test.yml for the integration test.
Move the config file to the ${basedir}/src/test/resources directory.
I used approach 2 and furthermore moved the according config_for_release.yml to src/main/resources in order to have a symmetric file structure. This, however, leaves the basedir directory empty when the program is run in normal mode (with the arguments server config_for_release.yml). Thus, one can adapt the argument to server src/main/resources/config_for_release.yml. Since I do not like to use such long paths on method startup I chose a different solution: I use the maven copy plugin to copy the file to the target folder:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
Å <directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.yml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
The program is then started with server target/config_for_release.yml. I use the target folder mainly so that the config file is hidden inside the according folder of Eclipse's Package Explorer and I do not accidentally open the wrong configuration file.
I am currently deploying a maven-built .war file to Elastic Beanstalk, using the 64-bit AmazonLinux Server for Tomcat 7. However, the application, which runs fine off of localhost, is not running due to the following error (Stack Trace at the bottom):
javax.naming.NamingException: com.mysql.jdbc.Driver
I am connecting to an external Xeround instance. After reading around on the web, I attempted to modify my app's context.xml to this:
<Resource auth="Container"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" //<- NOT THERE BEFORE
driverClassName="com.mysql.jdbc.Driver"
logAbandoned="true"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/xxxx-01292013"
password="xxxx"
removeAbandoned="true"
removeAbandonedTimeout="60"
type="javax.sql.DataSource"
url="jdbc:mysql://instancexxxx.db.xeround.com:xxxx/xxxx-01292013? autoReconnect=true"
username="xxxx-general"/>
Has anyone else had a problem uploading and using a previously working version to an Elastic Beanstalk Tomcat 7 app and found a way to get it working?
I have also read this post, but I don't know where to add in the .ebextensions file in a Netbeans maven project, and I don't understand what that would do. Thanks for any help.
1) Error injecting constructor, javax.persistence.PersistenceException: [PersistenceUnit:
myapp-persist] Unable to build EntityManagerFactory at
com.berger.jpa.EntityInitializer.(EntityInitializer.java:12)
while locating com.berger.jpa.EntityInitializer
for field at com.nexuscop.startup.StartupListener.entityInit(StartupListener.java:40)
while locating com.nexuscop.startup.StartupListener
1 error at
com.google.inject.internal.Errors.throwProvisionExceptionIfErrorsExist(Errors.java:451)
at
com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:65)
at
com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:944)
at
com.nexuscop.startup.StartupListener.(StartupListener.java:41)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method) at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at java.lang.Class.newInstance0(Class.java:372) at
java.lang.Class.newInstance(Class.java:325) at
org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:125)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4715)
at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at
org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1099)
at
org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1621)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679) Caused by:
javax.persistence.PersistenceException: [PersistenceUnit:
nexuscop-persist] Unable to build EntityManagerFactory at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
at
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at com.berger.jpa.JpaPersistService.start(JpaPersistService.java:83)
at com.berger.jpa.EntityInitializer.(EntityInitializer.java:14)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method) at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at
com.google.inject.internal.DefaultConstructionProxyFactory$2.newInstance(DefaultConstructionProxyFactory.java:85)
at
com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at
com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
at
com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:53)
at
com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:110)
at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:75)
at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:73)
at
com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
at
com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:73)
at
com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:60)
... 23 more Caused by: org.hibernate.HibernateException: Could not
find datasource at
org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:79)
at
org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143)
at
org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:51)
at
org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)
at
org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
at
org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)
... 42 more Caused by: javax.naming.NamingException:
com.mysql.jdbc.Driver at
org.apache.naming.NamingContext.lookup(NamingContext.java:860) at
org.apache.naming.NamingContext.lookup(NamingContext.java:154) at
org.apache.naming.NamingContext.lookup(NamingContext.java:831) at
org.apache.naming.NamingContext.lookup(NamingContext.java:154) at
org.apache.naming.NamingContext.lookup(NamingContext.java:831) at
org.apache.naming.NamingContext.lookup(NamingContext.java:154) at
org.apache.naming.NamingContext.lookup(NamingContext.java:831) at
org.apache.naming.NamingContext.lookup(NamingContext.java:168) at
org.apache.naming.SelectorContext.lookup(SelectorContext.java:158) at
javax.naming.InitialContext.lookup(InitialContext.java:409) at
org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
Many people currently seem to be having trouble getting the .ebextensions approach to work at the moment. Here is a work-around just to get up and running. I wouldn't run in production like this, but I have used it to do test/debug when I got frustrated with .ebextensions.
You can put the mysql driver directly in your WAR. If you are using Maven, just add this to the pom.xml:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
You can also add this to the META-INF/context.xml
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" factory="org.apache.commons.dbcp.BasicDataSourceFactory" type="javax.sql.DataSource"
url="jdbc:mysql://XXXXXXX
... />
And put this in the pom.xml (Otherwise the BasicDataSourceFactory isn't found):
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
I'm unable to deploy my web app with MySQL 5.5.11 backend to JBoss 5. I get this error:
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader#262b2310
I pasted my stack trace below.
Here's what I've done...
I added mysql-connector-java-5.1.14-bin.jar to {JBOSS_HOME}/lib (that connector should work with MySQL 5.5.11 right?). I also added mysql-ds.xml to {JBOSS_HOME}/server/default/deploy.
<datasources>
<local-tx-datasource>
<jndi-name>MySqlDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/my_libl_db</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>test</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
</local-tx-datasource>
</datasources>
Also, I made sure the mysql-connector-java-5.1.14-bin.jar in my lib folder is in my web apps classpath. In the JBoss Admin Console, under Resources/Datasources, I do see MySqlDS with a status of up.
My project (in Eclipse Indego Release) is an Enterprise Application Project with 1 Dynamic Web Project. The web app has has an #Entity bean and a #Stateless bean. The #Stateless is being injected to a servlet (using #EJB). Here's my persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<persistence-unit name="ContactBookPersistUnit" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/MySqlDS</jta-data-source>
<class>com.contact.model.Contact</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
What could I be doing wrong?
Caused by: javax.resource.ResourceException: Unable to get managed connection for MySqlDS
at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:441)
at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:381)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:496)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:941)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:89)
... 65 more
Caused by: org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Failed to register driver for: com.mysql.jdbc.Driver; - nested throwable: (java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader#262b2310{VFSClassLoaderPolicy#5a0b0303{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ domain=ClassLoaderDomain#5e33f929{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=BaseClassLoader#7cdd93a5{vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/}} roots=[ZipEntryHandler#150136868[path=ContactBook.ear/ContactBookWeb.war/WEB-INF/classes context=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ real=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/WEB-INF/classes]] delegates=null exported=[, com.contact.servlet, com.contact.service, com.contact.model, com.contact.control, META-INF] <IMPORT-ALL>NON_EMPTY}}))
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:225)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:195)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:633)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:267)
at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:622)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:404)
... 69 more
Caused by: org.jboss.resource.JBossResourceException: Failed to register driver for: com.mysql.jdbc.Driver; - nested throwable: (java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader#262b2310{VFSClassLoaderPolicy#5a0b0303{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ domain=ClassLoaderDomain#5e33f929{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=BaseClassLoader#7cdd93a5{vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/}} roots=[ZipEntryHandler#150136868[path=ContactBook.ear/ContactBookWeb.war/WEB-INF/classes context=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ real=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/WEB-INF/classes]] delegates=null exported=[, com.contact.servlet, com.contact.service, com.contact.model, com.contact.control, META-INF] <IMPORT-ALL>NON_EMPTY}})
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectionFactory.java:489)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:206)
... 74 more
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader#262b2310{VFSClassLoaderPolicy#5a0b0303{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ domain=ClassLoaderDomain#5e33f929{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=BaseClassLoader#7cdd93a5{vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/}} roots=[ZipEntryHandler#150136868[path=ContactBook.ear/ContactBookWeb.war/WEB-INF/classes context=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ real=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/WEB-INF/classes]] delegates=null exported=[, com.contact.servlet, com.contact.service, com.contact.model, com.contact.control, META-INF] <IMPORT-ALL>NON_EMPTY}}
at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:448)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectionFactory.java:474)
This bit of documentation says you need to add the JAR to the /lib file in your default server configuration:
http://docs.jboss.org/jbossas/getting_started/v4/html/db.html
UPDATE: JBOSS 6 and newer has been rewritten to be more modular. You have to add JBDC drivers to your /module directory.