Jsf application in Apache Karaf 3.0.3 - jsf

I am very new at OSGI and trying to run jsf application on an OSGI Framework. For this purpose, I am trying to deploy ".war" file to apache karaf 3.0.3. Firstly, i installed war feature to karaf by using
feature:install -v war
command. Then, i moved my .war file to "deploy" folder of karaf. I got some dependency errors which avoid my war file to be active. So, i moved neccessary .jar files to deploy folder and managed to make my .war file "active". But when i try to reach .xhtml page by this link "http://localhost:8181/JavaServerFaces/hello.xhtml", i got "Not found" error. I examined log file of apache, and there was exception:
"java.lang.ClassNotFoundException:
org.apache.myfaces.webapp.StartupServletContextListener not found by
JavaServerFaces"
Despite removing these lines
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
from web.xml and redeploy .war file, i got same exception. What should i do to get rid of this error? Am i missing a basic thing of OSGI or something else?
Thanks for suggestions.

Please take a look at how the Pax Web Samples are doing it.
You'll need a OSGi ready version of an JSF implementation. Pax Web has been tested with myfaces.
A working JSF sample application can be found at the pax web samples
Beginning with Karaf 4 and Pax Web 4, there is a feature that'll install all required bundles. As you're using Karaf 3 right now, just take a look at the following list:
<bundle>mvn:org.apache.myfaces.core/myfaces-api/${jsf-myfaces.version}</bundle>
<bundle>mvn:org.apache.myfaces.core/myfaces-impl/${jsf-myfaces.version}</bundle>
<bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr250-1.0/2.0.0</bundle>
<bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr303-api-1.0.0/1.8.0</bundle>
<bundle>mvn:org.apache.geronimo.bundles/commons-discovery/0.4_1</bundle>
<bundle>mvn:commons-beanutils/commons-beanutils/1.8.3</bundle>
<bundle>mvn:commons-collections/commons-collections/3.2.1</bundle>
<bundle>mvn:commons-codec/commons-codec/1.8</bundle>
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-digester/1.8_4</bundle>
These are the required bundles to start with JSF in karaf.

Related

Added faces-config.xml but still getting Target Unreachable

I have a JSF app running on embedded jetty. It works when I run it from eclipse but not from command line. I realised it was because eclipse uses the folders and cli uses the jar. I assumed, after googling, it was because my jar was missing a faces-config.xml. I added one in the META-INF folder but I'm still getting Target unreachable errors for the beans in my xhtml.
How can I check that JSF is in fact scanning my jar for #ManagedBean?
Ps. I build my projects' jar with maven, copy it to my lib folder then run it from cli with java -cp "lib\*" com.test.MainSystem
After debugging AnnotationConfiguration I could see that Jetty only scans jars under WEB-INF.
Fortunately, they provide a method for adding external jars. Adding this got me up and running...
WebAppContext webapp = new WebAppContext();
// Add "this" jar to the list of jars to scan for annotations
String jarPath = JettyServer.class.getProtectionDomain().getCodeSource().getLocation().getPath();
webapp.setExtraClasspath(jarPath);

Jboss Fuse and Cobertura

I have my application which runs in Jboss Fuse on Linux. I deploy my artifacts as jar files under the /deploy directory. I was planning to make use of Cobertura to get code coverage report after executing my jmeter tests. I instrumented my jars and placed under /deploy. I ran my jmeter tests.
Now I am unable to find the location where .ser file will be present.
I tried searching inside fuse directory.
Can anyone help me in getting Cobertura working with Jboss Fuse?
For most versions of Cobertura, you can add:
-Dnet.sourceforge.cobertura.datafile=<filename>.ser
to the JBoss/JVM startup parameters (e.g. run.conf) to specify explicitly the file where you want the report to be created.
Also, you need to make sure the cobertura.jar itself is present in the classpath if you haven't done so yet.

External log4j property file with Jetty

I'm migrating a bunch of our webapps (run in Jetty) from log4j to slf4j. Previously, log4j would find the log4j.properties file from jetty.home/resources/log4j.properties. After moving to slf4j, the external log4j.properties file is not found and everything is getting logged to stderror.
If I build the same log4j.properties file inside the war, everything works as expected (and as it did previously). What am I doing wrong? I'd like to use an external logging config in jetty.home/resources as opposed to building it into the war.
In each webapp war, I have log4j-1.2.17, slf4j-api-1.7.10 and the binder slf4j-log4j12-1.7.10.
The Jetty start.ini is OPTIONS=Server,jmx,resources,websocket
I was able to resolve this by adding the -Dlog4j.debug java option to the start-up script. In doing so, I found that log4j was picking up a log4j.properties file from within the war that had been added for test.
The two options I found for fixing this were either remove the embedded config file, or add a start-up option. I was able to move module's log4j file to it's root so that it was excluded from the maven build. This way, it is still available locally (for test) but not built into the war.
The other option that worked was to add -Dlog4j.configuration=file:resources/log4j.properties
to the start-up options. This approach seems a bit convoluted but will override the embedded file.

Would JRebel work with this project setup?

we have a project where we use Maven to deploy to Tomcat on mvn clean install. I'm fairly new to Java development and finding it difficult to continually wait for install to complete to view changes. I use IntelliJ and I think the class files are only created during mvn install in the target directory.
Is it possible to use JRebel so when I save a file in IntelliJ the compiled class updates Tomcat immediately like they show on the JRebel video?
Thanks
IntelliJ saves the file automatically for you. All you need to do is to recompile the changed classes and these will be picked up by JRebel, given you have included rebel.xml configuration file into the deployed archive.

Error with cssparser-0.9.5.jar in Netbeans using richfaces/JSF

For some reason when I make minor chances to the title or anything linked to css I get the following error:
Deleting directory C:\Users...
C:\Users...\nbproject\build-impl.xml:1057: Unable to delete file
C:\Users...\build\web\WEB-INF\lib\cssparser-0.9.5.jar
BUILD FAILED (total time: 6 seconds)
Line 1057: <delete dir="${build.dir}"/>
I undid the changes but the error seems to persist.
Why would it want to delete the cssparser jar file?
What's the solution to the problem.
I am using Richfaces in JSF using Netbeans as my IDE, thanks.
By default, NetBeans does a Clean to the project, that means NetBeans will try to delete the compiled files and any libraries it has copied into the deploy directory. In Windows, NetBeans can't find the deploy dir and shows this error, specially when this dir is inside My Documents. I recommend you to change your project directory, or just performing Run or Debug, these commands will Compile, Build, Deploy and Launch your application so there won't be the Clean error.
For more info, see http://forums.netbeans.org/topic39444.html

Resources