Running webapplications on spring TC server with IntelliJ IDEA [duplicate] - java

Using Netbeans, I develop sites with Tomcat as the local server to manage it.
In Netbeans it was "Install, write hit Run and it works"
How do I pull the same thing off in IntelliJ?
I can't find step-by-step instructions for this.

NOTE: Community Edition doesn't support JEE.
First, you will need to install a local Tomcat server. It sounds like you may have already done this.
Next, on the toolbar at the top of IntelliJ, click the down arrow just to the left of the Run and Debug icons. There will be an option to Edit Configurations. In the resulting popup, click the Add icon, then click Tomcat and Local.
From that dialog, you will need to click the Configure... button next to Application Server to tell IntelliJ where Tomcat is installed.

Here is step-by-step instruction for Tomcat configuration in IntellijIdea:
1) Create IntellijIdea project via WebApplication template. Idea should be Ultimate version, not Community edition
2) Go to Run-Edit configutaion and set up Tomcat location folder, so Idea will know about your tomcat server
3) Go to Deployment tab and select Artifact. Apply
4) In src folder put your servlet (you can try my example for testing purpose)
5) Go to web.xml file and link your's servlet like this
6) In web folder put your's .jsp files (for example hey.jsp)
7) Now you can start you app via IntellijIdea. Run(Shift+F10) and enjoy your app in browser:
- to jsp files: http://localhost:8080/hey.jsp (or index.jsp by default)
- to servlets via virtual link you set in web.xml : http://localhost:8080/st

Which version of IntelliJ are you using? Note that since last year, IntelliJ exists in two versions:
Ultimate Edition, which is the complete IDE
Community Edition, which is free but does not support JavaEE developments.
(see differences here)
In case you are using the Community Edition, you will not be able to manage a Tomcat installation.
In case you are using the Ultimate Edition, you can have a look at:
The FAQ for Netbeans users (see question How do I configure a web framework for my project?).
IntelliJ Ultimate edition "Help": Run/Debug Configuration: Tomcat Server

You can also debug tomcat using the community edition (Unlike what is said above).
Start tomcat in debug mode, for example like this:
.\catalina.bat jpda run
In intellij:
Run > Edit Configurations > +
Select "Remote"
Name the connection: "somename"
Set "Port:" 8000 (default 5005)
Select Run > Debug "somename"

Please verify that the required plug-ins are enabled in Settings | Plugins, most likely you've disabled several of them, that's why you don't see all the facet options.
For the step by step tutorial, see: Creating a simple Web application and deploying it to Tomcat.

The problem I had was due to the fact that I was unknowingly editing the default values and not a new Tomcat instance at all. Click the plus sign at the top left part of the Run window and select Tomcat | Local from there.

In Netbeans you can right click on the project and run it, but in IntelliJ IDEA you have to select the index.jsp file or the welcome file to run the project.
this is because Netbeans generate the following tag in web.xml and IntelliJ do not.
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

Related

How to hot reload Tomcat server in VSCode

