How to define Context Path in Wildfly? - deployment

I've used the following code to set the Context Path in tomcat where I can access my application directly using localhost:8080 by overriding the tomcat's default path.
<Context path="" docBase="G:\bitbucket\projectpath\project\build\libs\project-1.0" workDir="G:\bitbucket\projectpath\project\build\libs\project-1.0\work" debug="0" reloadable="false" autoDeploy="true" unpackWARs="true" crossContext="true"/>
Now I'm going to use wildfly-8.2.0 as runtime environment. I tried by directly pasting the .war file into G:\wildfly-8.2.0.Final\standalone\deployments and I can access my project in browser like localhost:8080/project-1.0.
I need to setup the same configuration to wildfly like I've done in tomcat to access my project in localhost:8080 by overriding the wildfly's default welcome page. I tried to do the same in wildfly but I'm stuck where to do that. There are lot of .xml files in wildfly folder (when comparing with tomcat's simple server.xml file) which I get confused on where to start with. I searched using "How to set Context Path in Wildfly", but got no success. Can anyone help me on how to do it..? If it's related to coding, then I can do lot of searches and atleast I can get some Ideas, but I'm stuck here at configuration. Thanks in Advance.

You can do this in the by adding a /WEB-INF/jboss-web.xml file in the application that you deploy:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>/</context-root>
</jboss-web>

