Migrating old JSP to Facelet (managed bean not instantiated) [duplicate] - jsf-2

I'm creating my first project Java EE 7, but I'm having trouble. Appreciate any help.
Tomcat 7.0.34
JSF 2.2
Primefaces 3.5
javaee-api-7.0.jar
When the application start, the Tomcat log shows the following message:
"validateJarFile (C:\...\build\web\WEB-INF\lib\javaee-api-7.0.jar)-jar not loaded. See Servlet 2.3 Spec, section 9.7.2. Offending class: javax/servlet/Servlet .class"
when I click on the button that calls the managed bean, I get the error:
AdvertĂȘncia: /index.xhtml #18,66 value="#{indexMB.user}": Target Unreachable, identifier 'indexMB' resolved to null
javax.el.PropertyNotFoundException: /index.xhtml #18,66 value="#{indexMB.user}": Target Unreachable, identifier 'indexMB' resolved to null
IndexMB
#Named("indexMB")
#RequestScoped
public class IndexMB {
private String password;
private String user;
public String loginTest(){
return (this.user.equals("admin") ? "adminPage" : "inOutPage");
}
// getters and setters
}
index.xhtml
<html ...>
<f:loadBundle basename="i18n" var="bundle" />
<h:head>
<title>#{bundle['index_title']}</title>
</h:head>
<h:body>
#{bundle['index_appname']}
<br />
<h:form id="frmIndex">
<p:panelGrid columns="2">
<p:outputLabel for="user" value="#{bundle['lblUser']}" />
<p:inputText id="user" value="#{indexMB.user}" />
<p:outputLabel for="password" value="#{bundle['lblPassword']}" />
<p:password id="password" value="#{indexMB.password}" />
</p:panelGrid>
<p:commandButton action="#{indexMB.loginTest}" value="#{bundle['btn_login']}" />
</h:form>
</h:body>
faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<locale-config>
<default-locale>pt_BR</default-locale>
<supported-locale>en</supported-locale>
<supported-locale>fr</supported-locale>
</locale-config>
</application>
These topics have not helped me:
Java EE 6 #javax.annotation.ManagedBean vs. #javax.inject.Named vs. #javax.faces.ManagedBean
Target Unreachable identifier resolved to null
Target Unreachable, identifier resolved to null
javax.el.PropertyNotFoundException : Target Unreachable, identifier 'login' resolved to null Spring + JSF
http://www.andrejkoelewijn.com/blog/2010/03/05/jee-cdi-tip-target-unreachable-identifier-resolved-to-null/

Tomcat as being a barebones JSP/Servlet container doesn't support CDI out the box. It is not correct to drop jakartaee-api.jar or javaee-api.jar in /WEB-INF/lib just to get your code to compile. The JEE API JAR contains solely the API classes, not the concrete implementation. Get rid of the whole JAR. It can cause many other portability troubles like as the ones described in this answer: How do I import the javax.servlet / jakarta.servlet API in my Eclipse project? You should actually be installing the concrete implementation along with the specific API.
You have 2 options:
Drop Tomcat and go for a true Jakarta EE container. As you're using Tomcat, just step over to TomEE. It's really simple, download the TomEE web profile zip file, extract it and integrate it in Eclipse exactly the same way as you did for Tomcat. Don't forget to remove the Jakarta EE JAR file from webapp and alter the Targeted Runtime property in project's properties from Tomcat to TomEE so that Jakarta EE dependencies are properly resolved. See also What exactly is Java EE?
No additional JARs or configuration is necessary. You can even remove the manually installed JSF/JSTL/CDI/BV/JPA/EJB/JTA/JSONPJAX-RS/etc/etc libraries from your webapp. TomEE as being a true Jakarta EE container already provides them all out the box. In case you're using Maven, the below coordinate is sufficient.
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version><!-- e.g. 10.0.0 or 9.1.0 --></version>
<scope>provided</scope>
</dependency>
Note the importance of provided and its meaning as in "the target runtime already provides this out the box". See also How to properly configure Jakarta EE libraries in Maven pom.xml for Tomcat? for detailed pom.xml examples of Tomcat and normal JEE containers.
If you want to stick to Tomcat, then you need to manually install a true CDI implementation via the webapp. Below instructions assume Tomcat 10+. Weld is one of the available CDI implementations. In the Weld installation guide you can find instructions how to integrate it in Tomcat. For sake of completeness and future reference, here are the steps:
For Tomcat 10.1.x, drop the weld-servlet-shaded.jar of version 5.x in webapp's /WEB-INF/lib. In case you're using Maven, use this coordinate:
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-shaded</artifactId>
<version>5.1.0.Final</version>
</dependency>
For Tomcat 10.x, use weld-servlet-shaded.jar of version 4.x instead:
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-shaded</artifactId>
<version>4.0.3.Final</version>
</dependency>
Optionally, create a /META-INF/context.xml file in webapp with following content:
<Context>
<Resource name="BeanManager"
auth="Container"
type="jakarta.enterprise.inject.spi.BeanManager"
factory="org.jboss.weld.resources.ManagerObjectFactory"/>
</Context>
This step is is only necessary when the CDI-dependent library tries to manually find it in JNDI. This step is not necessary when you're using for example Jakarta Faces / JSF version 2.3 or newer.
Create a /WEB-INF/beans.xml file in webapp to trigger activation of CDI. It can be kept empty.
That's it.
In case you prefer OpenWebBeans above Weld as CDI implementation, or need to install CDI in Tomcat 9.x or older, head to this blog for detailed Maven installation instructions: How to install CDI in Tomcat?