I'm migrating from Eclipse IDE (+ VSCode for coding Java servlets and HTML/CSS/JS webpages, respectively) to only Visual Studio Code for its lightweight.
I have several Java extensions installed for VSCode:
Language Support for Java(TM) by Red Hat
Tomcat for Java
Debugger for Java
Eclipse has a series of settings for hot reloading:
- Automatically publish when resources change
- Refresh using native hooks or polling
while VSCode doesn't seem to have any for me.
A few things I've try to reload my Java and web code:
Restart Tomcat server
Delete and re-adding Tomcat server
Delete and regenerate .war package (not sure if this does anything, it can run well without a .war package)
Good news...
It works automatically now. With Tomcat for Java Extension (And the rest of the Java Extension Pack):
https://marketplace.visualstudio.com/items?itemName=adashen.vscode-tomcat
Just make sure your settings are like this (search for "java.autobuild" to get those two in the first results):
Very important is, that you wont see any logs in the console on the HCR (Hot Code Replacement) like it happens in Eclipse ... but you in fact will see the replaced code behavior. Just debug over the piece of code you changed, and you will see it in fact changed in the running server.
UPDATE: I've found it works better with the 'manual'(default) setting. Just clicking once in the lightning icon. (Testing in Ubuntu 18.04 LTS)
[I say it works better because if I added lines to a Class' code with the 'auto' setting it will not add that code ... only if I change code in the existing lines. But with the manual setting I just save the file, and then click the lightning icon wait ~3 seconds myself and debug over the new code ... and everything goes well!!
... This solves my coding needs(lightweight Editor/IDE with Hot-Code-Replacement in Tomcat)]
Enjoy !
This article may be helpful, I migrate from other IDE to Vscode.
According to the article, if you install Debugger for Java, it enabled Hot code replacement(HCR) and then :
You can start a debugging session and change a Java file in your development environment, and the debugger will replace the code in the JVM running your code.
Hot code replacement for java comes to visual studio code
Install “Tomcat for java” extension in VScode.
Configure the Path of Tomcat in the above extension.
Now you should be able to run tomcat in usual build -> deploy mode. Now install DCEVM, By using “java -jar installer-light.jar”. (Select “Install DCEVM as altjvm”)
Place HotSwap Agent Jar in directory of your choice.
Now In VScode right-click the Tomcat server you have created. (The one from Step 3 ) And select “Customise JVM Options”.
In the file opened, Place “-XXaltjvm=dcevm
-javaagent:/[your_directory]/hotswap-agent-1.3.1-SNAPSHOT.jar” Now Right-click the tomcat server in VScode and select “Debug WAR package”, And select the WAR file.
If everything goes well, The WAR will be start in TOMCAT in debug mode with text “HOTSWAP AGENT” in the log.
Now your every save to your file will trigger Hot Reloading.
https://medium.com/#manoj_makkuboy/hot-reload-java-8-tomcat-server-in-vscode-ba6233d632e?

Issue Glassfish 4 doesn't appear glassfish-web

I'm trying to create a descriptor file for my Java web application project.
For this project i am using:
Netbeans 8.0 &
GlassFish 4
When I try to create the glassfish descriptor file. Netbeans shows into the dialog window that is going to create a file called sun-web.xml instead of glassfish-web.xml.
I was looking for this on the internet and found that the first one sun-web.xml is created for version older than 3, and the version 4 should create a file with the name glassfish-web.xml.
I'm following a tutorial where a person is using the same tools that I have. But in the tutorial he can create a glassfish-web.xml file.
Another error raise when I click the finish button with the intention of create the sun-web.xml file and an error popup raise a show me this message:
"Deployment Configuration for this project not found. Deployment descriptor version could not be set properly"
Can't anyone help me please ???
Thank you a lot!!
You should be able to use that sun-web.xml file fine, it might change in a couple of ways like for example when you want to add a security role mapping, NetBeans won't be able to automatically fill in the security role names from your web.xml, but if you fill them in manually and correctly you should be fine.
Actually, I had the same problem, so what I did was erase all versions of Glassfish (I use OSX so I erased the folders from Applications > Netbeans > GlassFish and from Users/MyUser/GlassFish_Server), added a new server in NetBeans Services > Servers > right click add server and follow the wizard, when you get to step 2 (Server location) click download now and that will reinstall glassfish, restart NetBeans and now when you try to create a Glassfish descriptor it should be properly named as glass fish-web.xml
Hope this helps :)
I simply changed version Java EE 7 to Java EE 5 when creating new project at 3rd step Server and Settings and it could create glassfish-web.xml. I'm using same versions of Netbeans and Glasssfish. Hope may this will help you.

Why won't basic spring 4 sample run with Eclipse kepler?

