I'm not well experienced in java.
I build a UI using JSP for my servlets to get input data from users. Everytime I want to see the UI and how the Servlets are performing I have to do all thses steps over and over again,
create the war file by mvn clean install
Copy war file to Webapps folder
restart apache tomcat
View the result using the url
I want to know if there is a command that i can use to rerun apache tomcat with the war file im building at once, So that i only have to refresh the webpage to see the result. Or any method that is easier than above.
I use Intellij Idea.
Thanks in advance.
IntelliJ IDEA Community Edition does not support J2EE, but you can also achieve this in the following two ways. For full support of tomcat, you can buy IntelliJ IDEA Enterpries Edition.
Use maven-compiler-plugin
1) Add this plugin to your pom.xml:
<build>
<finalName>mvn-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
</plugin>
</plugins>
</build>
2) Then run this command:
mvn tomcat:run
Or Install Tomcat Runner Plugin
Refer to this link for usage of this plugin.
May be this will help you to deploy the war file on server
I've been looking for this all-over the internet and somehow I can't find a easy way to do it.
What I need is really simple and I believe that many of you probably do it already:
- I develop Java Web Apps in Eclipse and so does my team;
- we have a tomcat7 server running on a Ubuntu machine which works as a centralized Dev environment;
- I would like to click a deploy button and send the new data to the server and deploy it (reload it), instead of exporting a war every time and manually upload it to server.
Up till now seems like the only way to do it is with Maven plugin for eclipse, which uses the manager/HTML interface of tomcat.
Problem: I just can't get it to work. But somehow I can't find a simple walk through that explains how to do it. I'm not too experienced with eclipse or Linux but the configuration of local tomcat servers seems pretty straightforward. I don't understand why is so hard to install a remote one.
Could you please help me out by explaining in detail how to do it? Thank you in advance for you patience.
Yes, you can use Tomcat7 Maven Plugin. Here is the steps:
1) Install Maven Integration for Eclipse (m2eclipse) to your eclipse from Eclipse Marketplace etc.
1.1) Navigate to Help -> Eclipse Marketplace and search "Maven Integration for Eclipse".
2) From eclipse, create a maven project.
2.1) Navigate to File -> New -> Project... -> Maven -> Maven Project.
2.2) Click Next (Leave all fields with default).
2.3) Select "maven-archetype-webapp" and click Next.
2.4) Enter arbitrary value on Group Id and Artifact Id. (e.g. "org.myorg" for Groupd Id and "myapp" for Artifact Id) and click Finish. (You will see pom.xml in your project's root.)
3) Edit pom.xml like this: (Replace yourhost below with your hostname or ip address.)
<project ...>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<url>http://yourhost:8080/manager/text</url>
</configuration>
</plugin>
</plugins>
</build>
</project>
4) Add following lines to your CATALINA_BASE/conf/tomcat-users.xml and restart your tomcat.
<tomcat-users>
...
<role rolename="manager-script"/>
<user username="admin" password="" roles="manager-script"/>
</tomcat-users>
5) From eclipse, run tomcat7:redeploy goal.
5.1) Right click your project and navigate to Run As -> "Maven build...".
5.2) Enter tomcat7:redeploy to Goals and click Run.
6) Once you create the run configuration setting above, you can run tomcat7:redeploy goal from Run -> Run Configurations.
Please refer to the following documents for details:
http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Configuring_Manager_Application_Access
http://tomcat.apache.org/maven-plugin-2.1/index.html
http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/plugin-info.html
If you use another user instead of admin with empty password (which is plug-in's default), you need to create %USERPROFILE%.m2\settings.xml and edit pom.xml like below:
%USERPROFILE%.m2\settings.xml:
<settings>
<servers>
<server>
<id>tomcat7</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
</settings>
%USERPROFILE% is your home folder. (e.g. C:\Users\yourusername)
pom.xml:
<configuration>
<server>tomcat7</server>
<url>http://localhost:8080/manager/text</url>
</configuration>
Add server tag.
I am currently working on a web app in Eclipse that I plan to push to Heroku. I am using the maven Eclipse plugin (m2e) for downloading dependencies for my app. Maven works great except for one thing.
Maven is downloading all my dependencies into ~/.m2 which is fine except for one thing. When I push my app up to Heroku those dependencies won't go up with it, so I need the dependencies within the project file system. So my problem is finding the best way (or any way in fact) to get the dependencies into my project.
I'm still a noob so any help is appreciated!
If you have a maven plugin in your eclipse, you can configure this directory on:
Window - Preferences -> Maven -> User Settings
But this is not you problem, because this maven file system is just to archive your repositories and the maven don need download it everytime.
Maybe you need to configure a war plugin in yout pom.xml.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Is it possible to run a web application using Tomcat Server in Intellij Idea Community Edition?
I tried to find some information about it but haven't achived any success.
Intellij Community does not offer Java application server integration. Your alternatives are
buying Intellij licence,
switching to Eclipse ;)
installing Smart Tomcat plugin https://plugins.jetbrains.com/plugin/9492, make following settings (image)
installing IDEA Jetty Runner plugin https://plugins.jetbrains.com/plugin/7505
running the application server from Maven, Gradle, whatever, as outlined in the other answers.
I personally installed the Jetty Runner plugin (Jetty is fine for me, I do not need Tomcat) and I am satisfied with this solution. I had to deal with IntelliJ idea - Jetty, report an exception, though.
If you are using maven, you can use this command mvn tomcat:run, but first you add in your pom.xml this structure into build tag, just like this:
<build>
<finalName>mvn-webapp-test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Using Maven, try tomcat7-maven-plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<contextFile>src/main/webapp/WEB-INF/config/app-config.xml</contextFile>
<mode>context</mode>
<charset>UTF-8</charset>
<warDirectory>target/${project.artifactId}-${project.version}</warDirectory>
</configuration>
</plugin>
</plugins>
</build>
Run it using tomcat7:run-war
More goals here
Tomcat (Headless) can be integrated with IntelliJ Idea - Community edition.
Step-by-step instructions are as below:
Add tomcatX-maven-plugin to pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>SampleProject</path>
</configuration>
</plugin>
</plugins>
</build>
Add new run configuration as below:
Run >> Edit Configurations >> + >> Maven
Parameters tab ...
Name :: Tomcat
Working Directory :: Project Root Directory
Command Line :: tomcat7:run
Runner tab ...
VM Options :: <user needed options>
JRE :: <project needed>
Invoke Tomcat in Run/Debug mode directly from IntelliJ Run >> Run/Debug menu
NOTE: Though this is considered a hacking of using using Tomcat integration features of IntelliJ - Enterprise version features, but I would consider this a programmatic way integrating tomcat to the IntelliJ Idea - community edition.
Yes, you can use maven plugin, or simple java program. No need for IDE plugin.
See for example Main class from https://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat
Tomcat can also be integrated with IntelliJ Idea - Community Edition with Tomcat Runner Plugin.
Details below:
https://plugins.jetbrains.com/plugin/8266-tomcat-runner-plugin-for-intellij
The maven plugin and embedded Tomcat are usable work-arounds (I like second better because you can debug) but actual web server integration is a feature only available in intelij paid editions.
Yes, its possible and its fairly easy.
Near the run button, from the dropdown, choose "edit configurations..."
On the left, click the plus, then maven and rename it "Tomcat" on the right side.
for command line, enter "spring-boot:run"
Under the runner tab, for 'VM Options', enter "-XX:MaxPermSize=256m -Xms128m -Xmx512m
-Djava.awt.headless=true" NOTE: 'use project settings' should be unticked.
For environment variables enter "env=dev"
Finally, click Ok.
When you're ready to press run, if you go to "localhost:8080/< page_name > " you'll see your page.
My pom.xml file is the same as the Official spring tutorial
Serving Web Content with Spring MVC
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-serving-web-content</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Well the question is already answered, however what I am writing here is just my observation so other fellows in the community can save some of their time.
I tried running a spring-mvc project using the embedded tom-cat in Intellij communit edition.
First try I did was using the Gradle tom-cat plugin, however the problem that I faced there is the tomcat server just starts once, after that from the second start the build complains saying that a container is already running.
There are so many open thread on the web about this, for some it works and for most of the people (almost 90% of the web threads that I broke my head with, faced the same problem of container not getting started the second time. The resolution is not there.
After wasting a lot lot of my time, I finally decided to switch to maven tom-cat plugin and do the same spring-mvc setup with maven that I did with gradle and VOILA! it worked in the first short.
So long story short, if you are setting up spring-mvc project in intellij community edition, please consider maven tomcat plugin.
Hope this helps somebody's hours of exploration across various web forums.
Using Tomcat 9 in IntelliJ IDEA Community Edition without installing any plugin
Note: Make sure environment variables JAVA_HOME and CATALINA_HOME is set. And in case value for JAVA_HOME or CATALINA_HOME is reset recently then restart IntelliJ IDEA before proceeding further.
First open the project in IntelliJ IDEA and then click on File > Settings... > Tools > External Tools, then click on the + button.
Then we have to specify the Name for the Tomcat, then in the Program we
have to specify the path for the catalina.bat file in the bin folder in
the folder where Tomcat is installed, then in Arguments we have to write jpda run and then click on Ok and then on Apply.
After that we can we run the Tomcat by clicking on Tools > External Tools > name_you_provided_for_tomcat.
Then we have to put the necessary files of the application we want to host on the Tomcat in the webapps folder in the folder where Tomcat is installed.
You can use tomcat plugin with gradle. For more information, you here.
apply plugin: 'tomcat'
dependencies {
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.2.4'
}
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
[tomcatRun, tomcatRunWar, tomcatStop]*.stopPort = 8090
[tomcatRun, tomcatRunWar, tomcatStop]*.stopKey = 'stfu'
tomcatRunWar.contextPath = "/$rootProject.name"
tomcatRunWar.ajpPort = 8000
if (checkBeforeRun.toBoolean()) {
tomcatRunWar { dependsOn += ['check'] }
}
I used Jay Lin's answer. Highly recommend it.
If you never used Maven before and don't want to go deep into it: follow Jay Lin's answer, but also do this:
right click on your project name -> Add Framework support -> Maven.
Then install maven from here http://maven.apache.org/install.html. Do what it says, run the commands.
Then install spring-boot from here https://mvnrepository.com.
Then follow the error messages if there are any - maybe you would need to install some other stuff (just google it and that mvnrepository.com would come up). To install use this command:
mvn install:install-file -DgroupId= -DartifactId= -Dversion= -Dpackaging=jar -Dfile=path
replace path with where you downloaded the jar file, replace version, group and artifact id with info from mvnrepository.com.
Further errors I encountered:
I had to create a class in src/main/java (with simple System.out.println command in main) and add <start-class>main.java.Hello</start-class> in <properties> tag in pom.xml. Btw, the pom.xml should appear itself when you do the first action from my answer - copy paste Jay Lin's code there.
Another error I got was connected to JAVA_HOME variable and the verion stuff. Somewhy it thought jdk is 7th version and I was telling it was 8th. So I changed the java version tag in <properties> to this <java.version>1.7</java.version>.
Now it works fine! Good luck everyone.
If you use Gradle, you can try my script: https://github.com/Adrninistrator/IDEA-IC-Tomcat .This script will build files for web application, create a Tomcat instance, start Tomcat and load the web application.
I think maven is not installed properly. check with mvn --v
or
Please check maven home path in env variables
or you have created this project before the installation of maven
I am using intellij CE to create the WAR, and deploying the war externally using tomcat deployment manager. This works for testing the application however I still couldnt find the way to debug it.
open cmd and current dir to tomcat/bin.
you can start and stop the server using the batch files start.bat and shutdown.bat.
Now build your app using mvn goal in intellij.
Open localhost:8080/ **Your port number may differ.
Use this tomcat application to deploy the application, If you get the authentication error, you would need to set the credentials under conf/tomcat-users.xml.
For Intellij 14.0.0 the Application server option is available under
View > Tools window > Application Server (But if it is enable, i mean if you have any plugin installed)
VM :-Djava.endorsed.dirs="C:/Program Files/Apache Software Foundation/Tomcat 8.0/common/endorsed"
-Dcatalina.base="C:/Program Files/Apache Software Foundation/Tomcat 8.0"
-Dcatalina.home="C:/Program Files/Apache Software Foundation/Tomcat 8.0"
-Djava.io.tmpdir="C:/Program Files/Apache Software Foundation/Tomcat 8.0/temp"
-Xmx1024M
Hi I have multimodule maven project something like this..
parent
Core
Web
and my Web project depend on Core project classes so i added Core project as a dependency in Web project pom.xml file.
But from inside eclipse when i am running Web project the lib directory does not contain Core-project.jar file in class-path so project not running. How can resolve this issue?..Plugin I used in my Web Projec *Pom.xml* file..
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
</plugin>
</plugins>
And i am using Tomcat6 Server.
this Dependency tag in my Web Project pom.xml File...
<dependency>
<groupId>org.csdc</groupId>
<artifactId>core-java</artifactId>
<version>5.0.0</version>
</dependency>
And When i run web project from inside Eclipse i am not getting core.jar in this path....
workspace_maven.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\web\WEB-INF\lib
Anyone got any such issue .If yes please let me know how can i resolve this issue?
Under Eclipse : you do not need to have your core.jar in your classpath. Check your librairies (web->properties->java build path->librairies), you should see your core folder and not your core.jar.
Make sure that "resolve workspace dependencies" is checked in your maven build target.
Install the m2e and m2e-wtp plugins for eclipse. m2e-wtp handles web projects and tomcat. You don't need the plugins sections of your pom that you've documented in the question.
For maven to work with projects in eclipse you need to ensure that the parent project is at the same level as the child projects and the pom of the parent project is like below
<modules>
<module>../project1</module>
<module>../project2</module>
</modules>
Unfortunately this is the only way to get maven to work correctly in eclipse and jenkins for multi-module builds.
Not exactly clear that this is what you are looking for, but the jars won't appear under your lib directory in eclipse because they are in your repository.
My version of eclipse has a 'maven' menu when I right click on the project. If yours does too then make sure that you have 'Enable Maven Nature' selected. This will make a small M appear next to the project name and a new folder in the project, which contains all of the dependencies listed in your pom.
1.Go to web project build path -> Libraries - Add variable -> Configure Variables -> New -> Enter Name as M2_REPO and Path as C:\Users\usernmee.m2\repository and click Ok.
All the dependencies will configured in the project build path. So no compilation error in web projecct.
2.Maven project need to take war and deploy it in any web container(tomcat,etc).
Check the war in your target directory after running mvn clean package. If it is missing there, check the scope of your dependency for "Core" in your pom.xml for "Web", make sure that it is not provided or test.
It sounds like from your pom fragment that you are using mvn eclipse:eclipse (which you shouldn't be anymore), instead use the m2eclipse plugin: http://www.sonatype.org/m2eclipse.
Install the correct set of plugins and configure them correctly.
If you need a more detailed answer, you should give us more information what you tried to achieve, which plugins you use, what kind of web server, how you deploy, whether you use Maben to deploy or the Eclipse WTP, etc.
[EDIT] You won't see anything in project/WEB-INF/lib when you start the project in Eclipse - there is no point putting anything in there because this folder isn't used.
Instead, you probably deploy the project to a web server. There are plugins for Eclipse which can do that (i.e. start a web server, deploy your project into it) but since you don't mention how exactly you "start" the project inside of Eclipse, which version of Eclipse you're using and which buttons you click, how you configured Eclipse, etc. it's really hard to help you.