Copy files to new project and now cannot create JDBC driver of class '' for connect URL 'null' - eclipse

Caused by: java.sql.SQLException: No suitable driver
A Maven project in eclipse, I lost the .project file for this application. I have to copy the files into another project. So it was running before.
I am using a DataSource in Tomcat. The projects META-INF/context.xml file hasn't changed. It's deployed into /META-INF directory. web.xml and pom.xml is the same. I don't know what has changed. mysql-connector-5.1.38.jar is in $Catalina/lib.
I would look at the Build Path and Deployment Assembly but let me know.
build path.
deployment assly.
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
name="jdbc/widget"
auth="Container"
type="javax.sql.DataSource"
maxActive="10"
maxIdle="3"
maxWait="10000"
username="appuser"
password="appuserpass"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/widget"/>
</Context>
web.xml
<resource-ref>
<description>MySQL Datasource</description>
<res-ref-name>jdbc/widget</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

Coming back to this, I saw a similar project and matched the deployment assembly. This seemed to fix the issue. Current configuration :
/src/main/java -> WEB-INF/classes
/src/main/resources -> WEB-INF/classes
/src/main/resources/META-INF -> META-INF
/src/main/webapp -> /
/src/test/java -> WEB-INF/classes
Maven Dependencies -> WEB-INF/lib

Related

Jboss eap-7.2: Adding external directory to a class-path

