Deploying a regular JAR to Tomcat server - java

I know this is a weird question but is it possible to somehow run a JAR with a main class on Tomcat like a WAR?
I'm aware that won't automatically give it any website capability.
I just want it to execute it inside the web server JVM with the isolation that it gives

Related

Java Program to load an changed class without server restart

I need a java/j2ee program, that will load an updated class file when the server is still on. In our Web Application testing environment few classes(Java files) are being frequently changed to fix defects and need to load them in JVM fresh.
We can not restart the server to impact on going testing .
Can we write a program to load it using class loader?
No you cannot, you would need to have the container on the server side. Although for your server like tomcat, jboss, websphere etc. you can configure them to hot deploy but the server side would still needs restart once new class file is placed. If you are trying to hot deploy a class file you can try using JRebel it will allow you to hot deploy the class file without actually restarting because it is managed within JRebel container. (also note that JRebel is not free)

Spring boot serving a spring web mvc application with tomcat in a java webstart application

I managed to get this running but I'm facing a lot of problems that only occur when the application is running with java web start. When I run it from within my IDE it runs fine.
Static content that should be served out of the box from within a folder named 'static' is not found in the jar. I wrote a mapping method to get it with getClass().getResourceAsStream() and write it to the response.
On my Win 7 & Java 8 machine, the used socket is not closed when shutting down. I see jp2launcher.exe that keeps running and probably prevents spring boot getting the shutdown hook called to clean up.
Apparently there are some jars in the class path that aren't found.
java.io.FileNotFoundException:Jar URL cannot be resolved to absolute file path
because it does not reside in the file system:
https://mysite/webstart/org.springframework.boot-spring-boot.jar
Someone an idea what causes this?

Java Web Container implementation independant development

One of the most important non-functional requirements of any project is the build process in my opinion and that's where I kinda get stuck in my java project, which has just one external dependency, a jdbc compatible database. All the tutorials about spring and deployment out there; I've read them all, but they either say:
run it with gradle bootRun applications.properties (yes works but on a webserver I'm not going to have any properties-files, but JNDI resource for example) or
build a deployable war file with JNDI resources (yes it works on the webserver, but not in my embedded webserver or I'm doing it wrong, but I cannot find any doc about how an embedded tomcat loads a context.xml from outside the jar file).
Now I tried to use the same setup as my server and installed tomcat7 and the #Asyc #Scheduled services run, but no servlets, like a simple /status page should return "OK" just for checking. catalina.out does not show any errors. My /manager from tomcat7-admin says deployment ok, and when I click start: "FAIL - Application at context path /xyz-0.1.0 could not be started
FAIL - Encountered exception org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/xyz-0.1.0]]"
And now I want to make a cut here and throw every "bootstrap" stuff away and start from zero.
So my question is, am I wrong when I say, that the big deal of my deployment is a jdbc JNDI resource provided from the web container, which is called 'jdbc/xyz' and everyone who wants to deploy my war needs that JNDI. That means so matter if you're using wildfly, jboss, tomcat, glassfish or any embedded server: your server impl has to provide that web container and jndi resource to make it run. And I don't want to configure any tomcat, glassfish or whatever implementation in my war.
Is that wrong?
It would be great, if you could help me. I'm playing around with that many weeks now :( and if A works B does not and vice versa. Would it be easier to use JEE?
Thank you.

Why does JBoss always redeploy .WAR files that have already been deployed but not changed?

I am new to using the JBoss 7.1.1 server and am confused by a behavior that I have observed.
My JBoss server is deploying the six jBPM .war files (designer, drools-guvnor, jbpm-form-builder, jbpm-gwt-console, jbpm-gwt-console-server, jbpm-human-task-war) which I have placed in the .\jboss-as-7.1.1.Final\standalone\deployments folder.
When I launched the server for the very first time it detected these files and deployed them. I see the deploymentNNN and tempNNN folders appear in the .\jboss-as-7.1.1.Final\standalone\tmp\vfs folder. This is similar to the behavior I'm familiar with from my use of the tomcat server.
I then shut the server down and observe that the two folders created in .\jboss-as-7.1.1.Final\standalone\tmp\vfs are retained but their contents are automatically deleted. When I restart the server it once again deploys the six jBPM files into a new pair of folders in .\jboss-as-7.1.1.Final\standalone\tmp\vfs.
This is very surprising because no changes have been made to the six jBPM files and the problem is that this redeployment takes 3 to 4 minutes.
If this was just happening in a "production" environment then perhaps this would not be much of an issue. However, I am trying to integrate the JBoss server into use with Eclipse Kepler in a development environment and having to wait 3 to 4 minutes for each code change and server launch is not practical.
1) Can anyone explain why JBoss goes to the trouble to redeploy files that have not been changed?
2) Is this a behaviour that can be changed through a configuration setting?
3) Is there any settings where we can stop the jboss to redeploy the war files when it restarted
Thank you,
All
In order to stop JBoss from re-deploying your apps (and deleting on shutdown),
try deploying the apps in unpacked form.
extract the files to {name}.war directories (e.g /designer.war, /drools-guvnor.war)
and then deploy these directories (i.e copy them to the deployments folder)
Alternatively, try to deploy them using the JBoss CLI
Deploying differently won't change the fact that at startup JBOSS reloads your application to the JVM.
This can take time because your application stores data from database to your server memory. (You could as well be hitting this WFLY-925 bug... Or the one they are talking about here...)
The thing is you normally don't need to restart your server completely when redeploying. You can hot-deploy your module - see also full doc. at Auto-deploy mode. (make sure the feature isn't disabled
If you need some context to be reloaded, I advise you have a specific procedure in your code that you can call to reload all cached info. instead of restarting completely (e.g. have a call to a specific URL from your application do it...)

How do I push an update to a war file to clients?

Assuming my clients are running my J2EE WAR application on their intranet, and I have an update for them... how do I push the updated war file to them?
I'd like it to be automatic and require no human interaction on the client's side.
Can this be done?
Any help would be appreciated.
Tomcat (if this is your target container...) offers a manager interface that will allow you to deploy/start/stop applications.
I have used both ant and maven tasks to great effect in deploying wars remotely all while being built-in to the build process.
Depending on your deployment process, this may not work for you, but for dev & qa: highly recommended.
Edit: of course apache has to be configured for this type of access to be allowed.
See: Deployer how-to
Glassfish has documentation on deployment here.
Ant tasks are also available here.
Glassfish uses Tomcat internally, but the Tomcat Manager is not available as it is a separate application.
If the glassfish admin console can be accessed, it can be used to upload and deploy war files.
I'm not sure if you're comfortable giving them access to your source code repository...even in read-only mode.
If you are, then you could script up something in ANT to check out the latest version of the source code (using CVS task) and then build the .war file (using WAR task).
The only trick would be automatically deploying it once the war has been built. Tomcat will automatically deploy applications copied into a certain directory. For Websphere, see this question and this question.
For other J2EE servers I don't know how it would be done.

Categories

Resources