I am using the sample project code here that i've downloaded from the following:
http://javahash.com/spring-4-mvc-hello-world-tutorial-full-example/
Direct link here:
http://javahash.com/wp-content/uploads/2014/02/Spring4MVCHelloWorld.zip
I have Eclipse Kepler SR2 (J2EE), Tomcat 7 64-bit, Java 7.
The project does not appear to be a web project, so I add "Dynamic Web Module" version 3.0 and "Java" (version 1.7) to it. I right click, maven install, which appears to run fine. When I try to actually deploy it on tomcat, it does not give any errors in the console, but when the browser window pops up it shows a 404
http://localhost:8080/Spring4MVCHelloWorld/
HTTP Status 404 - /Spring4MVCHelloWorld/
--------------------------------------------------------------------------------
type Status report
message /Spring4MVCHelloWorld/
description The requested resource is not available.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.39
That said, how do I get this "basic" example running in eclipse? Anyone able to get this working successfully? It feels like it should be more trivial than the 5 hours I've spent on trying to get this sample code working to no avail.
UPDATE:
Still continues to fail despite using Tomcat 7.0 server.
Download the sample, extract contents to workspace directory.
"Import Existing Project" in Eclipse
Since there is no "Run On Server" option, I right click on the imported project directory and hit "Properties".
I go to "Project Facets" and check 2 things: "Dynamic Web Module" (3.0) and "Java" (1.7) and hit apply then "Ok".
I right click on the project Spring4MVCHelloWorld and click "Maven"->"Update Project". Then I click "Run On Server".
There are no errors in the console, but the web browser that pops up in eclipse shows a HTTP STATUS 404.
I tried going to:
http://localhost:8080/Spring4MVCHelloWord/hello
and the same:
HTTP Status 404 - /Spring4MVCHelloWorld/hello
shows up, but the tomcat shows up as:
Apache Tomcat/7.0.53
Note that this is the 64-bit version. What steps am I missing? How do I get around this silent failing?
Apart from what Dimitri stated, your log seems to indicate that you are using
Apache Tomcat/6.0.39
That version of Tomcat does not support ServletContainerInitializer which your Spring web application depends on for configuration. Upgrade to a Tomcat version 7+.
It seems like the Maven update doesn't work for you (or for me).
First, go into Properties -> Deployment Assembly. You need to get rid of Web Content if it's there and add src/main/webapp (which is a maven convention). You also need to add the Maven Dependencies as shown below.
Finally, and this might not be necessary, delete the web.xml provided to you and re-create it by selecting and right clicking Deployment Descriptor in the Project Explorer and clicking Generate Deployment Descriptor Stub.
Also, make sure your Java Build Path in the Properties has a Java 7+ version of the JRE.
As far as I can see your controller only maps to /hello, which means your URL should be:
http://localhost:8080/Spring4MVCHelloWorld/hello
Another thing that might be interesting to you is that if your having problems with certain project facets (like Dynamic Web Module) not being recognized, you can usually fix them by righ clicking your project, opening the Maven menu and choosing Update Project.

Unable to associate project with a runtime server in eclipse IDE

I had created a dynamic web project. AS of now it has a jsp file which am trying to run. When I tried to associate the project with a specific runtime(tomcat 6.0), it is not happening.
I right clicked on the project/properties/Targeted Runtimes. It doesn't show any runtimes(I have added tomcat 6.0 in servers). When I click the checkbox 'Show all runtimes', everything comes in disabled mode.
What could be the problem ?
Attached screenshot of the problem.
Update: I even tried to create a new runtime and associate it with the project( project/properties/Targeted Runtimes/new). Even the newly created runtime is getting disabled and am unable to associate it with the project.
To add a project to a runtime you must have a match between your project and your runtime; you have to check:
project facet: to run on tomcat it must be a Dynamic Web Project
java version: you can't run for example a java 7 project on a java 6 runtime
web project version: you can't run a project that doesn't match the Java EE version deployable in the runtime
Once you've validated the match between your project and the runtime, you need the project to target the runtime, as follows:
Open the project in Package Explorer, Project Explorer, or Navigator.
Right-click on the project, and select "Properties".
Click on "Targeted Runtimes" in the properties window.
Select the checkbox of the validated runtime that is to be targeted.
Confirm by clicking "OK".
The new runtime will be associated with that project. If a runtime that you want to select is not displayed or is disabled, you may need to uninstall one or more of the currently installed project facets. This can be done within the same Properties dialogue.
This is what worked for me. I'm just posting my method because it might help somebody else.
Right-click on project
Click on Properties
Go to Project Facets
Uncheck Dynamic Web Module checkbox
Click on Runtimes in the tabs on the right. Apache Tomcat vX.x should be available now
Check Apache Tomcat vX.x
Click Apply and Close
Repeat the previous steps 1-3
Check Dynamic Web Module checkbox
Apache Tomcat vX.x under Runtimes should still be enabled
Click Apply and Close
I know it's already answered question, but I like to share my solution with new users if I can help..
For me the problem was because of the Dynamic wen Project version,
3.0 work with java 1.7 ( I was using 3.1) . If it didn't work you can access .settings folder in your project,
org.eclipse.wst.common.project.facet.core.xml file
and set the version that you need.
<installed facet="jst.web" version="3.0"/>
Hope I can help new users
I have Found a fix for this problem.
Go to Preferences and Check your Targeted runtime, If No Runtime is displayed you can Configure it through Feacts. Select Dinamic Web module to 3.0 or 3.1
You can Also refer to this Video for Detailed Explanation. :
https://youtu.be/0W6s0hXbmNE