Other possible option is leaving beans.xml in your deployment.

Related

Grails 5.2 can't deploy to JBoss EAP 7.4

Grails 5.2
create-app helloworld
create-controller hello (add render "Hello"
line)
Add the jboss-deployment-structure.xml file to WEB-INF folder for JBoss logging compatibility.
run-app (works)
war
Deploy to JBoss EAP 7.4 and get following error
ERROR [org.springframework.boot.SpringApplication] (ServerService Thread Pool -- 85) Application run failed: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.context.event.ApplicationEventPublisher<io.micronaut.context.event.StartupEvent>] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2778)
I did set the logging level to TRACE for is.micronaut.context.condition but nothing is logged at the TRACE level.
The JBoss jboss-deployment-structure.xml file that I added, which I think is standard for JBoss EAP, looks like this. I do not believe this is related, I'm just including it here so that others can reproduce what I did to generate the war file.
<jboss-deployment-structure>
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.slf4j" />
<module name="org.slf4j.impl" />
</exclusions>
</deployment>
How can I make a grails 5 app deployable to JBoss EAP 7.4?

Azure function V3 could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0 with EF core 5.0-rc1

Case
We are creating azure function v3 with .netcore 3.1. Using EF core 5.0-rc1 and Depdency Injection
1) DependecyInjection
[assembly: FunctionsStartup(typeof(xxxxx.Startup))]
namespace xxxxx
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var services = builder.Services;
var configBuilder = new ConfigurationBuilder()
.SetBasePath(Environment.CurrentDirectory)
.AddJsonFile("local.settings.json", true, reloadOnChange: true)
.AddEnvironmentVariables() ;
ConfigureServices(services);
ConfigureAppSettings(services, configBuilder.Build());
ConfigureLogging(services, configBuilder.Build());
}
}
}
2) EF core 5.0 rc-1
https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-efcore-5-0-rc1/
Error
Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Packages
Following are the packages referenced
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0-rc.1.20451.14" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Troubleshooting
commenting the following line in startup.cs (Dependency injection) solves the problem
[assembly: FunctionsStartup(typeof(xxxxx.Startup))]
The Microsoft.Azure.Functions.Extensions depends on .net standard 2.0.
While the Entity Framework Core 5.0 RC1 will not run on .Net standard 2.0 platforms, it requires .net standard 2.1. So it could not find the Microsoft.Azure.Functions.Extensions.
For more details, you could refer to this article.
If you are using .NET core 3.1 or below that. Downgrade the NuGet packages of Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.DependencyInjection.Abstractions to 3.x.x.
It's not supported in Azure Function v3, yet.
https://github.com/Azure/azure-functions-vs-build-sdk/issues/472
But, if you want to test it locally, I was able to run updating the DLL's in the Azure Function Core Tools directory:
C:\Program Files\Microsoft\Azure Functions Core Tools
I needed to replace/update these Dll's to use EF5 with my functions:
Dll's list
Microsoft.Extensions.DependencyInjection.Abstractions.dll
Microsoft.Extensions.Logging.Abstractions.dll
Microsoft.Extensions.Options.dll
Microsoft.Extensions.Primitives.dll
I switched my Azure function to an isolated process, which supports .NET 5.0. This only came about recently (March 2021). It looks like .NET 5.0 won't be supported in-process as far as I can tell (.NET 6.0 will be). There is a guide published here, I've listed the steps I took along with that for an existing project.
Steps
In .csproj, target .NET 5.0 (<TargetFramework>net5.0</TargetFramework>) and add <OutputType>Exe</OutputType>. Switch to the following packages:
Microsoft.Azure.Functions.Worker
Microsoft.Azure.Functions.Worker.SDK
Also replace Microsoft.Azure.WebJobs.Extensions.* with Microsoft.Azure.Functions.Worker.* ones.
In local.settings.json change runtime to: "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated".
Add Program.cs if you don't have one. Use the following:
public static class Program
{
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services => {
// Add your services here...
})
.Build();
host.Run();
}
}
In your triggers, you'll need to update [FunctionName("Example")] to [Function("Example")], and update your using statements to Microsoft.Azure.Functions.Worker ones.
There some differences between .NET Core 3.1 and .NET 5.0 support listed at the bottom of that article here which is worth reviewing before making changes! Dependency injection is supported out the box though in the "normal" sense. I think it might be possible to rework Program.cs to use your existing startup.
Debugging
To debug the program, you can run the function using the Azure Function CLI and attach a Visual Studio debugger.
Open terminal in CSProj directory.
Run func start --dotnet-isolated-debug.
When the app runs, you need to look for the process ID, or PID. The line looks something like " Azure Functions .NET Worker (PID: ###)".
In Visual Studio. Debug > Attach to Process..., search by the PID in the previous step (dotnet.exe) and Attach.
Further reading
The documentation seems a bit sporadic, I also found another guide on developing and publishing .NET 5.0 Azure functions here.
There is this issue which sheds some more light on what is going on.
I have a .Net Standard 2.1 lib project with a service that is injected into my function app. In my solution the lib referenced:
Microsoft.Extensions.Options v5.0.0
After I changed the package version to 3.1.11, my function app ran successfully. In other words, if any project referenced by your function app has a reference to a .Net 5.0 package, it looks like you will get this exception if you are using DI.
Current versions in my function app:
Function app: .Net Core 3.1
Azure Functions Version: 3
Other libs: .Net Standard 2.1
I started with .Net 5.0 for the function app but apparently that is not supported for now:
.NET 5 support on Azure Functions
Hopefully this answer will be obsolete before too long but as of Jan 24, 2021 don't use .Net 5.0 projects or package references in your Azure function app solution/projects.

