I am using JBoss AS 7.1.1.Final as my application server.
I have posted my question on the JBoss Community user forum: question-here
Reproduced below:
Installed AS 7.1.1.Final on my MacBook Pro.
Downloaded the Quickstart examples. Was able to successfully deploy and test helloworld, jboss-as-greeter wars.
Then i set up the postgresql database engine to try jboss-as-cmt example. I was able to compile and deploy it.
Everything works great except for one thing - i am unable to connect to the postgresql database from the h2console web-app that is shipped with the application server.
The jboss-as-cmt war works perfectly i.e i am able to add customers to the invoice. I can psql into the db engine and i can see all the records. My only problem is that i can't use h2console webapp to get into my jboss-as-cmt postgres database i created.
I am using:
"org.postgresql.Driver" for the Driver Class field.
"jdbc:postgresql://127.0.0.1:5432/jboss-as-cmt" for the JDBC URL. This is the same as my connection-url value set in the standalone-full.xml config file.
"sa" for username and password.
When i press the "Test Connection" button on the h2console app, unfortunately i see -
Class "org.postgresql.Driver" not found [90086-161]
org.h2.message.DbException: Class "org.postgresql.Driver" not found [90086-161]
at org.h2.message.DbException.get(DbException.java:158)
at org.h2.util.Utils.loadUserClass(Utils.java:429)
at org.h2.util.JdbcUtils.getConnection(JdbcUtils.java:146)
at org.h2.server.web.WebServer.getConnection(WebServer.java:653)
at org.h2.server.web.WebApp.test(WebApp.java:839)
at org.h2.server.web.WebApp.process(WebApp.java:215)
at org.h2.server.web.WebApp.processRequest(WebApp.java:164)
at org.h2.server.web.WebServlet.doGet(WebServlet.java:118)
at org.h2.server.web.WebServlet.doPost(WebServlet.java:153)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
at java.lang.Thread.run(Thread.java:680)
Caused by: org.h2.jdbc.JdbcSQLException: Class "org.postgresql.Driver" not found [90086-161]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
... 24 more
Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver from [Module "com.h2database.h2:main" from local module loader #b4e29b (roots: /Users/avyayatek/Downloads/jboss-as-7.1.1.Final/modules)]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.h2.util.Utils.loadUserClass(Utils.java:424)
... 22 more
I am able to establish a successful connection from the jboss admin management console (http://localhost:9990/console) to the datasource. On the datasources profile panel, i have the name of the datasource set to "postgresDS", jndi set to "java:jboss/postgresDS". Connection URL is same as what i am use on the h2console - "jdbc:postgresql://127.0.0.1:5432/jboss-as-cmt"
I don't know why h2console is not connecting to the postgresql db engine. It makes a successful connection to the h2 in-memory database that is used in the jboss-as-greeter example.
I have placed the JDBC driver in the $JBOSS_HOME/modules/org/postgresql/main folder. Created the module.xml there. There is a Driver.class file inside the jar in ~/org/postgresql/ folder. I have modified the $JBOSS_HOME/standalone/configuration/standalone-full.xml to add the postgresql related datasource and driver sections.
As i said, i can build jboss-as-cmt and deploy and it works as expected. If i could make the h2console connect to this postgresql database, it will give me some peace.
I am a newbie to JBoss and server side stuff in general.
I have attached some pics for reference.
Thanks for your time.
Any thoughts is highly appreciated. Thanks for your insights and time.
Firstly, thanks to #ThomasMueller whose comment encouraged me to dig further and arriving at a functional solution. And also thanks to Wolf-Dieter on JBoss Community page for pointing me in the right direction. So, my sincere suggestion to #MarkRotteveel is that it does not hurt to have postings at credible forums and when we find a solution, everyone benefits.
This is what worked for me:
Thanks for the link to the source, i created the h2console from the source and this time, i placed the postgres JDBC driver jar file in the WEB-INF/lib folder. Now, i am able to use the h2console to connect to postgresql database.
The h2console app that ships with the quickstart does not have any library jars in the WEB-INF/lib folder. Instead it specifies the dependencies in the META-INF/MANIFEST.mf file. I am positive both the h2 and postgres drivers are loaded while the JBoss starts - i can see the logs. But for some reason, this app only recognizes the h2 driver and fails to recognize the postgres driver. Looking at the source file, i am fairly positive that there is no "hardcoding" anywhere in there. So, it's still a mystery to me.
An alternative to h2console tool - SQUirrel.
Thanks All. Hope this helps someone - not just limited to SO.
A driver can register itself as a handler for multiple JDBC protocols. It might have changed but at one point H2 would register itself as a handler for jdbc:postgresql - not entirely unreasonable since H2 can be run in PostgreSQL emulation mode. You would be fine if you used the DriverManager directly (since it only requires the url) but have problems if you used a connection manager (which wants a driver classpath) since the driver is NOT org.postgresql.Driver.
This also caused problems if you had both h2 and postgresql drivers in your classpath. I don't remember if it's "first one registered" or "last one registered" but which driver you got from the DriverManager would depend on the order the jars were loaded. It caused a lot of grief and one reason I got into the habit of always defining a DataSource that explicitly named the classpath to use. It's a bit of overkill with a one-off app that only needs a single connection but it eliminates the ambiguity.
As for the particular problem I just add the jars to the java classpath. I have a small bash shell script that puts about a dozen jars onto the classpath and it allows me to connect to large number of databases without a problem. It avoids the need to rebuild the h2 jar every time I need to update one of the drivers.
Related
I've installed Talend ESB 6.5.1 and am trying to connect to a SQL Server database.
I tried using the JTDS driver, but that didn't work, and it appeared that I needed a DLL that wasn't included in the , and do I installed the pure java MS driver instead.
Talend has put the MS driver into Studio\workspace\xxx\temp\dbWizard having renamed it, but when I try to use it I get
Database connection is failed.
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at org.talend.core.model.metadata.builder.database.JDBCDriverLoader.getConnection(JDBCDriverLoader.java:195)
...
It looks like Talend has put the jdbc driver somewhere, but it not referencing it correctly.
Any ideas what I need to do to get Talend to find it? (I've looked inside the .jar file and the class is definitely there.)
(Taking the generated JDBC URL and using this directly in a tJDBCInput with the driver jar selected works fine... bizarre)
The location where your jar was put does not look familiar. Try deleting all the jtds jar versions in the following locations :
<Talend root folder>\configuration\.m2\repository\org\talend\libraries
<Talend root folder>\lib\java
And restart your studio. When you go back to your component, you'll see an install button. You should be able to download and install the jar.
Is it possible to create DB2 connection in QTP using JDBC driver?
Please guide me with some possible tips... Thanks!
Finally, I've found a solution !!!! :) It's very simple, if we know Java....!
Here we go - I've just written code in Java for DB2 connection establishment using JDBC driver and also included code for data retrieval.
And then, exported the package into Executable JAR File which made my job very easy. YES!!!!
After creating the Executable JAR, I've used the line below in QTP to access the DB2 through JAR.
SystemUtil.Run "cmd","/k java -jar C:\JarFile\DB2Connect.jar",""
I have a WAR file with REST services. It deploys just fine on JBoss EAP 6.2 (corresponding to AS 7.something) in the standalone mode but it fails sometimes - but often - in the domain mode with a ClassNotFoundException for my subclass of the the JAX-RS Application class, even though it is in the war (well, it runs in standalone). Since it sometimes works, I suspect there is some concurrency issue that leads to JBoss trying to load the class before it can see it.
This is the error:
ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start
service jboss.deployment.unit.myapp.POST_MODULE: org.jboss.msc.service.StartException in
service jboss.deployment.unit.myapp.POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of deployment "myapp"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:127)
...
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011230: Could not load JAX-RS Application class
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scan(JaxrsScanningProcessor.java:218)
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:100)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:120)
[jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
... 5 more
Caused by: java.lang.ClassNotFoundException: myapp.rs.RestApplication from [Module "deployment.myapp:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)
[jboss-modules.jar:1.3.0.Final-redhat-2]
...
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scan(JaxrsScanningProcessor.java:214)
... 7 more
The class is there:
[jboss/domain]$ unzip -l data/content/6c/0ffc675ff1c2254540b6e8caffc0d2605ed549/content | grep RestApp
2262 02-13-14 09:05 WEB-INF/classes/myapp/rs/RestApplication.class
This is how I deployed it (my user != the user running jboss, if that makes a difference):
me$ /opt/jboss/bin/jboss-cli.sh -c --controller=0.0.0.0:49999 --user=admin --password=***
[domain#0.0.0.0:49999 /] deploy /vagrant/myapp.war --all-server-groups
The deployment fails in the same way when executed via the web Admin Console. The deployment to standalone is done by copying the .war to the standalone/deployments/ directory.
Any tips?
Config info
JBoss EAP 6.2
Rest Easy 3.0.6 (replacing the default 2.x module)
We have no JAX-RS stuff in web.xml aside of the resteasy.servlet.mapping.prefix context param; we use the resteasy-servlet-initializer library instead of manually configuring a servlet or similar thing in there
It seems I have fixed the problem by removing all resteasy/jaxrs/jboss libraries from the WAR file's WEB-INF/lib/.
I have noticed the war contained many libraries it should not, such as resteasy-jaxrs-3.0.6.Final.jar, jboss-jaxr-api_1.0_spec-1.0.0.Final.jar (which, BTW, conflicts with Rest Easy 3.0.6), javax.servlet-api-3.1.0.jar etc.
So I guess the classloader did not see/find the class because of classpath hell, the server and the webapp using different "instances" of the same libraries. (No idea why it worked under JBoss standalone; but standalone has the out-of-the-box configuration while domain has been adjusted a lot).
I have also sometimes included --runtime-name=myapp in the deployment command, which seems to be wrong, I should have used --runtime-name=myapp.war (including the ending).
Even though the Author had found an answer for himself, I think it might be useful to post my situation in case other people come accross this issue and the authors solution doesn't work for them.
I had a similar issue where a class was also not found when run under a Redhat JBoss AS cartridge inside Openshift, even though it seemed unreasonable, but later I figured out that the war I was expecting to be deployed wasn't deployed, instead a different one was deployed.
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/].[HelloWorld]] (http--127.10.254.129-8080-1) Allocate exception for servlet HelloWorld: java.lang.ClassNotFoundException: com.company.app.HelloWorld from [Module "deployment.ROOT.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
So if there are possibilities, I would run a search of all war files which are expected to have that class, unzip them and search inside the contents to see whether they contain the needed compiled class. I really suggest trying to search for all possible wars. Also look for possible YOUR_WAR.war.deployed it is most likely going to be in the same folder as the war that is currently deployed.
In my case I had these wars:
./app-root/runtime/repo/deployments/ROOT.war
./app-root/runtime/dependencies/jbossas_custom/deployments/ROOT.war.deployed
./app-root/runtime/dependencies/jbossas_custom/deployments/ROOT.war
I was expecting the real one to be in ./app-root/runtime/repo/deployments/ROOT.war because that's where maven was creating it, but seems JBoss would later have to copy it to ./app-root/runtime/dependencies/jbossas_custom/deployments/ROOT.war in my case it didn't do that itself, so therefore my updated war was never deployed, instead it always went to deploy the old one which was already in ./app-root/runtime/dependencies/jbossas_custom/deployments/ROOT.war
Hope this helps somebody to get on the right track.
I'm using Eclipse Juno, Hibernate 4.0 and MSSQL 2008.
I've created a database and have just gone through the process "JPA Entities from Tables" in Eclipse. About half of the tables did not get created (even though I selected those table), but the classes were added to persistence.xml.
Has anyone else experienced this problem? Do you have a solution?
In my case the database was Oracle XE. So mine is a bit different case but may be helpful to someone.
The best way to find the problem with this is to check the logs of workspace present at $workspace_location/.metadata/.log file. In my case I found that there were 3 problems:
1) Caused by: java.io.FileNotFoundException: $MiddlewarePath\oracle_common\modules\oracle.adf.share_11.1.1\adfsharembean.jar (Access is denied)
2) Caused by: java.io.FileNotFoundException: $MiddlewarePath\oracle_common\modules\oracle.ldap_11.1.1\jremtool.jar (Access is denied)
3) !MESSAGE Unable to find JPA entities generation templates in pluginorg.eclipse.jpt.jpa.gen
!STACK 1
Java Model Exception: Core Exception [code 275] A resource exists with a different case: '/TestJPAProjectFacetsEJB/src/main/java/com/domainname/ejb/TestJPAProjectFacets'.
Hence I did the following:
1) Provided access permission for the jar files
2) While I was generating entities I was giving the package name as com/domainname/ejb/testjpaprojectfacets/model. But I was already having a package com/domainname/ejb/TestJPAProjectFacets hence the error. I then renamed my existing package to all lowercase (com/domainname/ejb/testjpaprojectfacets) and it worked.
Thanks,
Sanjay
My workaround was to use the JTDS JDBC Driver to connect to SQL Server database instead of the Microsoft SQL Server JDBC Driver
This sounds like Eclipse DTP bug 282206. Dali (the Eclipse project that supplies the Entity Generation wizard you are using) depends on the Eclipse DTP project for retrieving from various database servers the necessary meta-data to generate entities. The MS SQL Server "driver" you are using (i.e. the plug-in used by DTP to adapt the MS SQL JDBC driver to the DTP SPI interfaces - by default this plug-in is org.eclipse.datatools.enablement.msft.sqlserver... - it is a bit confusing that the DTP developers like to call these plug-ins "drivers"....) has a bug in the meta-data it returns to Dali, preventing Dali from generating entities.
I faced this issue too.
My workaround - Created the database in MySQL and generated entities from there. The generated entity classes work with SQL Server as well. Not faced any other side-effects (so far)
I was following the following instructions:
http://www.eclipse.org/articles/article.php?file=Article-EclipseDbWebapps/index.html
in order to set-up a derby database server and everything works fine. I created the DB and could easily access it. however, these instructions use JSP to access my DB and I wand to change it so that I can access the DB through my custom Java classes but I cant create any connections to the DB. I simply tried:
Connection con = DriverManager.getConnection
("jdbc:derby://localhost:1527/features", "root", "root");
Note: here my DB is names features
I get the error:
java.sql.SQLException:
No suitable driver found for jdbc:derby://localhost:1527/features
I tried loading the class for the driver:
Class.forName("org.apache.derby.jdbc.ClientDriver");
I get the error:
java.lang.ClassNotFoundException:
org.apache.derby.jdbc.ClientDriver
I dont know where to find and put org.apache.derby.jdbc.ClientDriver. How come in the instructions they only add a context.xml under META_INF and everything work? What am I missing?
Did you:
Copy the file derbyclient.jar from that folder to your TOMCAT_ROOT/lib
folder (if you're using Tomcat 5.x, install into
TOMCAT_ROOT/common/lib). This installs the Derby JDBC driver into
Tomcat for use in a DataSource.
You need the derbyclient.jar in the classpath.