Howto reach logback.xml in an Eclipse RCP plugin? - java

I created an Eclipse RCP "Hello World"-Plugin, it's running and showing me the main window, then I created a second plugin called "logging" with the logback libraries and added this logging-plugin as a dependency to the main plugin.
The main plugin now knows the logger-classes, and I can use them, but how do I reach the "logback.xml"-file from the main plugin? This file is stored in the "resources"-folder in the logging-plugin.
-mainplugin <---knows logging classes, but not reaching logback.xml
-logging
|-libs
|-resources
|-logback.xml

logback.xml is a configuration file for your logging, the one where you set log level ect. ... right? In this case it belongs to the mainplugin, not to the logging plugin (which would only expose the methods of the jar file in the libs folder).
Like this:
-mainplugin
|-resources
|-logback.xml
-logging
|-libs
In order to work you would have to set buddy policies in your plugins and lockback.xml have to be in the classpath (!). This is required to allow the logging plugin to find the lockback.xml inside your plugin without to have a direct dependency.
in the MANIFEST.MF of the logging plugin you would have to add:
Eclipse-BuddyPolicy: registered
In the MANIFEST.MF of your mainplugin you would have to add:
Eclipse-RegisterBuddy: org.logplugin.id
with org.logplugin.id being the id of your logging plugin.
For more information: http://www.eclipsezone.com/articles/eclipse-vms/

A more introductory, including another two approaches, is described at http://devblog.virtage.com/2012/07/logback-and-eclipse-attaching-logback-xml/.

Related

Akka: unable to read configuration in karaf

I am using Akka actors for Remote communication in karaf.
When I deploy the jar file generated after compiling using maven, I get the following error:
Exception in thread "Thread-113"
com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'
at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:152)
at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:170)
at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:176)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:184)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:189)
at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:246)
at akka.actor.ActorSystem$Settings.(ActorSystem.scala:168)
at akka.actor.ActorSystemImpl.(ActorSystem.scala:522)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:142)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:119)
at org.opendaylight.com.test.rem$$anon$1.run(rem.scala:19)
I even added Maven shade plugin in the pom file which was suggested in other answers, but adding the plugin makes all the karaf features to change to ''Resolved'' state. The configuration file for akka is in the classpath too. As of my knowledge, the akka configuration file is not being read at all, as I got the same exception even after removing the configuration file.
This error is most often caused by combining multiple Akka jars into a single super-jar and not handling the reference.conf files correctly. The reference.conf file in each of the Akka module jar-files needs to be concatenated into a single file in the super jar.
Follow the instructions in the docs here: https://doc.akka.io/docs/akka/current/scala/general/configuration.html#when-using-jarjar-onejar-assembly-or-any-jar-bundler
And then verify that the jar-file you use when running has the contents of all those reference.conf files concatenated into a single file.

Ignore dependency log4j.properties

