Showing posts with label tomcat. Show all posts
Showing posts with label tomcat. Show all posts

Running maven web project with maven tomcat7 plugin

With maven tomcat7 plugin you won't have download,install and configure Tomcat server seperately.Maven can do it for you.Just run:
mvn tomcat7:run
with a tomcat7 maven plugin enabled project and browse to localhost:port/path
In your pom.xml simply put this plugin:
  1. <plugin>
  2. <groupId>org.apache.tomcat.maven</groupId>
  3. <artifactId>tomcat7-maven-plugin</artifactId>
  4. <version>2.0</version>
  5. <configuration>
  6. <server>tomcat-development-server</server>
  7. <port>9966</port> <!--make sure port doesnt conflict with others -->
  8. <path>/SpringMVC</path><!--http://localhost:9966/SpringMVC/ -->
  9. </configuration>
  10. </plugin>

Example spring maven hello world web project pom.xml:
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3.     <modelVersion>4.0.0</modelVersion>
  4.     <groupId>com.mohi</groupId>
  5.     <artifactId>SpringMVC</artifactId>
  6.     <packaging>war</packaging>
  7.     <version>1.0-SNAPSHOT</version>
  8.     <name>SpringMVC Maven Webapp</name>
  9.     <url>http://maven.apache.org</url>
  10.     <dependencies>
  11.         <dependency>
  12.             <groupId>org.springframework</groupId>
  13.             <artifactId>spring-webmvc</artifactId>
  14.             <version>4.0.3.RELEASE</version>
  15.         </dependency>
  16.     </dependencies>
  17.     <build>
  18.         <plugins>
  19.             <plugin>
  20.                 <groupId>org.apache.maven.plugins</groupId>
  21.                 <artifactId>maven-compiler-plugin</artifactId>
  22.                 <version>2.3.2</version>
  23.             </plugin>
  24.             <plugin>
  25.                 <groupId>org.apache.tomcat.maven</groupId>
  26.                 <artifactId>tomcat7-maven-plugin</artifactId>
  27.                 <version>2.0</version>
  28.                 <configuration>
  29.                     <server>tomcat-development-server</server>
  30.                     <port>9966</port>
  31.                     <path>/SpringMVC</path>
  32.                 </configuration>
  33.             </plugin>
  34.         </plugins>
  35.     </build>
  36. </project>

Sample code:
Here is a Spring Helloworld maven with tomcat7 plugin example project SpringHelloworldMavenTomcat7PluginExample.zip
Download ,unzip and run:
mvn clean install tomcat7:run
Browse to localhost:9966/SpringMVC/welcome

Getting rid of "java.lang.OutOfMemoryError: PermGen space" in Netbeans 7

In Netbeans 7.4 right click your tomcat server instance and choose properties in Services->Servers task pane:
Select the Platform tab and in the VM Options field set Permgen parameter.Put this code:
  1. -XX:PermSize=512m //512MB memory in this case
And click close.
If this still doesn't work.You can change netbeans.conf file :
Navigate to /etc/ directory in your netbeans installation directory:
Open the file netbeans.conf and look for a line like this:

  1. netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true"

Add permgen parameter's here:
-J-XX:PermSize=512m -J-XX:+CMSClassUnloadingEnabled
Like this:
  1. netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=512m -J-XX:+CMSClassUnloadingEnabled -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true"
Save and close the file.Restart netbeans.