суббота, 5 июля 2014 г.

How to run and debug a simple web application on Java (Tomcat) through Intellij IDEA

At first we will need the best tool for java developers Intellij IDEA, simple java web application (will be better if we either will have a Maven Project Object Model file) and Tomcat as servlet container.
Example of my POM file

    4.0.0
    ua.home.webmvc
    WebMVC
    war
    0.0.0.1
    WebMVC

    
        
            public
            http://mvnrepository.com
        
    
    
        
            plugins.public
            http://mvnrepository.com
        
    

    
        WebMVC
    

    
        4.0.3.RELEASE
    

    
        
        
            org.springframework
            spring-core
            ${spring.version}
        

        
            org.springframework
            spring-web
            ${spring.version}
        

        
            org.springframework
            spring-webmvc
            ${spring.version}
        

        
            org.springframework
            spring-context
            ${spring.version}
        

        
            org.springframework
            spring-beans
            ${spring.version}
        

        
            javax.servlet
            jstl
            1.2
            runtime
        

    



Let's open our IDE and choose the option "Open project"

And after that we need open a pom.xml (ofc if we have a Maven Project Object Model file)

As reasult we will see our project in Intellij IDEA

IDEA are able to setup project from maven pom.xml file but for following work You need download a maven distributive. To IDEA is able to work with maven You have to create M2_HOVE variable environement with Maven home path (for example M2_HOME: D:\Install\build_tools\apache-maven-3.2.1) or using IDEA right tool bar as You can see on picture

Since our application is web application we need some web server like a JBoss or just simple servlet container like a Tomcat. Let's download a Tomcat from official site and unpack to some folder We are ready to start our application. Take a look please on next picture and do the same

For the next step we need to adjust a tomcat

On bottom of configuration window appeared warniong message: Warning: No artifacts marked for deployment, for fixing this problem You just need to push a button "Fix" choose any option (I recommend to choose "exploded" option). As You will see IDEA will offer to fill context param and name of run up configuration

That's all :) Our application is ready to start :) Let's try

Example of link for enterence for our application: http://localhost:8080/webmvc/view.do Actually if someone needs example of my application please leave me message in comments
  • OS: Windows 8.1
  • IDEA: 13.1.3
  • Tomcat: 7.0.50
  • Maven: 3.2.1

Комментариев нет:

Отправить комментарий