How to connect Jboss-as-7.1.1 with Postgresql [closed] - postgresql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Does anybody know how to connect jboss-as-7.1.1 to PostgreSQL?

(Note that this was written for JBoss AS 7.1.1; keep that in mind if on a newer version, as things might have changed.)
Download PgJDBC. I'm assuming you're using postgresql-9.1-902.jdbc4.jar, the current version at time of writing. Adjust any filenames to match if you need a different version.
Now deploy the JDBC driver to JBoss AS 7 by putting it in the deployments folder or using the deploy command in jboss-cli. This will work for most, but not all, purposes.
Alternately, you an define a PostgreSQL JDBC driver module:
Create the path $JBOSS_HOME/modules/org/postgresql/main. The modules/org part should already exist, make directories for the rest.
In $JBOSS_HOME/modules/org/postgresql/main/module.xml with the following content, changing the resource-root entry for the PgJDBC driver to refer to the driver you wish to use.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-9.1-902.jdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
Into the same directory as module.xml place postgresql-9.1-902.jdbc4.jar
Start JBoss AS
Open jboss-cli by running $JBOSS_HOME/bin/jboss-cli --connect
Run the command:
/subsystem=datasources/jdbc-driver=postgresql-driver:add(driver-name=postgresql-driver, driver-class-name=org.postgresql.Driver, driver-module-name=org.postgresql)
Now create any required data sources, etc, using postgresql-driver as the driver name.
You can create a datasource via the web ui, with jboss-cli with the data-source create command (see data-source --help, data-source add --help), or by deploying a -ds.xml file like this:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<datasource jndi-name="java:/datasources/some-ds" enabled="true" use-java-context="true"
pool-name="some-ds-pool">
<connection-url>jdbc:postgresql:dbname</connection-url>
<driver>postgresql-driver</driver>
<security>
<user-name>username</user-name>
<password>password</password>
</security>
</datasource>
</datasources>

Related

How do I set myDatasource-ds.xml without modules.xml

I want to set database configuration using only ds.xml. So that without using modules.xml and standalone.xml I just deploy the ds.xml in deployments for Database connection.
mydatasource-ds.xml
<datasources>
<datasource jndi-name="java:jboss/datasources/myDatasource" pool-name="myDatasource_pool" enabled="true" use-java-context="true">
<connection-url></connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>ojdbc6</driver>
<security>
<user-name></user-name>
<password></password>
</security>
</datasource>
If you are creating driver module then only module.xml comes into picture. If you deploy driver jar directly into deployment directory, no need to create module.xml.
However it is recommended to create driver module and create datasource in standalone.xml because if you create datasource using ds.xml you will not be able to monitor it.

Deployment of webapp in wildfly using Context Descriptors

I searched using "How to set Context Path in Wildfly", but got no success. Can anyone help me on how to do it..?
I've used the following code to set the Context Path in tomcat where I can access my application directly using localhost:8080/myApp
myApp.xml contains as follows and placed at $CATALINA_BASE\conf\[enginename]\[hostname]\myApp.xml
<Context path="myApp" docBase="G:\workspace\j2ee\myProject\myWebApp\WebContent" />
similar or equivalent type of configuration want to use in Wildfly server.
In your standalone.xml configuration you want to add a deployment like this:
<deployments>
<deployment name="myProject" runtime-name="myProject.war">
<fs-archive path="G:/workspace/j2ee/myProject/myWebApp/WebContent"/>
</deployment>
</deployments>
Then within WebContent/WEB-INF create a file called jboss-web.xml with a configuration similar to:
<?xml version="1.0"?>
<jboss-web>
<context-root>/my-context-path</context-root>
</jboss-web>
If this doesn't work you may need to rename WebContent directory to WebContent.war, even if it is exploded it may want .war in the name.

WildFly 8.2 unable to configure for external property file