I have a web application deployed on WildFly 10. After adding a new Maven dependency to my application, logging stopped working. Investigating, I've found that the new dependency includes a log4j.properties in its JAR, and I guess this is causing the logging to screw up.
I cannot delete the file from the JAR, since every time my project compiles it would come back. I need WildFly to manage the logging properties, so adding an additional log4j.properties isn't an option (it would be if it can be configured to fallback to WildFly defaults, but I don't know if this is possibile).
How can I ignore a dependency's log4j.properties or override it with WildFly's settings?
If your app does not use is own log4j properties file or xml, you are best just disabling the per-deployment logging configuration option on wildfly, then any will be ignored
You can exclude Logging module from you jar.
dependencies {
compile group : 'com.chapter1' name: 'common.all', version: '1.0.001'{
exclude( // here u can exclude that module... )
}
In WildFly 10 you can set the use-deployment-logging-config on the logging subsystem to false which will skip processing any logging configuration files. Do note this will skip processing on all deployments.

Vaadin widgetset path is changed after updating to 7.7.0

In my Vaadin application, I have my own widgetset specified like below in web.xml
<init-param>
<param-name>widgetset</param-name>
<param-value>com.foo.bar.AppWidgetSet</param-value>
</init-param>
And, I had placed my AppWidgetSet.gwt.xml file in src/main/java/com/foo/bar/AppWidgetSet.gwt.xml
This setup worked fine until I upgraded to vaadin 7.7.0 (from 7.6.8). After upgrade, I got following error, when I try to access the app through a browser.
INFO: Requested resource [/VAADIN/widgetsets/AppWidgetset/AppWidgetset.nocache.js] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.
It seems like vaadin is looking for a different location for the widgetset, so I placed my AppWidgetSet.gwt.xml in the root of the classpath (src/main/java/AppWidgetSet.gwt.xml) and re-built the app.
Then it worked again.
Is specifying the widgetset as an init param no longer available? Do I have to place the widgetset xml in the root of the classpath itself?
I have similar issues after upgrading my Vaadin application from 7.6.8 to 7.7.2. I've noticed that package under src/main/resources started to multiply recursively :
Below was the state with version 7.6.8, prior updating POM to 7.7.7 :
src/main/resources
myPackage
MyAppWidgetset.gwt.xml
After updating POM to 7.7.7, under "myPackage" appeared new "myPackage" with xml file ! Just to emphasize that after every rebuild, those folders constantly creating and creating, so after 4th build there are more than 10 subfolders !
src/main/resources
....myPackage
........myPackage
................MyAppWidgetset.gwt.xml
................................myPackage
................................................MyAppWidgetset.gwt.xml
...
MyAppWidgetset.gwt.xml
It seems as if there is a bug in 7.7.2 as regards custom widgetsets. First, check if you really need them. With no client side custom widgets, just forget any widgetset annotations or any related web.xml parametrization and let Vaadin make use of its new default AppWidgetset. If not, consider refactoring and converting custom client stuff into separate projects, installed in local Maven repo and then used via dependency, still not putting any own gwt.xml anywhere in main project's path. Finally, if none of above may be used (as in my case, too), just wait for bug fix in 7.7.3.
See: https://dev.vaadin.com/ticket/20320
As I noticed, new 7.7.2 plugin does not put anything into source (i.e. /VAADIN/widgetsets), but stores compiled JS directly in output artifact and war archive. So, the workaround for #Lahiru Chandima could be not rely entirely on new, ascetic 7.7.2 plugin and make use of some old elements like <webappDirectory> and/or <hostedWebapp>, mentioning ${basedir}/src... locations.
For #dobrivoje I'd recommend doing compilation as needed, then remove surprisingly created unnecessary (nested) packages and xml file and forget client compilation for some time (is it really needed in every build?) by commenting out Maven goals:
<!-- goal>update-widgetset</goal>
<goal>compile</goal -->

Maven shade - repackage dependecy jar with custom configuration

I have a common service which is packaged as a jar with all it's dependencies.
Consumer1, consumer2, consumer3 provides different configuration for Common_service.
What is the best way to repackage common_service with all it's jar content and in addition, bundle the configuration with it.
Final output, on Consumer1 would give :
Consumer1-shaded.jar (without common-service)
Consumer1-Common-service.jar (only common-service with custom configuration)
Consumer2 would give :
Consumer2-shaded.jar (without common-service)
Consumer2-Common-service.jar (only common-service with custom configuration)
I tried maven shade to repackage common_service, but I need to explicitly include all the dependencies of common service in consumer., Why should the consumer be aware of the common service contents ? Is there any direct way to take the jar, add config and repackage ?
To get what you want, probably your best bet is to have four maven modules. The common_service module would no longer produce a shaded jar, just a regular jar. The consumer_1 module would include the configuration files and have common_service as a dependency, and would produce a shaded jar. The consumer_2 and consumer_3 modules would be set up similar to the consumer_1 module.

Adding classpath to jetty running in maven integration-test

I'm trying to set up integration tests for a Maven project that produces a war file. (As seen here http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin/.) However I the war file requires a bunch of .properties files on the classpath, that I don't want to bundle in the war.
Is there a way (preferably through plugin configuration) to add a folder to the classpath used by jetty?
I Googled this and found http://markmail.org/message/awtqrgxxttra3uxx but this, as far as I can tell, does not actually work at all. The .properties files are not found.
This should be possible using the webAppConfig configuration element (sample below taken from this thread):
<webAppConfig>
<contextPath>/nportal</contextPath>
<!-- All I want to do here is add in the /etc/jetty/classes for runtime files. For some reason I have to also add back in the /target/classes directory -->
<extraClasspath>${basedir}/target/classes/;${basedir}/etc/jetty/classes/</extraClasspath>
</webAppConfig>
If you find that the above solution doesn't work for you, consider including the test classpath into your Jetty configuration.
<configuration>
<useTestClasspath>true</useTestClasspath>
...
</configuration>
This will then allow you to place all manner of resources/classes on the test classpath and have them visible to the Jetty server without them creeping into the production code.
You can place your additional configuration files under /src/test/resources and set a property <useTestScope>true</useTestScope> in the plugin configuration as specified here:
useTestScope
If true, the classes from testClassesDirectory and dependencies of scope "test" are placed first on the classpath. By default this is false.

Categories

Resources