I have a WAR with Java Spring application, which I can deploy to a Java application server. I need to run it on a machine with JRE, but without application server, i.e. with java -jar my_application.jar.
The guide "Convert an existing application to Spring Boot" is a close match, except that I do not need to create a deployable WAR as I already have it. The existing code does not use #SpringBootApplication, and I'd prefer not to mangle with it.
If you want a runnable 'Jar' file, then the jar file must contain the Web server, so you best option is to convert your application to spring boot. Spring boot is able to package an application as a war file, so it can be deployed on a Tomcat, or be launched with java -jar, but it has to be a spring boot app to begin with.
Related
We extensively use Java ServiceLoaders as a plugin infrastructure for our application components. We define interfaces, and then use the loader to load them at run time. Adding additional jars with extensions and service files are fine for our use cases.
However, i'm struggling to understand how we would be able to continue this approach while deploying an application within Wildfly. The intent is as stated above, the ability to add "extension" jars to the web-application class path without having to
Stop the server
Unzip the war
Add additional jar
Zip war
Start the server
In Tomcat, we could deploy web application folders instead of a war. So stopping the server, dropping in a jar, and starting the server worked fine. Within Wildfly (latest), it appears to not like the deployment of a folder vs war.
I've read about the modules approach, but have not been successful using this approach to get the deployed application to see the module from the service loader implementations.
Would like to know if there is an alternative solution or perhaps we are doing something wrong?
Thanks
WildFly supports exploded deployments with the deployment scanner or using the explode command with jboss-cli. Using the jboss-cli you can even update files remotely.
I'm struggling to learn how I go about building, packaging, and deploying a Spring REST API locally so that I can interact with it? Ideally, I'd just like to GET and POST data as practice -- specifically integrating with DynamoDB.
I've cloned this DynamoDB project and built it using mvn package so that I have a jar file. I moved the jar file to the webapp directory of Apache and started the server, but I cannot interact with the API in any way. The project is structured as follows:
Once Apache is running with the jar in the webapp directory, I've tried accessing the API at:
http://localhost:8080/
http://localhost:8080/springbootapp (from server.contextPath=/springbootapp in application.properties)
Each gives a 404 error. And yes, DynamoDB is running locally. So what do I need to do differently? How can I deploy and access this API locally?
The project you have cloned is a spring boot project, hence you can use mvn spring-boot:run to run the application locally.You can also run it by running the com.baeldung.Application class as a java application from the IDE. For more details on how to run a spring boot app you can follow this link. Spring boot parent has a dependency on the embedded tomcat, which will run the application.
Additionally if you want to deploy the application as a war the spring boot documentation shows how to do it.
I would like to know if is possible use external jars with web application that uses spring boot with embedded server.
Example:
java -cp external.api -jar app.war -spring.config.location=application.properties
When I use application I got errors like ClassNotFoundException for classes that are inside of external jar.
I have a Gradle, Spring Boot (web starter) application, that is built to be run either as a standalone application with the embedded container, or deployed to a container as a war.
So I from Eclipse I can run/debug the #SpringBootApplication class, and also deploy the war in Tomcat. All works fine.
Now, for some requirements, I need to know the running environment; standalone or container. Basically, we generate a MANIFEST file to the war, with a Gradle build, and refer to that file for some version/meta information. However, this would be generated only when built from Gradle. Is there any way in code I can differentiate this?
I've developed a small MVC project using Spring MVC, Hibernate, MySQL, Maven and Tomcat. I can run and test the application (locally) smoothly.
Now I need to publish/deploy this project on an (online) server that have only Tomcat installed on it. How can I publish/deploy the project online? Is there any special build I should do? What files I shall upload and to where?
There are several types of development options available.
For development on localhost EAR (Exploded ARchive) type of project is usually used (because you can easily make hot deploy on servery). But for production WAR (Web ARchive) is used (basically it's the same EAR archive, but compressed using ZIP algorithm).
If you want to deploy your project to remote Tomcat server then make your project as WAR archive and upload it to Tomcat's webapps directory. Then you might need to restart Tomcat. But it's manual way of deploying.
Better option is to use automated build tools (like Maven) which can compile your project, run unit tests, deploy on web server (local or remote) etc.
This one is a great example of how to deploy your project on Tomcat server by using Maven's tomcat-maven-plugin: http://www.mkyong.com/maven/how-to-deploy-maven-based-war-file-to-tomcat/
Good luck ;)
Do a mvn clean install and you will get a .war file in your target directory of web module.
Copy it and paste it in tomcat_home/webapps directory and restart tomcat. Thats it. now, you can access it in whatever configured port (eg: http://localhost:8080/<your webapp war name>). lets say your war name is myapp.war, then tomcat would have extracted it into myapp folder in webapps.
so your url will be http://localhost:8080/myapp
With maven deploy command, usually gets errors for various reasons.
if you work in Unix/Linux system, I recommend using "rsync" method on console. (You can write own shell script to manage easily). It helps not only deploying without a problem but also helps to get time while redeploying (only uploading changed / new files). Because maven deploy / redeploy uploads your project as a bundle in jar/war. However "rysnc" method uploads your project files one by one.
Before using it, you should sure that two conditions.
1- your project is built in target folder (Spring Tool Suite)
2- you have access to tomcat via ssh
example code : (v_ : prefix which is variable(customizable))
rsync -avz v_your_project_in_target root#v_ip:v_tomcat_name/webapps/v_project_name
(Second sharing)