Configuring ucanaccess driver on wildfly 8.0

I am trying to create a web application using MS Access as database. For it, I am using ucanaccess driver and my server is Wildfly 8.0
The issue is to how correctly configure this driver on the server ?
After researching on internet I got to know below steps
create a folder structre and place all the ucanaccess jar files-
wildfly-8.0.0.Final\modules\system\layers\base\com\ucanaccess\jdbc\main
Edit module.xml file-
<module xmlns="urn:jboss:module:1.1" name="com.ucanaccess.jdbc">
<resources>
<resource-root path="ucanaccess-2.0.9.4.jar"/>
<resource-root path="commons-lang-2.6.jar"/>
<resource-root path="commons-logging-1.1.1.jar"/>
<resource-root path="hsqldb.jar"/>
<resource-root path="jackcess-2.0.8.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
Edit standalone-full.xml file
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jndi-name="java:jboss/MyDS" pool-name="MyDS" enabled="true" use-java-context="true">
<connection-url>jdbc:ucanaccess://C://Users//sahashu//Documents//NGCORE.accdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>ucanaccess-2.0.9.4.jar</driver>
<security>
<user-name></user-name>
<password></password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="ucanaccess" module="com.ucanaccess.jdbc">
<xa-datasource-class>org.ucanaccess.jdbc.MsAccessDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
However, still I get this error-
23:29:34,422 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 28) JBAS014613: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "ucanaccess")
]) - failure description: "JBAS010441: Failed to load module for driver [com.ucanaccess.jdbc]"
Please help me to identify the issue
Thanks
There is an easier way: Just create your own JAR using the UcanAccess JAR files.
In Eclipse:
Create a plain Java Project (for Java 8)
Create a dummy class with a dummy main method, and execute it (for example a simple Hello World program)
Right-click on the project -> Build Path -> Configure Build Path
Go to the Libraries tab and use "Add External JARs" to add all 5 JARs that you find in your UcanAccess download
Right-click on the project -> Export -> Java / Runnable JAR file, choose your dummy class as Launch configuration, and keep Library handling as "Extract required libraries..."
Now go to your WildFly administration console, and click on "Deployments". There you can add your freshly baked JAR and enable it. WildFly will recognize this driver automatically from now on, when you need to add a Microsoft Access Datasource using the Wizard in the administration console.

Upgrade WebLogic 10.3.0 to JSF 2 via webapp-provided JAR