How to deploy portlets to Liferay?

I have faced problems in trying to install new portlets to Liferay running on Glassfish domain. I figured out the flow very lately and want to share it with others also. So, please read the answer and hope this helps someone :)
(Pre requisites for the problem is that I knew that adding projects running on Glassfish is done with a autodeploy folder, but making them visible on Liferay was another story.)
So, you make first a .war file let's say a portlet of name your_file.war. You wanna have it running on a glassfish domain under Liferay portal.
Steps to success:
1) Navigate to Control Panel -> Plugins Installation on Liferay
2) hit Install new portlets
3) hit Configuration
4) Fill in to Deploy Directory a new place for deployment let's say [your domain]/autodeploy2
5) Check that in the next line target is [your domain]/autodeploy (it is the Glassfish default deployment directory)
6) hit save
Now deployment will be done by copy pasting files to that new directory [your domain]/autodeploy2. The rest of it is handled automatically. Setting takes action imediatedly.
Done with deployment: Make a victory jig and enjoy :)
..you stop dancing and face a bug. You want a new revision to be deployed.. In this case, continue reading.
So, you have built your war again and want to re-deploy. Do the following:
1) undeploy old stuff from (your domain)/autodeploy folder by deleting the war file. Don't delete any other file.
2) result is that your_file.war_UnDeployed file will appear.
3) deploy new file by copying the newly built war in (your domain)/autodeploy2 folder.
4) result is that your_file.war_deployed will appear in (your domain)/autodeploy folder.
Make a dance again :)
There is several methods to deploy plugins (portlets, hooks, filters...) into your Liferay Portal.
If you're using Administration you can do it as Mico descripted. but if you're using Maven, Gradle, Ant, Ivi... you can configure their deployment descriptors and redirect their outputs (that are the wars) to the hotdeploy server folder (If you're using Tomcat, JBoss, Glassfish...).
This approach is quite better because you can create backup webapp folder and restore it whenever you want easily.
Below are not for Glassfish but common startup steps:
To install a portlet in lliferay portal
• first install liferay portal from below link
http://www.liferay.com/en_GB/community/wiki//wiki/Main/Liferay+IDE+Getting+Started+Tutorial
this requires installation of
liferay ide
liferay portal bundled with tomcat
add this tomcat as run server time and start it, it will start liferay portal
• create a portlet application
• open liferay at localhost:8080 and goto Admin -> control panel
• goto Plugins Configuration
• goto Intall tab and give location of war file (some logging error might come
at tomcat console, ignore it)
• again goto home page at localhost:8080 and click + button
• go at the bottom in the list and u will find ur portlet
• click add button present at the right side of it and ur portlet would be added to the page.
Modifying code of portel requires to uninstall and install again the portlet from war file.
All existing added portlets would also be modified.

Categories

Resources