How to migrate Java project from Eclipse to VS Code? - java

I'm trying to migrate a Java project from Eclipse to VS Code, the project consist of a front and a backend, and both are supposed to run on a Wildfly Server at localhost. I want to have hot code reload when a .xhtml or .java file is modified, without having to manually compile a .war file and publish it to the server.
I'm using the Red Hat Server Connector plugin, but on the Wildfly server there is only and option for deploying a war file or a folder.
Is there a way to configure Maven to compile directly to wildfly\standalone\deployments? or some tutorial about how can I configure VS Code for Java.

Have you tried the Tomcat for Java extension?
You can have a look at this video, at the 8:13 you can see the Hot Code Replace button.

Related

Deploy java web application to Tomcat with Visual Studio Code

I'm trying to deploy a java web application to Tomcat using Visual Studio Code and I'm having some issues that I'd like to share.
After installing the extension Tomcat for Java, I've tried to deploy a Maven Java Web project. To do so, I've clicked over project's folder and selected "Run on Tomcat Server" option. The result is an error with this message: The folder is not a valid web app to run on Tomcat Server.
Then, I've realized that maybe I should create a war file before running it on Tomcat. Therefore, I've executed mvn clean package command and afterwards execute "Run on Tomcat Server" option over the war file. Doing this the project has been deployed correctly.
However, compared to Eclipse's way to work with Tomcat, it seems to me a bit tedious. Particularly if I'm working with static files, like css or js, because every time I modify a file I should execute mvn clean package and "Run on Tomcat Server". Whereas, in Eclipse, these files are deployed automatically on Tomcat without restarting.
I wonder if there is another way to work with VS Code and Tomcat for Java.
Thanks!
If you use Spring, there is an easy way.
The Spring Initializr extension comes with an embedded Tomcat installation, and hot reloading works out of the box.
Rely on the following guide to install it:
https://code.visualstudio.com/docs/java/java-spring-boot

How to deploy and access a Java WebSocket endpoint on Heroku without any additional frameworks

I have followed this very basic tutorial for setting up a WebSocket endpoint in Java: http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HomeWebsocket/WebsocketHome.html
Heroku, however, expects me to rely on Play Framework: https://devcenter.heroku.com/articles/play-java-websockets
My question is: how could I deploy the same without any additional frameworks and what procedure should I go through in order to make things work?
The problem you had was this:
The tutorial you followed was made for the GlassFish Application Server but Heroku only supports Tomcat 8 and Jetty. See here: https://devcenter.heroku.com/articles/war-deployment
But don't worry, I ported and tested the tutorial to run with Tomcat 8.
I also added the glassfish implementation of the javax.json specification.
(Make sure to download the implementation and not the spec interfaces only)
You can find it here: http://central.maven.org/maven2/org/glassfish/javax.json/1.0.4/
I also noticed why maybe your index.html didn't work locally: I think it was because the WebSocket URL was hardcoded in the websocket.js file.
I have taken the liberty to fix this by making it dynamic.
Here is the complete NetBeans 8.0.2 project:
http://ray.hulha.net/WebsocketHome.zip
Here is the best way to create a war file from inside NetBeans 7 or 8:
There is one catch however, the Tomcat 8 on Heroku is missing the websocket addon.
But no worries, you can added it manually to the war file.
Here are the steps:
Download the Tomcat websocket addon here:
http://central.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-websocket/8.0.29/tomcat-embed-websocket-8.0.29.jar
The war file is really just a zip file. So I used 7-zip to open the war file. Then navigate to the WEB-INF/lib folder inside the war file.
Copy the jar into the war. Drag and Drop the tomcat-embed-websocket-8.0.29.jar into the lib folder of the war file inside 7-Zip.
Z-Zip will ask if you really want to copy the jar into the war file.
Say Yes.
Here is the compiled war file complete with the tomcat-embed-websocket-8.0.29.jar ready to deploy on Heroku:
http://ray.hulha.net/WebsocketHome.war
I used this command to deploy it:
heroku war:deploy WebsocketHome.war --app websockethome
Make sure to replace the app name in the end with your app name.
And here is the working result:
http://websockethome.herokuapp.com/
Heroku does not require Play framework to use Websockets. That is just an example. As long as your app from the Oracle tutorial binds to $PORT it should work.

Deploying Eclipse dynamic web app after changing java source

I have a eclipse dynamic web project with backend written in java. I have configured Eclipse to deploy and run this project using tomcat.
When I change my java source code, build project and run the server in tomcat, sometimes my changes get applied, but sometimes they do not get applied.
When changing java source code, what are the steps I need to follow when running the project, so that changes will be applied?
I am using eclipse jee neon.
When you changes to the code, follow following steps to test the changes.
Go to the servers tab in your IDE and remove the existing web module
related to your application.
Now right click on the project and build project. Then right click on
index.jsp file and select Run as → Run on Server

Run spring project in eclipse

I am new in spring.I imported one spring project in eclipse and try to run with apache tomcat but it is not running.There is no main method in project.It contains only controllers and models and one jsp page.When i tried to run as a java application is shows below dialog. Please help me.I tried all in google for how to run spring project but i can't understand.Please tell me how to do?
Assuming you have added tomcat to your eclipse.
If your project is pure java project then it will not show you the run on server option in eclipe. You need to change project facet and add dynamic web module to it then you can run it on tomcat server from eclipse.Basically project needs to be web project.
After doing above if it gives error or do not run properly, check your project deployment assembly and add projects webapps folder in eclipse.
you need to have a tomcat installed in your eclipse and run it on the server.
Here is a tutorial to do this
You need to install the Web Tools Platform, which has support for the usual Web-application tools.

How to deploy Java project to Tomcat

I have downloaded a sample extjs+mysql+spring web project (link) with a java backend that I'd like to set up locally on my machine. I have installed Tomcat server, and MySQL DB but it's my first time ever with a java-based web application and I have troubles setting it up. Does it require any modifications ? I thought that .jsp files should be included there, but I can only see .java sources. Do I need to build it before it's ready for deployment ? Any help appreciated.
This is an Eclipse project so you'd need to run it from within Eclipse.
Download Eclipse
Open the project in it
Define a Tomcat container in your Servers tab
Drag and drop the project onto the newly defined Tomcat
Run it
if your are using eclipse IDE for development, create a project in eclipse,
run as "run on server" , and set the running server (eg TOMCAT 7).
and thats it,,
make sure, you correctly setup spring project in IDE with all needed jar files .

Categories