I am using the wildly 8.2 final , facing the configuration with external property file. My requirement is like this i am using jboss 5 earlier for locally . we were placed property file in this location jboss-5.0.0.GA\server\default\conf and using in application ear (spring property file configuration), but in wild fly we are unable to configuring i tried modules also, i.e we used the property file with out package
Specify location in standalone.bat file inside bin folder as shown below
set JAVA_OPTS=%JAVA_OPTS% -Dprogram.name=%PROGNAME% - DpropertyName.config.dir=Path_to_config
Adding a module and putting your property files inside the module is the way to go.
Ensure the following:
That your module directory is created correctly, such as $JBOSS_HOME/modules/com/company/package/main.
That you have a valid module.xml file in the directory. It should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.company.package">
<resources>
<resource-root path="."/>
</resources>
</module>
Your property file(s) is in the directory.

Does anyone know how I can directly use classes under sun.awt namespace in a JBOSS 7.1 servelet?

We have a customer who create a servelet to be hosted in JBOSS 7.1 on Windows 7 64-bit and the servelet uses the java classes in a jar file we develop. One of our classes makes use of sun.awt.DisplayChangedListener interface. The problem is that we get NoClassDefFoundError exception from the class that uses the DisplayChangedListener when the servelet is called and DisplayChangedListener is the root cause. There is no problem with many other classes in the same rt.jar file where DisplayChangedListener also resides. I use process explorer to look at the jar files the JBOSS process loads and only one rt.jar file is there. If I run the same codes directly using java, I have no problem. If I place a copy of rt.jar file to the local repository of the deployed servelet application in JBOSS, there is no problem as well. I know classes under sun.awt namespace are supposed to use internally not by developers, and it seems like the JBOSS class loader reinforece the restriction on their use. Is there any way I can make it work without the local copy of rt.jar and without abandoning the use of DisplayChangedListener interface (such as through some setting in configuration files)?
Thanks in advance for any help.
The steps I recommend are:
create a new module
add the following dependany (with edits for the packages you need)
...
<dependencies>
<system export="true">
<paths>
<path name="com/sun"/>
<path name="com/sun/net/ssl/internal/ssl"/>
</paths>
</system>
<module name="javax.api"/>
<module name="org.apache.log4j"/>
<module name="sun.jdk" export="true"/>
</dependencies>
make your application depend on the module.

How do I change the context path of my Enterprise Project

So my enterprise project name TestProject, which contain TestProject-ejb and TestProject-war, so when I run the project the url is like this locahost:8080/TestProject-war. How can I change this url to localhost:8080/testproject. I use netbean 6.9, I try to right click on TestProject-war folder in netbean, and specify the context-path there under Run, but it still load locahost:8080/TestProject-war
You need to check that the context-root element for the web module in the application.xml file that's in the META-INF directory of your EAR has been correctly changed.
An example would look like this:
<?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_6.xsd"
id="Application_ID" version="6">
<display-name>TestProject</display-name>
<module>
<web>
<web-uri>TestProjectWeb.war</web-uri>
<context-root>testproject</context-root>
</web>
</module>
<module>
<ejb>TestProjectEJB.jar</ejb>
</module>
</application>
In this example the web module should be available under /testproject of the server you deploy to, so in your case http://localhost:8080/testproject.
(In case you would like to deploy to the root of your server, you can leave the context-root element empty: <context-root></context-root>.)
If you indeed see that your action in Netbeans has correctly changed this file, it may be a deployment problem like BalusC indicated. Check the location the EAR is deployed to and manually inspect whether the deployed version also has the correct value.
As Harry pointed out the default project template doesn't create an application.xml file, so you have to create it by hand at $ENTERPRISE_APP_PATH/src/conf (tested with NB 6.9.1)
Just ran into this question in the course of figuring out the same thing. Since the OP was asking about doing this in Netbeans, let me add to previous answers by describing specifically how to do this using the Netbeans IDE.
With Netbeans 8 (and possibly also with earlier versions) you can tell the IDE to create the application.xml file for you, as follows. Right-click the enterprise application project (in the OP's example this would be "TestProject"), select "New" then "Standard Deployment Descriptor...". This will create an "application.xml" file and put it in the appropriate place in your Netbeans project. Then you can easily edit this file to set the context-root element to be whatever you want.