Added faces-config.xml but still getting Target Unreachable - jsf

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);

Related

JRebel - sync new gradle jars on classpath

Can jrebel detect a jar file has been added to maven/gradle and then automatically add it my libs folder and add it to the classpath?
For example I'm running IntelliJ and Jetty and I make a gradle change to add a new version of a jar dependency and then click "gradle refresh."
Can jrebel be set up to load that jar? Otherwise this requires a full restart which partially makes jrebel less useful.
The short answer is no.
JRebel works by reloading individual class files, but not whole JARs.
If you add a new dependency or update the version of an existing dependency then it won't get reloaded.
However, if this library you're updating or adding is your own internal library that you build yourself, then it is possible to reload the changes.
In that case you need to build a rebel.xml file into the root of that library jar and configure it to point to the build directory of the library.

Jsf application in Apache Karaf 3.0.3

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.

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.

Build and include JSF taglib as jar in a Dynamic Web Project using Maven

I am working on a JSF taglib. To test it I compile it to a JAR as described here and add it manually to a Dynamic Web Project (In the WEB-INF/lib directory).
I know that this step can be automated, but I do not know how. Can anybody explain how to copy a generated jar to a second project in Eclipse?
Thanks in advance!
quite some steps to do :)
add a pom.xml into your project and follow the maven directory structure. use packaging "jar" for the taglib project. Lets assume you use groupId=com.company.taglib artifactId=company-taglib version=1.0.0-SNAPSHOT
if you do a mvn install on this project it will copy the jar into your local maven repository (usually found at ~/.m2/ - now maven can resolve the dependency on your local machine
add a pom.xml to your webproject, use packaging "war" and add the taglib project as a dependency (within <dependencies> in pom.xml).
<dependency>
<groupId>com.company.taglib</groupId>
<artifactId>company-taglib</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Maven will resolve this dependency from your local repository. In Eclipse using the m2e Plugin it will resolve the project directly.
To "publish" the taglib.jar you need an infrastructure to share artifacts. Usually using a repository proxy (Sonatype Nexus or Artifactory). You can also use a network folder using the file:// protocol for quick startup.
In the pom.xml you need to add the <distributionManagement> section (in the taglib pom.xml) to specify the folder / proxy the artifacts are uploaded to. A mvn deploy will then build and copy the jar file for you.
Other developers need to add that location as repository in settings.xml (I dont recommend doing that in pom.xml) or if you setup a maven proxy configure a mirrorOf in settings.xml
There are archteypes available (project templates) that will help you creating initial project structures: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
see also: http://maven.apache.org/guides/getting-started/index.html

Resources