I have a Java EE 5 Web Application running on WebLogic 10.3.0.
I want to use JSF 2.x, but WebLogic 10.x only supports JSF 1.2.
So I did the following in order to use JSF 2.x instead.
I deployed a WAR cointaining those JARs:
wls.jsf.di.jar
glassfish.jstl_1.2.0.1.jar
javax.jsf_1.0.0.0_2-0.jar (jsf 2.0)
glassfish.jsf_1.0.0.0_2-0-4.jar
I added the following JARs to build path purely for compilation:
javax.faces-2.1.26.jar
jstl-1.2.jar
Created a Servlet 2.5 compatible web.xml and a weblogic.xml (1.0).
Included this in weblogic.xml:
<library-ref>
<library-name>jsf</library-name>
<specification-version>2.0</specification-version>
<implementation-version>1.0.0.0_2-0-2</implementation-version>
<exact-match>false</exact-match>
</library-ref>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
For EL 2.2-like method arguments support in EL 2.1, I added this JAR:
jboss-el-2.0.0.GA.jar
And placed this in web.xml:
<context-param>
<param-name>com.sun.faces.injectionProvider</param-name>
<param-value>
com.sun.faces.vendor.WebContainerInjectionProvider
</param-value>
</context-param>
After all this changes WebLogic Console is still saying the following:
Initializing Sun's JavaServer Faces implementation (1.2_03-b04-FCS)
for context
As you can see, it is still using JSF 1.2. What else can i do to fully use JSF 2?
Well, after doing some tests i was really using JSF 2! So yes, that is enough to make Weblogic 10.3.0 work with JSF 2. I don't remember if i got rid of the "Initializing JSF 1.2" message tho, i recommend to just ignore it

TF215097 Custom Build Activities using Com Interop on 64 bitsTF215097: An error occurred w

TF215097: An error occurred while initializing a build for build definition {DefinitionName}: The invocation of the constructor on type 'Classname' that matches the specified binding constraints threw an exception.
OK some had already answered this very well:
TFS 2010 Custom Build Activity TF215097 error
I had the same issue before and corrected them by adding the correct attribute:
Microsoft.TeamFoundation.Build.Client.BuildActivity( Microsoft.TeamFoundation.Build.Client.HostEnvironmentOption.Agent )
My build is running well on x86 machine but give the error on 64 bit build controller or agent.
The Context :
I created several Build Activities. One of this activity is a Visual Build Pro runner activity. I referenced the Visual Build Professional 6 Server Object. (We have several project and could not update it... at this point)
When I build the assembly VS 2010 generate Native.{MyAssemblyName}.manifest
<?xml version="1.0" encoding="utf-8"?>
<assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity name="Native.EMI.TeamFoundation.Build" version="1.0.0.0" type="win32" />
<file name="VisBuildSvr.dll" asmv2:size="712904">
<hash xmlns="urn:schemas-microsoft-com:asm.v2">
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>aePKKx7BgE7vN7OjQqwrQ2bvex8=</dsig:DigestValue>
</hash>
<typelib tlbid="{c48285d5-e97e-4824-9e14-faf8124b00a4}" version="1.0" helpdir="C:\Program Files (x86)\VisBuildPro6\System\VisBuildPro.chm" resourceid="0" flags="HASDISKIMAGE" />
<comClass clsid="{d87ad38d-99d9-4e04-9505-696c3afde66c}" threadingModel="Both" tlbid="{c48285d5-e97e-4824-9e14-faf8124b00a4}" progid="VisBuildSvr6.Application" description="Visual Build Pro 6 server application component" />
<comClass clsid="{1cc058ff-793f-4560-9fad-48d88db93ca9}" threadingModel="Free" tlbid="{c48285d5-e97e-4824-9e14-faf8124b00a4}" progid="VisBuildSvr6.Builder" description="Visual Build core builder component (MTA)" />
<comClass clsid="{5ef3f30b-278b-4796-8f23-41fdd5ddc96c}" threadingModel="Both" tlbid="{c48285d5-e97e-4824-9e14-faf8124b00a4}" progid="VisBuildSvr6.BuilderSTA" description="Visual Build core builder component (MTA/STA)" />
</file>
</assembly>
And Interop.VisBuildSvr.dll assembly
When I trig a build on a Windows 64 bit Build Controller and Agent on the same machine I have the TF error.
I tried to attach the debugger on the controller and I am able to see the first error :
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
Additional information: Could not load file or assembly 'Interop.VisBuildSvr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d64ea679b6fd0408' or one of its dependencies. The system cannot find the file specified.
That file is on my custom assemblies folder on TFS and also on the BuildController and BuildAgent folder.
Thanks
From your comment, it looks like you got it working by configuring your build to invoke the 32-bit version of MSBuild. Is that right?

Resources