how to configure the batch job on weblogic server - java

I have created a standalone java application using quartz.i want to deploy the standalone program on weblogic so as it could be run as a batch job.
Can you please help me how could i deploy the java application on the weblogic and run the same.

I think one way to do this is create new thread and do your batch job in it.
You can add your class to Weblogic classpath and use it like start or shoutdown class.
Here is link on oracle documentation.

Related

Spring boot embedded container or war file in an external container for production

I'm complete able to configure spring boot in both cases, the question here is which of them are more robust and is the more recommended, because I didn't find in the spring boot documentation the recommended way to deploy it in a production environment, my concerns about use the embedded container are:
If I want to set it as a Windows or Linux service, is the jar file the best option?
If I use the jar file I'm not going to have access to restart the server.
Maybe in the future I need more applications in the same container.
If I restart the machine I have to execute again the java -jar.
The question in general is which is better use the jar file and execute it as java -jar jarname.jar in production or change the packaging to war set the tomcat as provided and set the generated war in an empty tomcat.
I hope you can help me.
---EDIT---
Many times the answer is depends, this is for a normal web application or REST web service.
jar packaging is perfectly suitable for production and you should rather fallback to war only if you really have to - which is often the case when you cannot control your deployment environment (which is often the case in large enterprises).
There is a chapter in Spring Boot Reference about setting up Spring Boot based application as a Unix/Linux/Windows service: Installing Spring Boot applications.
Regarding your concern:
Maybe in the future I need more applications in the same container.
With embedded containers if you need more applications running on the same machine, you should start two applications separately, each running on different port and effectively you will end up with two containers running - which is good, applications are better isolated from each other.
About a month ago I had the question like yours.
Let me share my conclusion:
1) JAR:
You can run independently every appliction with different ports (in linux, java -jar ... > app_logs.log &) and you can route it (e.g. nginx). Note that, restarting is not problem. You can write custom bash script (like this: ps aux | grep appname and kill by PID)
But there are some problems with configuring production app. Property files will archived into jar.
2) WAR
You can deploy into container and just run it. Easy managing at the server. If you want to re-configure app, open properties file from unarchived folder inside container, change it as need and restart container. So, managing and configuring will be easy.
But, if you want to run another app in this server with another port, then you must install another copy of container and config it.
So, in my practice, using war app easier than jar to manage and re-configure.
I don't know that much about Windows services but on Linux you can add the execution of a jar to a RC-Scripts (and thus make the application start at a certain run-level). For a spring boot app you just have to symlink to the jar and you can start/stop/etc like any other service, see: Spring Boot application as a Service
restart the machine or the JVM? A shutdown mechanism is built into spring boot, you just have to activate it (and you should enable security machanism so that not anybody can do that), see: How to shutdown a Spring Boot Application in a correct way?
Spring-Boot enables microservices - so the idea is to have one embedded webapp-container for each webapp/microservice. This reduces the risk of losing all services when only one is going down.
Yes. and you have to execute catalina.sh|bat start after every restart. Or you add an appropriate startup script (see 1.)
I sense that you'd rather do it the old-fashioned way. Despite the 'matter of taste' answer, there is one argument pro-jar: the only dependency is the JVM! The rest (the web-app-container, db-drivers, other libraries) is all part of the package you deliver. And if you decide to change the container for the next release, so will it be.
One more reason to use "war" file in production.
Springboot masked an error Jetty threw whereas WAR deployed in Jetty correctly caught it ( though issue below is still under review )
https://github.com/spring-projects/spring-boot/issues/8917#issuecomment-294673487
I don't know much about server kind of things, But my recommendation is
If you are using Monolithic application, better to use war with
external tomcat.
If you are using for Micro Service applications, use embedded
tomcat with different port. And each micro service applications are
independent from each other.

How to deploy my java j2ee program in glassfish server ?

I have a java application that running every 15 min.
I want to deploy it under a GlassFish server.
Can you help me please ?
There are many ways of doing this. Check this documentation for starters.
Also, in the IDE you can configure your Glassfish server and the IDE will automatically plug in deployment process for the project. All you would then have to do is to use Run / Run on Server.

Is it possible to run two servers on a same system simultaneously? Or how can I execute a MySQL query in Eclipse while XAMPP/WAMP is not running?