As per project need we need to migrate from jboss-eap-5.1.2 to jboss-eap-7.2 and for testing I was trying to deploy the war file in jboss-7.2.
But it started giving me exception
rom relative location [mailsender.xml]
Offending resource: class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreExcept
ion: IOException parsing XML document from URL [vfs:/C:/dev/migration/jboss-eap-7.2-eap/bin/content/basel.war/WEB-INF/classes/mailsender.xml]; ne
sted exception is java.io.FileNotFoundException: C:\dev\migration\jboss-eap-7.2-eap\standalone\tmp\vfs\temp\tempc01c1475a2367060\content-53d16429
03fec06a\WEB-INF\classes\mailsender.xml (The system cannot find the file specified)
i.e. file mailsender.xml is not added in the classpath.
Query : Is there any way in jboss-eap-7.2 to add a external folder(where I can put all of my XML's which needs to be present at the classpath) to classpath?
This works for me in JBOSS EAP 7.1, where APP-INF/classes resource folder in ear or war:
add META-INF/jboss-deployment-structure.xml with similar config:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<resources>
<resource-root path="APP-INF/classes" />
</resources>
</deployment>
</jboss-deployment-structure>

JBoss EAR deployment fails because WAR classes are unable to find jars from EAR/lib folder

I am using JBoss EAP 7 and want to deploy an EAR file in standalone mode (using standalone-ha.xml).
I went through almost everything available on StackOverflow/JBoss forums but couldn't make my deployment to work (correctly). I have followed the docs to the best of my abilities but still the deployment of EAR gives Exception on console because the jar files inside WAR/WEB-INF/lib are not able to see the jar files present int EAR/lib folder. I can't figure out what I am doing wrong.
Structure
myEAR.ear
|- lib (contains a.jar)
|- META-INF
|--- maven (folder with pom)
|--- application.xml
|--- jboss-deployment-structure.xml
|--- MANIFEST.MF
|- myWar.war
|--- WEB-INF
|----- lib (contains b.jar)
|----- jboss-deployment-structure.xml (which should be ignored per the docs)
|----- (WEB-INF contains other files/folders such as classes,jsp etc
EAR- application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" version="7">
<display-name>myear</display-name>
<module>
<web>
<web-uri>myWAR.war</web-uri>
<context-root>/mywar</context-root>
</web>
</module>
<library-directory>lib</library-directory>
</application>
EAR- jboss-deployment-structure.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
<dependencies>
<module name="com.organization.global" export="true" />
</dependencies>
</deployment>
<!-- Having/Not having below sub-deployment has no effect -->
<sub-deployment name="myWAR.war">
<dependencies/>
</sub-deployment>
</jboss-deployment-structure>
Deployment succeeds if I copy a.jar inside WAR/WEB-INF/lib/ folder, otherwise gives an exception: Caused by: java.lang.NoClassDefFoundError related to a class specific to a.jar. I want my WAR to be able to get access to all the jars put together inside EAR/lib.
I read in one of the forums that the jar/classes in lib folder should be available to all modules within the EAR but sometimes they are not added automatically but I couldn't find the solution on how to add them.
Any guidance would be appreciated. Thanks in advance!
In JBoss EAP 7, to access lib files present in ear inside war you could try by adding a context param in your war's web.xml.
To create env variable try below in terminal:
export JAR_HOME=../jboss-eap-7.1/standalone/deployments/example.ear(Please add value equivalent to your environment and ear's path)
export PATH=$PATH:$JAR_HOME
Add this variable to web.xml as file:${JAR_HOME}/lib/example.jar
Read this context param inside your classes present inside war.

EAR application works on Websphere8.5 but refuses to work on Websphere liberty 16.0.0.4

I get in inheritance EAR application which I need to continue to develop. The problem that I can't cause it work on Websphere Liberty 16.0.0.4 while on Websphere Application Server Full Profile 8.5 it works fine. Unfortunately or (fortunately :) ) my working station is Macbook Pro, and WAS Full Profile can't be installed on OSX (can't find links right now, but have done some search and find enough evidences for it) so I need to use VirtualBox with Linux or try to run this app on Liberty.
The latest solution doesn't work so well for me, I get the following error:
[ERROR ] CWWJP0012E: The persistence unit name is not specified and
a unique persistence unit is not found in the BigEnterpriseAppEAR
application and BigEnterpriseAppEJB.jar module. [ERROR ] CWWJP0029E:
The server cannot find the persistence unit in the
BigEnterpriseAppEJB.jar module and the BigEnterpriseAppEAR
application. [ERROR ] CWNEN0035E: The java:comp/env/BigEnterpriseApp
reference of type javax.persistence.EntityManager for the DataProvider
component in the BigEnterpriseAppEJB.jar module of the
BigEnterpriseAppEAR application cannot be resolved. [ERROR ]
CNTR0020E: EJB threw an unexpected (non-declared) exception during
invocation of method "getDataByOwner" on bean
"BeanId(BigEnterpriseAppEAR#BigEnterpriseAppWEB.war#DataAPI, null)".
Exception data: javax.ejb.EJBTransactionRolledbackException: nested
exception is: javax.ejb.EJBException: The
java:comp/env/BigEnterpriseApp reference of type
javax.persistence.EntityManager for the DataProvider component in the
BigEnterpriseAppEJB.jar module of the BigEnterpriseAppEAR application
cannot be resolved.
The app is pretty simple EAR = JPA + EJB + WAR
I don't know which configuration files would be helpful, so just write in a comments what to post and I will do it.
Thank you in advance.
UPDATE 1:
server.xml file:
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>localConnector-1.0</feature>
<feature>servlet-3.1</feature>
<feature>ejbLite-3.1</feature>
<feature>jndi-1.0</feature>
<feature>jaxrs-1.1</feature>
<feature>ssl-1.0</feature>
<feature>jpa-2.0</feature>
<feature>cdi-1.0</feature>
</featureManager>
<basicRegistry id="basic" realm="BasicRealm">
<!-- <user name="yourUserName" password="" /> -->
</basicRegistry>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
<library id="DB2JCC4Lib">
<fileset dir="/Users/anatoly/developer/sql_drivers" includes="*.jar"/>
</library>
<dataSource id="db2_slc" jndiName="jdbc/BEADB" type="javax.sql.DataSource">
<jdbcDriver libraryRef="DB2JCC4Lib"/>
<properties.db2.jcc databaseName="beadb" password="********" portNumber="50000" serverName="db2server" user="db2username"/>
</dataSource>
<keyStore id="defaultKeyStore" password="******"/>
<enterpriseApplication id="BigEnterpriseAppEAR" location="BigEnterpriseAppEAR.ear" name="BigEnterpriseAppEAR"/>
</server>
persistence.xml file, located in BigEnterpriseAppJPA > src > META-INF > persistence.xml
in packaged EAR persistence.xml located in BigEnterpriseAppEAR -> BigEnterpriseAppJPA.jar -> META-INF -> persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="BigEnterpriseApp">
<jta-data-source>jdbc/BEADB</jta-data-source>
<class>com.bea.entities.System</class>
<class>com.bea.entities.Data</class>
<class>com.bea.entities.User</class>
<class>com.bea.entities.Group</class>
<properties>
<property name="openjpa.jdbc.Schema" value="BEADB" />
<property name="openjpa.ConnectionRetainMode" value="transaction" />
</properties>
</persistence-unit>
</persistence>
[ERROR ] CWWJP0012E: The persistence unit name is not specified and a unique persistence unit is not found in the BigEnterpriseAppEAR application and BigEnterpriseAppEJB.jar module.
This would imply your persistence.xml roots are not at the legal locations defined by the JPA spec, section 8.2:
In Java EE environments, the root of a persistence unit must be one of the following:
an EJB-JAR file
the WEB-INF/classes directory of a WAR file[87]
a jar file in the WEB-INF/lib directory of a WAR file
a jar file in the EAR library directory
an application client jar file
NOTE: Java Persistence 1.0 supported use of a jar file in the root of the EAR as the root of a
persistence unit. This use is no longer supported. Portable applications should use the EAR
library directory for this case instead
Your setup seems to be trying to use #4?
BigEnterpriseAppEAR -> BigEnterpriseAppJPA.jar -> META-INF -> persistence.xml
BigEnterpriseAppJPA.jar should be placed inside your EAR library directory. I believe this will be BigEnterpriseAppEAR/lib by default, but you can configure this with your /META-INF/application.xml in the EAR
Also note, that the persistence-unit name must be unique. Make sure that all persistence-unit names are not using the same name.

How to define a custom EAR file name for a specific application?

Here is my setup
SDK: Eclipse Ganymede (3.4.2)
App Server: jBoss 4.2.3GA
I got three projects:
MYAPP, which is the main project, with only libraries and log4j configurations. This is where application.xml and jboss-app.xml resides.
MYAPPEJB, which is my business logic project in which I have my entity beans, sessions beans.
MYAPPWeb, which is my client logic project in which I have my Struts Forms, Struts Actions, JSPs and Jasperreports reports.
When I publish my project to my jBoss server on my laptop, I got the following EAR file name: MYAPP.ear, which make sense.
I would like to define a different custom name for the final EAR, let's say ACCOUNTMANAGER.ear
Here is my application.xml file
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" id="Application_ID" version="5">
<display-name>MYAPP</display-name>
<module>
<ejb>MYAPPEJB.jar</ejb>
</module>
<module>
<web>
<web-uri>MYAPPWeb.war</web-uri>
<context-root>/manager/myapp</context-root>
</web>
</module>
<library-directory>/lib</library-directory>
</application>
Any idea?
Thank you
Charles
You can specify your ear file name in application.xml file under web -> web-uri tag. Please check this link for your reference. web-uri
You can specify in application.xml file. It will pick up this name instead of ear file name.
MyEarName

JBoss (liferay) no context.xml so where to put JNDI resource

I've got the order to switch from Liferay on tomcat, to Liferay on JBoss.
One issue I'm having is that unlike in tomcat, I can't seem to find a context.xml in liferay-portal-6.0.5\jboss-5.1.0\server\default\conf
Will it work if I just copy the context.xml from my tomcat installation to my jboss installation? (I don't know if JBoss scans that folder).
Or is there an alternative location where I can put my resource?
<Resource name="jdbc/x" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="y"
username="z" password="A" maxActive="20" maxIdle="10"
maxWait="-1"/>
Add a file named "*- ds.xml" in the deploy directory server with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/myds</jndi-name>
<connection-url>jdbc:oracle:thin:#127.0.0.1:1521:sid</connection-url>
<user-name></user-name>
<password></password>
<new-connection-sql>SELECT * FROM DUAL</new-connection-sql>
<check-valid-connection-sql>SELECT * FROM DUAL</check-valid-connection-sql>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
</local-tx-datasource>
</datasources>