Experience with running Jetty 7 or 8 from ant? - ant

Is there a way to run jetty 7 or 8 from ant? There's an ant plugin that works fine with the (pre-eclipse) version 6 only, but the eclipse versions seem only available in standalone form.

Quote from http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty
Jetty has a slogan, "Don't deploy your application in Jetty, deploy Jetty in your application." What this means is that as an alternative to bundling your application as a standard WAR to be deployed in Jetty, Jetty is designed to be a software component that can be instantiated and used in a Java program just like any POJO. Put another way, running Jetty in embedded mode means putting an HTTP module into your application, rather than putting your application into an HTTP server.
This means that you can just add a single java class in your project, compile and run with something like:
<target name="run.jetty">
<java class="myjettyrun/RunJetty" classpathref="classpath.run.jetty"/>
</target>
And the RunJetty.java would look something like this:
package myjettyrun;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class RunJetty {
public static void main(String[] args) throws Exception {
Server server = new Server(80);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar("distrib/wars/root.war");
server.setHandler(webapp);
server.start();
server.join();
}
}
This has been tested with Jetty 8. Make sure you have all the required jetty jars (jetty-webapps, jetty-server) and possibly jsp support (eg. jsp-2.1-glassfish) with their dependencies in classpath.run.jetty.
In http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty you can find more examples on how to run jetty in different situations.

Related

GraalVM native image reflection doesn't work