I have two questions, for those which I did not get any solution sounds good for my expectations.
1. Why both XAMPP/WAMP and Apache Tomcat?
Assume if I am now running a Windows system, with Eclipse LUNA.
Now, if I have to run a query for my localhost server, how does Eclipse help?
I won't be satisfied if you say there should be an XAMPP server running live for your query to execute in Eclipse(Like they say here Database Development Using the Eclipse IDE, MySQL with Eclipse Data Tools Platform in Java).
Then why Tomcat is there?
Sorry if there is some loop hole, or may be this is a Banana-Monkey` type question. All because I don't get it clear.
And now, my second question.
2. How can I(Is it possible to) run a Java project in Eclipse with Apache Tomcat while WAMP/XAMPP is running in background in my system?
Suppose I am on the same system working with different user privileges. Say user1 runs both the XAMPP and Eclipse As Administrator. Now (or anyhow) is it possible to run a project in Apache Tomcat while WAMP/XAMPP is running in background simultaneously in the system?
I am totally confused. Helps with your comments and answers are appreciated.
Thank you.
Yes it is possible to run two servers on same system simultaneously.
Yes you can execute a MySQL query when XAMP/WAMP is not running.
It seems you don't understand your setup and the elements involved.
XAMP/WAMP contains Apache server, so a http server that can handle static html or run php scripts. It also comes with a MySQL database.
So the only important part from the Java WebAPP is the MySQL. You can start MySQL without starting apache, you can finally install MySQL yourself (it has simple windows installer). But if your application is using MySQL it has to be running for it to work (be it a XAMP version or standalone version).
Your Java Web Application requires application container to run, and it is the Tomcat. It is Apache Tomcat as it is developed under apache groupe, but it is not the same as Apache web server.
So you need tomcat to run your web app. Again you can install one yourself or use the one that comes toghether with Eclipse.
You can have many tomcats at the same time, all running (for example different version of Tomcats or Java) as long as they listen on different ports. The ports on which tomcat is runing is configured in its server.xml file under conf directory.

jenkins deploy with hibernate create-drop option

To enforce the create-drop hibernate option I need to shutdown tomcat(?), however if I were to do that my jenkins server is also shut down. At the moment the jenins job simply builds the war and then copies it to webapps directory.
I want to enforce the create drop hibernate option on my web app without restarting tomcat/jenkins, is their a way to do this ?
As other users already stated you do not have to restart tomcat in order the restart a web application inside it. There is a deploy plugin available in Jenkins which is perfect for your scenario: https://wiki.jenkins-ci.org/display/JENKINS/Deploy+Plugin .
By the way, Jenkins comes with an embedded Jetty server so it is very straightforward to run this outside tomcat:
https://wiki.jenkins-ci.org/display/JENKINS/Starting+and+Accessing+Jenkins
In case you are just starting with this application then consider using Liquibase to manage your DB creation, upgrades, ...: http://www.liquibase.org/ . It can be integrated with hibernate if desired and you could then easily create a Jenkins jobs that does a liquibase drop_all/update to recreate your database (schema) without touching your running application.
Well i think you don't have to restart the server just redeploy the application.

How can I embed Weblogic server in java?

I am searching any way for embedding Weblogic server in Java , I know its possible because we have maven plugins for Weblogic which embeds Weblogic in maven, But googling for it did'nt gave me useful output, Does anybody know how can we embed wemlogic in java program ?
WebLogic doesn't provide an embedded API so, even if it's a pure Java Server and if you can thus call weblogic.Server from Java code, you will have to handle everything yourself (starting the container, waiting until it's started, deploying things, waiting until they are deployed, etc). In other words, this will require some work.
Maybe have a look at the sources of Cargo, although Cargo isn't really starting an embedded Weblogic (i.e. running weblogic.Server in the same JVM). This will give you an idea of what has to be done. Or, depending on your needs, use Cargo Java API.
But if you need a full Java EE server and if this is an option, I would use GlassFish v3 in embedded mode instead of WebLogic, it will be much simpler. Check the following links and see yourself:
Embedding Glassfish V3 in Unit Test - Two Jars, Three Lines Of Code And Five Seconds Start With Deployment
Embedding EJB 3.1 Container Into Your Unit Tests - Boot Time: 5 Seconds
Using the EJBContainer API with or without Maven (but with GlassFish v3)
TOTD #128: EJBContainer.createEJBContainer: Embedded EJB using GlassFish v3
Do you need WLS specifically, of any servlet container would do? If the latter is OK, then use Jetty.
WLS is not designed to be embeddable. But you can do it. After all, WLS is just a class named weblogic.Server. Setup classpath correctly, setup PATH and other environment variables (see setDomainEnv.sh and startWeblogic.sh), start that class from Java, and you have an "embedded" WLS.
There is probably a way, but I don't know it. My experience from writing maven plugins tells me that the most likely way that the plugin works is that it starts up a new command line process just like you would normally start up the server. So in a sense, not really embedded it.
The best way to see is to track down the source of the plugin and see how they did it.
WebLogic doesn't support embedded mode like Glassfish but you can have control over your Weblogic using "WebLogic Maven Plugin", this provide several maven goals for managing and working with Weblogic instance.
See this link for further information.

Categories