37

My basic workflow is in terminal mvn clean install on my base directory. This creates a target directory with a WAR file. I copy that war file into the webapps directory of my Tomcat.

If I make changes I obviously have to repeat the process which is tedious. I am using Intellij Ultimate 13.1.6 and I know it is possible to have all of this done through the IDE based on this guide.

So before I begin I run mvn clean on my base which removes the target directory.

Now to start I when into the Project Structure --> Artifacts and created a new Web Application: Archive. I named it project_name and it had a different output directory by default (baseDir/out/artifacts/project_name vs baseDir/target) which I left everything default and hit ok.

Now I go to Run --> Edit Configurations and create a new Local Tomcat Server using the following settingsenter image description here

and in the Deployment Tab I add the artifact which is built in my Before launch as seen in my picture. Pretty straightforward.

However, whenever I run the server through Intellij it successfully starts but nothing is deployed. I get the error:

Artifact project_name: com.intellij.javaee.oss.admin.jmx.JmxAdminException: com.intellij.execution.ExecutionException: /Users/path/to/workspace/project_name/out/artifacts/project_name/project_name.war not found for the web module.

And I double check my directory and as seen in the error, nothing is created. Not even the out directory.

What am I doing wrong? I know one workaround is to go back to terminal, run mvn clean install and with that .war file that is created, put that into the deployment configuration. I felt like that was more of a hack since I am still doing it through command line and if I don't have it already built I can't set the target as a directory to find the war file.

Any assistance is appreciated.

Community
  • 1
  • 1
Joey
  • 1,724
  • 3
  • 18
  • 38

7 Answers7

49

Checklist of things you can do to verify where things go wrong:

  1. Manually build the artifacts using Build > Build artifacts.
  2. Verify if the artifact is in the expected output directory (out/artifacts/xxx).
  3. If not, go to File > Project structure > Artifacts
  4. Select the artifact file in question (project_name in this case).
  5. Verify if the output directory is correct. Optionally try to create this directory yourselves in case IntelliJ doesn't do it (although this would surprise me)
  6. Verify if the contents are correct.
  7. Optionally check "Build on make" to always have the latest version of your code deployed whenever you run the server.

Note that for deploying WAR files to a Tomcat, you should prefer to use the exploded WAR. This makes deploying/testing/debugging significantly faster.

Pavlo
  • 43,301
  • 14
  • 77
  • 113
xaviert
  • 5,653
  • 6
  • 29
  • 31
10

I got this error when I tried to launch an app by using Run. The problem was that for some reason the WAR file wasn't deployed even after selecting Build->Build Artifacts. Solution: I closed Idea then reimported the project and choose as artifact war-exploded. This time the deploy worked.

vovahost
  • 34,185
  • 17
  • 113
  • 116
  • This did work for me and it happens exactly in the same way every thing was correct but the deploy was not working when i reimported the project everything went perfect. Just to give more info i used the IntelliJ version 2018.2 just in case some on else has this issue. Thanks vovahost! – Ismael Terreno Oct 17 '18 at 17:38
6

I get this issue, the reason is in Project Structure, the Artifacts' Output directory is not really exists:

enter image description here


Solutions:

  1. Goto Project Structure:

File -> Project Structure

  1. Then click the directory button

enter image description here

  1. You create the directory one by one according to the Output directory shows:

enter image description here

  1. Then restart your Project.
aircraft
  • 25,146
  • 28
  • 91
  • 166
  • Worked for me. I just pointed to `target` directory. Idea really should be more specific with its error message when this is the case. Or autocreate a directory the artifact points to. It always some 30 minutes wasted when trying to run a new Spring project in Idea – parsecer Nov 10 '20 at 02:27
5

I had the same problem and none of the above solutions solved the problem. Sharing it here in case someone else encounters the same issue.

The Tomcat server in my case was configured to run the JMX port on 18099 instead of 1099. Therefore the artifact was never deployed since the JMX port used in the IntelliJ Tomcat configuration by default is 1099.

Changing it to 18099 or removing that particular Tomcat configuration solved the issue.

The bottom line: if you want your artifact deployed, make sure the JMX port configured in IntelliJ matches the JMX port that is actually used by your Tomcat server.

isaac.hazan
  • 3,772
  • 6
  • 46
  • 76
0

Check the output directory path. NOTE that using ~ in the path won't work.

Rammgarot
  • 1,467
  • 14
  • 9
0

I was also facing the same issue in tomacat 9 . It seems intellij doesn't create "out" folder automatically (or in my case it didnt create it). so I built "War exploded" instead of "war" file , and that worked for me.follow the bellow steps:

  1. Delete the existing "war" file ( project Structure -> artifacts -> ) then select the "war" file and delete it.

  2. Invalidate cache

  3. Then create an "war exploded" file (project Structure -> artifacts -> "+" sign(Add) -> Web Application: Exploded -> From modules(select your module) ).

  4. Then from "Build" menu manually build the created "exploded war" file.

rafi
  • 306
  • 1
  • 8
-1

I tried the above solutions but the WAR file didn't work when I deployed it to the tomcat server. Instead of the above solutions, simply type mvn clean and then mvn install in the terminal window. Your WAR file is now located in

ProjectName/target/
Crabigator360
  • 822
  • 10
  • 9