I'm trying to load a properties file using Spring's #PropertySource annotation. The properties file is stored in a Wildfly 8 module. The error message that I'm getting is:
class path resource [campaigner.properties] cannot be opened because it does not exist
Here's the Java code, which is used by the application's services.
#Configuration
#PropertySource("classpath:campaigner.properties")
class ServiceConfigImpl implements ServiceConfig
{
#Autowired
private Environment env;
#Bean(name = "serviceConfig")
public ServiceConfig getServiceConfig()
{
return new ServiceConfigImpl(this.env);
}
}
Here's my jboss-deployment-structure.xml, which I'm putting in the META-INF directory of my .ear file.
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.dr_dee_sw.campaigner" />
</dependencies>
</deployment>
</jboss-deployment-structure>
I've also put a MANIFEST.MF file in the META-INF directory
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.7.0_71-b14 (Oracle Corporation)
Dependencies: com.dr_dee_sw.campaigner
Here's my module file, which I've put in WILDFLY_HOME\modules\com\dr_dee_sw\campaigner\main directory, along with the campaigner.properties file
<module xmlns="urn:jboss:module:1.1" name="com.dr_dee_sw.campaigner">
<resources>
<resource-root path="."/>
</resources>
</module>
What am I missing?
This page led me to the answer: https://www.javacodegeeks.com/2012/09/jboss-as-7-classloading-explained.html. My jboss-deployment-structure.xml was wrong. I have an EJB-JAR file inside the EAR file and that needs to be the focus of that file. So, I had to switch from using <deployment> to <sub-deployment> as shown below.
<jboss-deployment-structure>
<sub-deployment name="campaigner-service.jar">
<dependencies>
<module name="com.dr_dee_sw.campaigner" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
Related
I have developed a maven-based project (maven-3.3.9) using jboss-eap-6.4 in IntelliJIDEA 14.0. I am using bouncy castle libraries and I have to set them as provided scope in maven dependency.
Where exactly should I put the bouncy castle jar files?
What configuration should I set?
I have tried two options for the 1st question as follows:
I put jar files here: jboss-eap-6.4\modules\org\bouncycastle\main\
and
I put jar files here: jboss-eap-6.4\modules\system\layers\base\org\bouncycastle\main\
Also, I have provided the following configuration in module.xml beside the jar files:
<?xml version=1.0" encoding=UTF-8"?>
<module xmlns="run:jboss:module:1.1" name="org.bouncycastle">
<resources>
<resource-root path="bcpkix-jdk15on-1.54.jar"/>
<resource-root path="bcprov-jdk15on-1.54.jar"/>
</resources>
<dependencies>
<module name="javax.api" slot="main" export="true"/>
</dependencies>
</module>
However, when I clean and install maven I get the following error:
error during artifact deploment
caused by java.lang.RunTimeException:...
caused by java.lang.NoClassDefFoundError:...
caused by java.lang.ClassNotFoundException:...
The errors you mentioned are deployment errors those are not related to maven.
To add a JBoss module to your application create a file named WEB-INF\jboss-deployment-structure.xml and add the module in dependency. In your case the file content should be as follows.
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.bouncycastle"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
The while deployment jboss will load the module in to classpath.
I have .war using Jersey REST, and it works in tomCat. But I need to run my .war in JBoss 6.4.0 which causes an exception
java.lang.RuntimeException: java.lang.NoSuchMethodError:
javax.validation.spi.ConfigurationState.getParameterNameProvider()
because JBoss uses old version javax.validation, and I need to exclude javax.validation from deployment of JBoss.
I create jboss-deployment-structure.xml in WEB-INF of .war:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="resteasy" />
<subsystem name="jpa"/>
<subsystem name="org.hibernate" />
<subsystem name="org.hibernate.validator" />
</exclude-subsystems>
<exclusions>
<module name="javaee.api" />
<module name="javax.ws.rs.api"/>
<module name="org.jboss.resteasy.resteasy-jaxrs"/>
<module name="javax.validation.api"/>
<module name="org.hibernate"/>
<module name="org.hibernate.validator"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
This helped me to exclude javax.ws.rs, but How can to exclude javax.validation? Help me, please
Ok, so You need to exclude not only
<module name="javax.validation.api"/>
itself, but also modules that are dependent on javax.validation.api module. The easiest way to see which modules are dependent on javax.validation.api and force it to be included, even though it was excluded, is to search your .xml files in
JBOSS_DIRECTORY/modules for javax.validation.api, the modules that are dependent have something like that in module.xml:
<dependencies>>
<module name="javax.validation.api"/>
...
And those modules need to be excluded as well. For me - I also needed to exclude:
<module name="javax.faces.api"/>
<module name="org.jboss.resteasy.resteasy-hibernatevalidator-provider"/>
And then, javax validation eclusion was working :)
So, it is something! May be help to someone:
Library javax.validation.api in JBoss - belongs to Implicit module, documentation about implicit module: implicit module dependencies
So implicit modules are Automatic Dependencies, and their can exclusion, about this: class lading and automatic dependencies - part about Automatic Dependencies:
Automatic dependencies can be excluded through the use of jboss-deployment-structure.xml. But this is not work! :(, and JBoss has bug with similar library javax.persistence, and it bug open in tasks.
So - what can to do?
Update JBoss to 7.0.0 version, but now just Alpha and Beta versions :(
Replace old javax.validation.api .jar on new version .jar
(in EAP-6.4.0/modules/system/layers/base/javax/faces/api/main)
Add custom version, and it tangled:
change default config in EAP-6.4.0/modules/system/layers/base/javax/faces/api/main module.xml file, in line <module name="javax.validation.api" export="true"/> remove option export="true", result: <module name="javax.validation.api"/> This changed to allow you add a new custom library javax.validation.
And create custom folder with name 1.1 in EAP-6.4.0/modules/system/layers/base/javax/validation/api, put in 1.1 folder new javax.validation .jar and model.xml.
model.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="javax.validation.api" slot="1.1">
<resources>
<resource-root path="validation-api-1.1.0.Final.jar"/>
</resources>
<dependencies>
<module name="org.jboss.logging"/>
</dependencies>
</module>
params:
slot - name custom folder (1.1),
path - path to .jar library
Last: add module to jboss-deployment-structure.xml in project:
<dependencies>
<module name="javax.validation.api" slot="1.1" export="true"/>
</dependencies>
I am migrating an EAR application from JBoss 6.1.0 AS to Wildfly 8.2.0 AS. EAR contains log4j.xml and application logs are generated by using this logging configuration file by employing the below line of code:
org.apache.log4j.xml.DOMConfigurator.configureAndWatch(log4j file path)
Application logs are generated fine but in server.log, application logs are also getting appended. I am using standalone-full-ha.xml configuration file and tried the below steps:
Added jboss-deployment-structure.xml with the following contents:
<deployment>
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
</deployment>
Added below lines under <subsystem xmlns="urn:jboss:domain:logging:2.0"> section
in standalone-full-ha.xml.
<use-deployment-logging-config value="true"/>
<add-logging-api-dependencies value="false"/>
How can I prevent applications logs getting appended in server.log ? Please help.
Workaround tried
Just adding to my previous comments, I tried first option provided in the link http://www.mastertheboss.com/jboss-server/jboss-log/using-log4j-with-jboss-as-7-and-wildfly.
Added log4j.xml under META-INF of EAR.
Added org.apache.log4j module as one of the dependencies attribute in MANIFEST.MF.
It was mentioned to add a VM argument -Dorg.jboss.as.logging.per-deployment=true but I did not add.
server.log is generated fine and application logs are getting generated fine but I have below concerns:
is the starting tag in log4j.xml and it has "warn" as value of threshold attribute. But, I am getting all kind of logs (i.e. works as ALL or DEBUG threshold).
I have placed log4j.xml in META-INF of EAR. So, will org.apache.log4j.xml.DOMConfigurator.configureAndWatch(log4j file path) work where path denotes log4j.xml in META-INF ? Default time out is 60 seconds and if I change threshold, will it reflect ?
I use following jboss-deployment-structure.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--https://github.com/wildfly/wildfly-core/blob/master/server/src/main/resources/schema/jboss-deployment-structure-1_2.xsd-->
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
<exclusions>
<module name="org.apache.commons.logging"/>
<module name="org.apache.log4j"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.logging.jul-to-slf4j-stub"/>
<module name="org.jboss.logmanager"/>
<module name="org.jboss.logmanager.log4j"/>
<module name="org.slf4j"/>
<module name="org.slf4j.impl"/>
</exclusions>
</deployment>
I'm trying to setup a CORBA enabled application on JBoss 7.1.1 Final. It seems that I'm missing something because everything I try results in another exception. So, what I tried:
standalone -c standalone-ha.xml -Djboss.node.name=nodeA or
standalone -c standalone-full-ha.xml -Djboss.node.name=nodeA
then the 2nd line here
GlobalData.orb = org.omg.CORBA.ORB.init(args, p);
orb.resolve_initial_references("NameService");
throws the exception:
(MSC service thread 1-9) IDL:omg.org/CORBA/ORB/InvalidName:1.0: org.omg.CORBA.ORBPackage.InvalidName: IDL:omg.org/CORBA/ORB/InvalidName:1.0
at org.jacorb.orb.ORB.resolve_initial_references(ORB.java:1343) [jacorb-2.3.1.jbossorg-1.jar:]
at MyApp.startServer(MyApp.java:145) [server.jar:]
My /conf folder contains a jacorb.properties with the entry
ORBInitRef.NameService=corbaloc::localhost:3828/JBoss/Naming/root
Can anyone bring some light into the dark?
Thanks, Peter
I found solution for that problem, Jacorb require mandatory configuration (jacorb.propeity)
you can get that file from JBoss 4.2.2
Then
you need to include that file in your class path, to do that we create custom module
for instance go to jboss modules directory
create sub directory custom/myconfig/main for example
there add your property files
create module.xml file .. you will chose module name... for instnace custom.myconfig
<module xmlns="urn:jboss:module:1.1" name="custom.myconfig">
<properties>
<property name="jboss.api" value="private"/>
</properties>
<resources>
<resource-root path="."/>
<!-- Insert resources here -->
</resources>
<dependencies>
</dependencies>
</module>
In your jboss-deployment-structure.xml include this module to your app
<jboss-deployment-structure>
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<deployment>
<dependencies>
<module name="custom.myconfig/>
</dependencies>
<resources>
</resources>
</deployment>
<sub-deployment name="My_WAR.war">
<dependencies>
<module name="custom.myconfig" />
</dependencies>
</sub-deployment>
Hope that help as it work with me
I'm am having trouble logging using my appenders defined on my XML log4j configuration file.
I created the jboss-deployment-structure.xml on my EAR's META-INF folder with no sucess.
The jboss-deployment-structure.xml structure is:
<jboss-deployment-structure>
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<deployment>
<exclusions>
<module name="org.apache.log4j" slot="main"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
I have even tried to edit my standalone.conf.bat file adding the following line:
set "JAVA_OPTS=%JAVA_OPTS% -Dorg.jboss.as.logging.per-deployment=false"
My application deployment is like this:
-> MyAppEAR.ear
-> META-INF
-> MANIFEST.MF
-> MyAoo.war
-> META-INF
-> MANIFEST.MF
-> jboss-deployment-structure.xml
-> WEB-INF
-> web.xml
-> lib
-> log4j-1.2.17.jar
-> ---
-> classes
-> log4j.xml
-> ...
I've noticed the following error:
jboss-deployment-structure.xml in subdeployment ignored. jboss-deployment-structure.xml is only parsed for top level deployments.
I even tried migrating from JBOSS 7.1.0 to 7.1.1
Some help please!
Thanks
Thanks for the repply James.
I did what you said and moved the jboss-deployment-structure.xml file to MyAppEAR.ear/META-INF.
I've noticed that this way the exception:
jboss-deployment-structure.xml in subdeployment ignored. jboss-deployment-structure.xml is only parsed for top level deployments.
... doesn't occur. I don't know if that means that the file was parsed... how can I tell?
Despite of this new behaviour my log4j.xml configuration file still isn't loaded and the logger used still is Log4J's.
I know this becaused I wrote to the console:
System.out.println(Logger.getRootLogger().getClass().toString())
...and got:
class org.jboss.logmanager.log4j.BridgeLogger
I've also tried:
moving my log4j.xml to MyAppEAR.ear/META-INF.
removing the unecessary -Dorg.jboss.as.logging.per-deployment=false from standalone.conf.bat
removing slot from my jboss-deployment-structure.xml
Any more ideas?
Thanks
Hi RedEagle see the following configuration which i have tested and its working fine...
Step-1
Create a new module as
jboss-as-7.1.1.Final/modules/com/company/mylog/main/
-module.xml
-log4j-1.2.14.jar
Content of module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.company.mylog">
<resources>
<resource-root path="log4j-1.2.14.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
Step-2
Now IN my.ear/META-INF/
-jboss-deployment-structure.xml
-MANIFEST.MF
content of jboss-deployment-structure.xml
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
<sub-deployment name="MyWeb.war">
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</sub-deployment>
<sub-deployment name="MyBeans.jar">
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</sub-deployment>
</jboss-deployment-structure>
Content of MANIFEST.MF
Manifest-Version: 1.0
Dependencies: com.company.mylog
Step-3
Content of MyLogger.java
public static Logger getLogger(String name) {
Logger logger= LogManager.getLogger(name);
PropertyConfigurator.configure("log4j.properties"); //Path to log4j.properties as many option available in my case for testing i used static path /home/gyani/log4j.properties
return logger;
}
Step-4
Here is log4j.properties
log4j.rootLogger=info,gyani
log4j.appender.gyani=org.apache.log4j.RollingFileAppender
log4j.appender.gyani.File=/home/gyani/myserverlog.log
log4j.appender.gyani.Append=true
log4j.appender.gyani.MaxFileSize=100000KB
log4j.appender.gyani.MaxBackupIndex=10
log4j.appender.gyani.layout=org.apache.log4j.PatternLayout
log4j.appender.gyani.layout.ConversionPattern=[%d{MMM d HH:mm:ss yyyy}] [%-5p] [%c]: %m%n
Your jboss-deployment-structure.xml needs to be in your MyAppEAR.ear/META-INF directory. There is also no need for the slot attribute for this case.
Also the -Dorg.jboss.as.logging.per-deployment=false isn't used in JBoss AS 7.1.1.Final, but it doesn't hurt anything either.