I'm trying to create a GraalVM native image using the maven plugin but having some issues.
Here the config for the maven plugin
I'm using GraalVM JDK (installed through Sdkman):
$ java -version
openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment GraalVM CE 21.1.0 (build 16.0.1+9-jvmci-21.1-b05)
OpenJDK 64-Bit Server VM GraalVM CE 21.1.0 (build 16.0.1+9-jvmci-21.1-b05, mixed mode, sharing)
I have a done simple main class like:
package it.r;
public class Main {
public static void main(String[] args) {
System.out.println("********");
System.out.println(Main.class.getConstructors().length);
System.out.println("********");
}
}
When executing it using mvn exec:java -Dexec.mainClass=it.r.Main I get as a result:
********
1
********
But when doing mvn package and then executing the created executable, I have as result:
********
0
********
Why is this happening?
Here the git repo to reproduce
This issue seems to impact Jackson deserialization, as in another example I have an error from jackson that cannot deserialize a yaml file because it can't find constructors for my class.
When GraalVM native image builds your application into a native binary it statically analyzes your application.
The analysis is static, so several dynamic features your application might use require explicit configuration, for example:
reflection
serialization
method handles
using resources (like classloader.getResource())
JNI
This explicit configuration is provided as json configuration files, for example,
You can provide the config files manually, but you can also run your application using a javaagent which will record usages of features requiring configuration.
In a nutshell, you run your application like this:
java -agentlib:native-image-agent=config-output-dir=/path/to/config-dir/
and exercise the code paths that use the code you want to be configured. This is important because the tracing agent can only record the config for the code it actually saw running.
Then the output directory will contain a json file, for example looking like this:
[
{
"name":"StringCapitalizer",
"methods":[{"name":"capitalize","parameterTypes":["java.lang.String"] }]
},
{
"name":"StringReverser",
"methods":[{"name":"reverse","parameterTypes":["java.lang.String"] }]
}
This file lists the classes that need to be included into the analysis and the binary result and their members that need to be accessed.
It’s fairly straightforward but a bit tedious to create manually that’s why the agent approach is preferred.
There’s also a programmatic way to configure classes and members be registered for reflection, but using it means you need to include a dependency on the GraalVM code into your app.
Classes using reflections need to be registered in order to include them in the native image built, more info in the docs

Has anyone had success with Grails 4 / Java 11 and using DCEVM for hotswapping during development?

We upgraded to Grails 4 / Java 11 and lost hot-swapping capabilities during development. I tried DCEVM but the application wouldn't start (errors on first withNewSession call).
Has anyone had success with getting Grails and DCEVM to work together?
I've got hotswap working with Grails 5.1.2 but the Hibernate plugin causes a
org.hibernate.HibernateException: No Session found for current thread
so I had to disable the plugin. This means any changes to domain classes will still need a restart.
You'll need a copy of groovyReset.jar to avoid random errors due to Groovy caching methods that have been replaced by hotswap.
sdk install java 11.0.9-trava
sdk use java 11.0.9-trava
Add a copy of groovyReset.jar to your project root
Add the following to the bootRun jvmArgs in build.gradle:
'-XX:HotswapAgent=fatjar',
'-javaagent:groovyReset.jar'
Create src/main/resources/hotswap-agent.properties containing:
disabledPlugins=Hibernate
autoHotswap=true
You should now be able to start Grails and any code changes will be picked up without restarting.
Recently I tried with Hybris2005 + Java 11 + Windows + Eclipse.
Follow below given steps and do modification as per your need.
DCEVM 11 Configuration Step.
Download and extract java11-openjdk-dcevm-windows.zip in your local machine
Set JAVA_HOME=D:\java11-openjdk\dcevm-11.0.10+3 (Adjust the path as per location in your system)
In eclipse go to windows->Preference->Installed JRE and set JRE home to D:\java11-openjdk\dcevm-11.0.10+3
4 In local.properties adjust the property tomcat.debugjavaoptions as below
tomcat.debugjavaoptions=-XX:HotswapAgent=core -javaagent:D:/java11-openjdk/dcevm-11.0.10+3/lib/hotswap/hotswap-agent.jar=disablePlugin=Log4j2,disablePlugin=Spring,disablePlugin=Proxy,disablePlugin=AnonymousClassPatch,disablePlugin=ZK,autoHotswap=true -Djava.locale.providers=COMPAT,CLDR -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n -Xmx4G -Xms2G
Also, please set ANT_HOME environemnt variable so that we don't to run setantenv.bat from \hybris\bin\platform and update the PATH variable accordingly.
Perform ant clean all and start hybris in debug mode.
Add System.out.println() statement in your code and then execute ant build command from that specific extension folder.
Verify if HOT swap is done.

springBoot application on Jboss EAP, servlet context not lodaed

I have a very simple spring boot application that I want to deploy to Jboss EAP. Here is my simple application class:
#SpringBootApplication
public class MayurApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(MayurApplication.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
private static Class<MayurApplication> applicationClass = MayurApplication.class;
}
#RestController
class GreetingController {
#RequestMapping("/hello/{name}")
String hello(#PathVariable String name) {
return "Hello, " + name + "!";
}
}
and my pom.xml is also very basic. When I run this application on Tomcat, using the embedded Tomcat what ships with spring boot. Everything works like charm in just one click. I can access http://localhost:8080/demo/hello/World and it works too.
Now I tried to make it Jboss EAP compatible war, I disabled the Tomcat by excluding from spring-boot-starter-web, and convert it into a war project. (as suggested by article http://spring.io/blog/2014/03/07/deploying-spring-boot-applications).
I also added:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>,
as it was complaining.
Now after all this, it compiles fine and creates a war too. When I copied this war to jboss deployment, I can see it successfully deployed on console.
But the rest api http://localhost:8080/demo/hello/World just does not work and constantly throws error on browser:
JBWEB000068: message /demo/hello/World
JBWEB000069: description JBWEB000124: The requested resource is not available.
What am I doing wrong?
Found this in Spring Boot Reference Guide, add the below line in application.properties file
server.servlet-path=/*
tested this in jBoss EAP 6.2 and worked fine.
Answer is here : Spring Java Config vs Jboss 7
Apparently "/" does not work on Jboss EAP 6.3 , but "/*" works.
and they seems to have fixed it with wildfly 8
You mentioned JBoss 6 in you tags. Based on my experience Spring Boot Autoconfigure and JBoss 6 (specifically) is a no-go. If Hot Deploy is turned on or perhaps some other condition JBoss VFS performs some aggressive scanning of all jars in the war file. Once it starts to scan the classes in the autoconfigure module, it will abort due to an error akin to ClassNotFoundException. If you are using Autoconfigure, one solution might be to place the spring modules in the Container's lib. But this would make deployment unwieldy. I did not see this behavior on JBoss 7 nor Wildfly 8.

Unable to deploy a osgi bundle containing a camel route defined via aries blueprint in Websphere 8.5

I created an .eba file (enterprise bundle archive) that contains one osgi bundle having a apache camel route (Java DSL). The camel context definition is done via a blueprint xml file. When I tried to deploy the .eba file in Websphere Application Server 8.5, I got the following exception:
org.apache.aries.application.modelling.ModellerException: CWSAL0126E: An exception occurred while modelling bundle ib-base_0.0.1.SNAPSHOT: org.apache.aries.application.modelling.ModellerException: org.osgi.service.blueprint.container.ComponentDefinitionException: Unsupported node namespace: http://camel.apache.org/schema/blueprint.
My blueprint xml file is as follows:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-
blueprint.xsd">
<camel:camelContext id="cbrContext" trace="false">
<camel:packageScan>
<camel:package>a.b.c.d</camel:package>
</camel:packageScan>
</camel:camelContext>
</blueprint>
I am not too sure why this fails in Websphere. The same .eba file gets successfully deployed in Karaf 3.0.0-SNAPSHOT. (This version of Karaf uses Aries Blueprint version 1.0.0).
I guess the same is used or a forked version of the Aries Blueprint 1.0.0 is used in Websphere 8.5.
As per the OSGi specs, any blueprint extension handlers for custom namespaces like camel: are retrieved from the OSGi Service Registry under the key (osgi.service.blueprint.namespace). The value element tells the actual namespace uri .
eg:
<service interface="org.apache.aries.blueprint.NamespaceHandler">
<service-properties>
<entry key="osgi.service.blueprint.namespace" value="http://camel.apache.org/schema/blueprint"/>
<entry key="osgi.service.blueprint.namespace" value="http://camel.apache.org/schema/blueprint/cxf"/>
</service-properties>
<bean class="org.apache.camel.blueprint.handler.CamelNamespaceHandler">
</bean>
</service>
I am not too sure why IBM does not honor this spec.
Another interesting point to ponder over is the fact that when I tried to create a blueprint .xml file using Websphere Application Developer Tool, it shows only 4 extensions as shown below:
IBM Blueprint Extension
JPA Blueprint Support
Blueprint Transaction Support
Blueprint Resource Reference support
I ensured that both the camel-core and camel-blueprint bundles are deployed in the internal repository in websphere.
I tried to deploy the .eba file as an asset.
Not too sure, if I have missed something. I would be glad if someone can point me in the right direction.
best regards,
Sriraman.
WebSphere does not support custom namespace extension (other than the one provided by IBM). The main reason being it runs on Aries (Blueprint container) isolated runtime. There are two options
Use camel api instead of blueprint tags
Use other container (for e.g. Karaf) which supports custom namespace extension
Karaf is a friendly container for camel.

EJB calls from grails to glassfish

I need to use EJB remote calls from my grails application. For this in previouse Servlet application I used client glassfish jar(gf-client.jar) and is's worked.
How I can include gf-client.jar into build path in grails app for call EJB methodth?
thank you.
the answer was to copy all libraries of GlassFish application server to client mashine (directory with gf-client.jar and 2 levels up, check dependencies in gf-client.jar) and add only gf-client.jar to classpath of application. Ather dependencies will loaded automatically, when gf-client will loaded.
note 1: in my case for grails application witch I deploying to tomcat servlet container write full path to gf-client.jar to shared.loader section of catalina.properties file in conf dir, and restart tomcat.
note 2: for GlassFish v3.1 and up, replace gf-client.jar with gf-client-module.jar
Put gf-client.jar into the lib directory of your grails app. Any jar files in the lib directory of your grails app will automatically be included when you run your application as well as be packaged in generated war files.

Resources