Change context-root directly in WebService class with annotation.
import org.jboss.ws.api.annotation.WebContext;
#Stateless
#WebService(portName = "SampleWSPort", serviceName = "SampleWS")
#SOAPBinding(style = Style.DOCUMENT)
#WebContext(contextRoot = "/SWS", urlPattern = "/SampleWS")
public class SampleWS implements SampleWSInterface {
org.jboss.ws.api.annotation.WebContext is in MAVEN artifact:
<dependency>
<groupId>org.jboss.ws</groupId>
<artifactId>jbossws-api</artifactId>
<version>1.1.2.Final</version>
</dependency>

Related

How to access the endpoint assembled inside an ear file?

I am building a web app using java ee as backend and angular as frontend. As application server i have chosen Wildfly 13. As a build tool for backend I have chosen Maven. I have created this structure for the project :
-Project
---Project-ear
---Project-model
---Project-service
---Project-service-api
Neither of this modules packages a war file, I package 3 jars and in the end I assemble them in an ear file using
"Project-ear"
I have tried to consume the exposed service inside
"Project-service"
but I cant. It seems I don't set the right url. Can somebody help me please?
I have tried to access the following urls:
http://localhost:8080/Project-ear/Project-service/resources/test/testDtos/,
http://localhost:8080/resources/test/testDtos/
I have created the RestActivator class :
#ApplicationPath("/resources")
public class RestActivator extends Application {
}
And I have created a Resource class :
#Path("/test")
public class TestResource {
#GET
#Path("/testDtos")
#Produces(MediaType.APPLICATION_JSON)
public Response getWorkflowDiagram() {
TestDto testDto = new TestDto();
testDto.setFirstName("Test");
testDto.setLastName("Test");
return Response.ok(testDto).build();
}
}
I don't get any error message, I just can't access the URL endpoint.
When you configure the Application Server (Wildfly) and add the ear artifact, it creates a target folder in your ear-folder. There you can find a file called application.xml. You have to set the context-root like that:
<?xml version="1.0" encoding="UTF-8"?>
<application 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/application_7.xsd"
version="7">
<module>
<web>
<web-uri>test.war</web-uri>
<context-root>/api</context-root>
</web>
</module>
</application>
Your URL depends on what you have set in context-root in application.xml and how have set the application path in your root class (RestActivator).
In this example:
localhost:8080/api/resources
And to get access to your method in TestResource:
localhost:8080/api/resources/test/testDtos

Class name is wrong or classpath is not set ERROR in Netbeans with Glassfish 5 server and JPAs

I have a Web Application in Netbeans 11 (with JDK 8 installed), I have added the dependencies for mysql-connector-java-8.0.15.jar and I have generated the JPAs from my DB.
No error while building it.
But when I try to run it, the Glassfish server give me these errors (pastebin link).
This is my persistence.xml, that I set accordingly, is:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="InvoicesPU" transaction-type="JTA">
<jta-data-source>java:app/Invoices</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
And in my java class I call it by:
#Stateless
public class InvoiceEJB implements InvoiceEJBLocal {
#PersistenceContext(unitName = "InvoicesPU")
EntityManager em;
...
em.someMethod();
For completeness, I have no error during the compilation phase!
Anyone know how to solve it?
After some research I solved it in this way:
taking inspiration from a similar problem, I created the Connection Pool and the Resource in the Glassfish Admin Console as suggested by devmind following this.
I removed as dependency the mysql-connector-java-8.x.x.jar and I added the mysql-connector-java-5.x.x.jar
In the persistence.xml I set the JNDI name for the tag jta-data-source
And everything goes as expected!
I don't know how to make everything work with the latest version of the MySQL Connector but, at least, in this way my Web Application works.
EDIT: for latests versions of mysql-connector, as devmind has suggest you should set MysqlDataSource: from com.mysql.jdbc.jdbc2.optional.MysqlDataSource to com.mysql.cj.jdbc.MysqlDataSource as reported here.
I hope it's useful to someone else.
Try to put your JDBC driver jar to Glassfish domain's lib folder. I usually store them in lib/ext.
I do not remember if I got this info from some other post or from the Glassfish user manual but it solves the issue mentioned for me, i.e.: Class name is wrong or classpath is not set ERROR with Glassfish 5 or Payara server. I'm using Payara Server 5.2022.3 currently.
Add the latest connector j to your server/your_domain; in my case it is domain1 and this is the script after I cd to /bin:
C:\Program Files\payara-web-5.2022.3\payara5\bin>asadmin add-library --type app "C:\Program Files (x86)\MySQL\Connector J 8.0\mysql-connector-j-8.0.31.jar"
Where quoted string is the path where I keep my connector j.

How to fix "Can not find the tag library descriptor" in eclipse 4.3 for my custom EL function

setup:
eclipse 4.3 with tomcat7 (running on localhost port 8080) configured as my test server.
my EL class (folder structure: http://i.imgur.com/ogOsCZM.jpg) created using New => Java project in eclipse
package org.flinders.mycustomutilities;
//import java.lang.StringBuilder;
public class MyCustomUtilities {
public static String Hello(String name) {
return "Heya " + name;
}
}
The class was then exported into a JAR file and imported into my maven repository. It was then imported to my spring mvc project using this entry in pom.xml:
<dependency>
<groupId>org.flinders.mycustomutilities</groupId>
<artifactId>MyCustomUtilities</artifactId>
<version>0.0.1</version>
</dependency>
I'm not getting any errors in Eclipse's Maven POM editor.
my TLD file (stored in D:\work\eclipse\java.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\ROOT\WEB-INF which seems to be the working folder for tomcat)
<?xml version="1.0" encoding="UTF-8" ?>
<taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<tlib-version>1.0</tlib-version>
<short-name>mytaglib</short-name>
<uri>org.flinders.mycustomutilities</uri>
<function>
<name>Hello</name>
<function-class>org.flinders.mycustomutilities.MyCustomUtilities</function-class>
<function-signature>java.util.String Hello(java.util.String)</function-signature>
</function>
</taglib>
not really sure what to put in the URI tag for my setup.
This is how I'm importing my custom EL function in my JSP file
<%# taglib uri="WEB-INF/mytaglib.tld" prefix="mine" %>
I've also tried
<%# taglib uri="/WEB-INF/mytaglib.tld" prefix="mine" %>
but eclipse just can't see it. I have started tomcat via eclipse just in case that is required without any positive outcome. Still getting the error mentioned above.
Any ideas? I've been searching for examples on the net but they don't really give complete/working examples.
thanks!
My problem is that I was placing the tld file in the wrong place. I am importing the class/jar into my spring web mvc project. But I was putting the TLD file in the "ROOT" WEB-INF. I should've placed it in the WEB-INF for my web project. All working now thanks to all those who looked at it.

How to define a custom EAR file name for a specific application?

Here is my setup
SDK: Eclipse Ganymede (3.4.2)
App Server: jBoss 4.2.3GA
I got three projects:
MYAPP, which is the main project, with only libraries and log4j configurations. This is where application.xml and jboss-app.xml resides.
MYAPPEJB, which is my business logic project in which I have my entity beans, sessions beans.
MYAPPWeb, which is my client logic project in which I have my Struts Forms, Struts Actions, JSPs and Jasperreports reports.
When I publish my project to my jBoss server on my laptop, I got the following EAR file name: MYAPP.ear, which make sense.
I would like to define a different custom name for the final EAR, let's say ACCOUNTMANAGER.ear
Here is my application.xml file
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" id="Application_ID" version="5">
<display-name>MYAPP</display-name>
<module>
<ejb>MYAPPEJB.jar</ejb>
</module>
<module>
<web>
<web-uri>MYAPPWeb.war</web-uri>
<context-root>/manager/myapp</context-root>
</web>
</module>
<library-directory>/lib</library-directory>
</application>
Any idea?
Thank you
Charles
You can specify your ear file name in application.xml file under web -> web-uri tag. Please check this link for your reference. web-uri
You can specify in application.xml file. It will pick up this name instead of ear file name.
MyEarName

failed to run wicket examples on tomcat7

I downloaded wicket examples 1.6.0 and built successfully in netbeans7.2. but got errors when I tried to deploy on tomcat 7:
Cannot deploy the module. The context.xml file seems to be broken. Check whether it is well-formed and valid.
The module has not been deployed.
See the server log for details.
at
org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:210)
at
org.netbeans.modules.maven.j2ee.ExecutionChecker.performDeploy(ExecutionChecker.java:178)
at
org.netbeans.modules.maven.j2ee.ExecutionChecker.executionResult(ExecutionChecker.java:130)
at
org.netbeans.modules.maven.execute.MavenCommandLineExecutor.run(MavenCommandLineExecutor.java:212)
at
org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
heres the contents in context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- <Loader className="org.atmosphere.util.AtmosphereClassloader"/> -->
<Loader delegate="true"/>
</Context>
I prefer to run wicket in eclipse as it negates the requirement to mess around with an external tomcat instance.
If you are comfortable with eclipse and maven i would download wicket 1.6 example archetype via maven, import into eclipse and then in the test directory you can run the run.java class to get an internal jetty server host wicket for you.
this should get you started quickly without having to wrestle with tomcat configurations too.
Not really an answer but an alternative route to the same end point
Add parameter path to context tag, same path that app will be served:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/application-path-name/">
<!-- <Loader className="org.atmosphere.util.AtmosphereClassloader"/> -->
<Loader delegate="true"/>
</Context>
Answer obtained from this question.