My JBoss version is Jboss-as-7.1.1.Final.
I have some system properties in standalone.xml:
<system-properties>
<property name="ims.eas.service.registerSystem" value="registerSystem"/>
<property name="ims.developerMode" value="false"/>
...
</system-properties>
In web.xml refer to them as ${ims.developerMode}. But it does not work.
Watched System.getProperties() in debug mode, system properties are there. It reads them from standalone.xml but not replaces in web.xml. With jboss-eap-6.1 it works pretty well.
Related
I'm doing some EJB with JPA project that maps/persists some entities to mysql database.
I have defined persistence unit in persistence.xml like this:
<persistence-unit name="MyAppPU" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>MyAppDS</jta-data-source>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
<property name="openjpa.jdbc.DBDictionary" value="mysql" />
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
</properties>
</persistence-unit>
Then, in tomee/conf/tomee.xml file i have defined data source like this:
<Resource id="MyAppDS" type="DataSource">
JdbcDriver com.mysql.jdbc.Driver
JdbcUrl jdbc:mysql://127.0.0.1:3306/MyAppDB
UserName root
Password 123
JtaManaged true
DefaultAutoCommit false
</Resource>
All this works fine, i create MyApp.jar, deploy it to TomEE server, test it and i get mysql tables in database.
My question is "Is there any other place where I could define data source resource?"
Or it has to be in tomee/conf/tomee.xml file?
Can it be defined somewhere inside application structure, in some xml file, and deployed inside apps jar file to server?
That's the whole point of a JNDI data source, to externalize it outside of your application, so you can modify it without recompiling or repackaging. So it is better to leave it this way.
For testing purpose, some EE server such as JBoss (Wildfly) let you define this in your project.
It might be a bit late to answer this, You can in tomee place the resource definition in WEB-INF/resources.xml.
You only have to set the tomee.xml. If you are using Eclipse, you must copy the tomee.xml into the servers configuration/Tomee to get recognize it into the web project, otherwise you will get troubles.
I am attempting to complete this Java Brains tutorial on hibernate, using hibernate3.6.10.Final and Eclipse IDE, and I am encountering an exception that is not covered in the video. Here is the output:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.hibernate.cfg.Configuration.reset(Configuration.java:332)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:298)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:302)
at com.helo478.firsthibernateproject.SimpleTest.setUpHibernate(SimpleTest.java:31)
at com.helo478.firsthibernateproject.SimpleTest.main(SimpleTest.java:19)
Caused by: java.lang.NullPointerException
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:167)
at org.hibernate.cfg.Environment.<clinit>(Environment.java:618)
... 5 more
[EDIT] I thought the first 3 lines of code were irrelevent, because I've seen a working version of this program (in the tutorial) that had that output. However, it seems that the issue was, indeed with the slf4j jars. Thank you #Jayaram Pradhan and # drurenia[/EDIT]
I did some searching on StackOverflow already and found this similar case (actually they were probably doing the same tutorial). Unfortunately, that thread does not, at this time, have a usable solution. The questioner solved their problem by starting from scratch and using a different database. I have done that (using both PostgreSQL and MySQL), and I get the same error on each.
The other response indicated that the configuration file should be in the project root directory and that the Configurations.configure() method takes an optional String filepath. I have tried placing the hibernate.cfg.xml file in both the project root directory, as well as the "src" directory. I have also tried pointing to the file in with an argument on the .configure() method. There is no change in output.
Because every line of my Java code is taken directly from the tutorial, I think it is most likely that there is a problem with my hibernate.cfg.xml file. The file is altered from a template that was packaged with hibernate3. I just changed it to reference the MySQL database. Being new to Hibernate, I suppose I must have made a mistake there. Here is the complete text:
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernatedb</property>
<property name="connection.username">root</property>
<property name="connection.password">password</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- Names the annotated entity class -->
<mapping class="com.helo478.firsthibernateproject.User" />
</session-factory>
</hibernate-configuration>
My question is this:
What, if anything, am I doing wrong in my hibernate.cfg.xml file? If nothing is wrong, what else might explain the failure?
I didn't see the tutorial you are reffering but from your stack trace its look like, your slf4j dependencies are not present.
Reffer to the below links which will help you to include the slf4j dependcies:
Hibernate 3.4 with slf4j and log4j
http://www.slf4j.org/manual.html
Make sure you have :
•slf4j-api-1.7.5.jar
•slf4j-simple-1.6.1.jar
in your lib.
I'm writing a java Application for Tomcat 7.
I have a bean configuration for a class that creates a log file and appends information to it.
now the question is how can I know the tomcat log directory path in bean configuration.
for now I have the following bean:
<bean id="foo_logger" class="com.bar.LoggerBean">
<!-- <property name="logPath" value="/path/DWHEventGenerator.log"/> -->
<property name="logPath" value="/var/lib/tomcat7/logs/mylog.log"/>
<property name="logLevel" value="ALL"/> <!-- ALL, FINE/R/ST, INFO, SEVERE, WARNING, OFF -->
</bean>
what i'd like to do is instead of specify /var/log/tomcat7/log, is to specify some variable that will indicate the actual path of the logs directory of tomcat. is that possible ?
thank you.
The simplest approach would be to use catalina.base from the system properties in the logPath property value
<property name="logPath" value="${catalina.base}/logs/mylog.log"/>
This property will be set by Tomcat's launch script (catalina.sh/catalina.bat) so will be available for use when Spring loads the application context file.
I'm trying to configure a xWiki server on a OpenShift hosting (Tomcat 6 (JBoss EWS 1.0)). I've never configured a Java server before and I have a issue:
I followed THIS tuto on my local Ubuntu and worked. But reproducing the steps in the OpenShift server I can't find the hibernate.cfg.xml. Looking for files in the directory tree with hibernate I've found the folder jbossews-1.0/jbossews-1.0/work/Catalina/localhost/xwiki/WEB-INF/lib/ with the files:
hibernate-c3p0-3.6.9.Final.jar
hibernate-core-3.6.9.Final.jar
hibernate-validator-4.3.0.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-commons-annotations-3.2.0.Final.jar
But nothing similar to hibernate.cfg.xml. How can I fix it?
hibernate.cfg.xml is your configuration file for Hibernate, where you specify the dialect, connection driver, url, username, password, etc. of the database.
Example:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://host/database</property>
<property name="connection.username">username</property>
<property name="connection.password">password</property>
<property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">false</property>
</session-factory>
</hibernate-configuration>
Place this file in the Java resources classpath.
For detail information look hibernate.cfg.xml for Oracle or example by mkyong
This is (should be, anyway) an xWiki installation issue. If you are using the WAR file, then when you put the WAR into the tomcat webapps directory, Tomcat normally will expand the WAR into a directory with the same name. In that directory, in the WEB-INF directory, should be the hibernate.cfg.xml file. Typically, here:
/var/lib/tomcat5.5/webapps/xwiki/WEB-INF/hibernate.cfg.xml
If you have configured your Tomcat to run the WAR without expanding it, then the file will be in the WAR at:
WEB-INF/hibernate.cfg.xml
But in this instance you will have to edit the XML file and put it back into the WAR to configure the application.
I had the same problem, and by stracing tomcat I see it looks at the following places, the long one being in the git repository in my openstack gear:
/var/lib/openshift/518f381fe0b8cd1de2000181/git/tomcat.git/hibernate.cfg.xml
/usr/share/java/tomcat7/hibernate.cfg.xml
I cannot see any correlation between these locations and the classpath either given in the command line or in catalina.properties. The git repository is the cwd of tomcat. Putting hibernate.cfg.xml there does work for now. But I believe as soon as openstack guys realize how messy is to put the cwd there, they will move it away.
I am trying to deploy a WAR on the mentioned tomcat application server. However following is the error that I get when I try to use the tomcat manager / ant script for deployment.
java.lang.IllegalStateException: ContainerBase.addChild: start: LifecycleException: Error initializaing : java.lang.IllegalArgumentException: The archive [jar:file:/var/lib/tomcat6/webapps/afgretail.war!/] is malformed and will be ignored: an entry contains an illegal path [/]
The WAR contains spring beans, HTML pages, js, images, css etc. We are currently deploying the project by coping the unzipped project directly into the webapps folder on the tomcat server which works fine. However we would like to deploy using the ant script developed to deploy war file to a remote tomcat.
The development was done on windows platform but the tomcat server resides on Linux (Oracle Enterprise Linux)
Snippet that does deployment as follows:
<!-- Configure the folder and context path for this application -->
<property name="webapp" value="walton" />
<property name="path" value="/walton" />
<!-- Configure properties to access the Manager application -->
<property name="url" value="http://localhost:8080/manager/html" />
<!-- <property name="url" value="http://osm4.afgonline.com.au:8080/manager/html" />-->
<property name="username" value="tomcat" />
<property name="password" value="s3cret" />
<property name="dist.dir" value="dist" />
<property name="webapp.path" value="${dist.dir}/${webapp}" />
<property name="project.path" value="C:/java/workspace/afghl_walton"/>
<path id="deployer.classpath">
<!--fileset dir="${basedir}/lib"-->
<fileset dir="C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\">
<include name="*.jar" />
</fileset>
</path>
<!-- Configure the custom Ant tasks for the Manager application -->
<taskdef resource="org/apache/catalina/ant/catalina.tasks"
classpathref="deployer.classpath" />
<target name="deploy" description="Deploy web application">
<deploy url="${url}" username="${username}" password="${password}"
path="${path}" war="${project.path}/${webapp.path}.war" update="true" />
</target>
Any help will be apprrciated. If there is more information required please let me know.
Thanks,
Khush
I had the same problem with Tomcat 5.5.34. I build the WAR with Ant and the WAR target contained the following task:
The prefix caused an jar entry named "/" in the war package and since Tomcat 5.5.26 that entry causes an exception during startup of the Tomcat container.
Changing the prefix attribute value of the war command to
removed all my problems.
Best regards,
Chris
Just avoid using out and getOutputStream at the same time!