Tag Archives: Eclipse IDE

How to Create your First Spring Framework Application for CloudBees

1) Install the CloudBees Toolkit for Eclipse plugin in Eclipse IDE.

2) Deploy.

You can find more details here.

A sample is available here.

Advertisements

How to Create your First Spring Framework Application for Heroku

1) Install the Heroku Eclipse plugin in Eclipse IDE.

2) Setup your account.

3) Create a new project from the “Blank Heroku App” template.

4) Add Tomcat to your project:

<!-- Only if using JSPs -->
<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jasper</artifactId>
  <version>7.0.30</version>
</dependency>
<!-- Only if using JSPs -->
<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jasper-el</artifactId>
  <version>7.0.30</version>
</dependency>
<!-- Only if using JSPs -->
<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jsp-api</artifactId>
  <version>7.0.30</version>
</dependency>
<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-core</artifactId>
  <version>7.0.30</version>
</dependency>
<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-jasper</artifactId>
  <version>7.0.30</version>
</dependency>
<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-logging-juli</artifactId>
  <version>7.0.30</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>3.1.2.RELEASE</version>
</dependency>

5) Create a launcher class:

package br.eti.fernandoribeiro.sample.springframework;

import java.io.File;

import org.apache.catalina.startup.Tomcat;

public final class Main {

  public static void main(final String[] args) throws Exception {
    final Tomcat tomcat = new Tomcat();

    tomcat.setPort(Integer.valueOf(System.getenv("PORT")));

    tomcat.addWebapp("/", new File("src/main/webapp/").getAbsolutePath());

    tomcat.start();

    tomcat.getServer().await();
  }

}

6) Add the Application Assembler Maven Plugin to your project:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>appassembler-maven-plugin</artifactId>
  <version>1.2.2</version>
  <configuration>
    <programs>
      <program>
        <mainClass>br.eti.fernandoribeiro.sample.springframework.Main</mainClass>
        <name>webapp</name>
      </program>
    </programs>
  </configuration>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>assemble</goal>
      </goals>
    </execution>
  </executions>
</plugin>

7) Create a web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

8) Create a DispatcherServlet-servlet.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
  <context:component-scan base-package="br.eti.fernandoribeiro.sample.springframework" />
</beans>

9) Create a procfile file:

web: sh target/bin/webapp

10) Deploy.

You can find more details here.

A sample is available here.

How to Create your First Java EE Application for Heroku

1) Install the Heroku Eclipse plugin in Eclipse IDE.

2) Setup your account.

3) Create a new project from the “Blank Heroku App” template.

4) Add Tomcat to your project:

<!-- Only if using JSPs -->
<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jasper</artifactId>
  <version>7.0.30</version>
</dependency>
<!-- Only if using JSPs -->
<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jasper-el</artifactId>
  <version>7.0.30</version>
</dependency>
<!-- Only if using JSPs -->
<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jsp-api</artifactId>
  <version>7.0.30</version>
</dependency>
<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-servlet-api</artifactId>
  <version>7.0.30</version>
</dependency>
<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-core</artifactId>
  <version>7.0.30</version>
</dependency>
<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-jasper</artifactId>
  <version>7.0.30</version>
</dependency>
<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-logging-juli</artifactId>
  <version>7.0.30</version>
</dependency>

5) Create a launcher class:

package br.eti.fernandoribeiro.sample.javaee;

import java.io.File;

import org.apache.catalina.startup.Tomcat;

public final class Main {

  public static void main(final String[] args) throws Exception {
    final Tomcat tomcat = new Tomcat();

    tomcat.setPort(Integer.valueOf(System.getenv("PORT")));

    tomcat.addWebapp("/", new File("src/main/webapp/").getAbsolutePath());

    tomcat.start();

    tomcat.getServer().await();
  }

}

6) Add the Application Assembler Maven Plugin to your project:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>appassembler-maven-plugin</artifactId>
  <version>1.2.2</version>
  <configuration>
    <programs>
      <program>
        <mainClass>br.eti.fernandoribeiro.sample.javaee.Main</mainClass>
        <name>webapp</name>
      </program>
    </programs>
  </configuration>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>assemble</goal>
      </goals>
    </execution>
  </executions>
</plugin>

7) Create a procfile file:

web: sh target/bin/webapp

8) Deploy.

You can find more information here.

A sample is available here.