Monday, June 20, 2011

java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config

Problem :

When I open a jsp page in the browser, I have the following error :

20:16:32,243 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/getting-spring].[integration]] "Servlet.service()" pour la servlet integration a généré une exception: java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config from BaseClassLoader@74c252{vfs:///opt/jboss/jboss-6.0.0.Final/server/dr_jbossweb-standalone/deploy/getting-spring.war}
        at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:480) [jboss-classloader.jar:2.2.0.GA]


I looked in my pom.xml and I have correct Maven dependencies:



    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <scope>provided</scope>
      <version>1.1.2</version>
    </dependency>
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <scope>provided</scope>
      <version>1.1.2</version>
    </dependency>



So it's Ok.Moreover I checked in my war and there are these dependencies but there is always the error.


Solution


I add jstl-1.1.2.jar in the directory lib (in JBoss 6 for example you can add in  jbossweb-standalone/lib)


Note : You can find this jar on Maven repositories : here

Sunday, June 19, 2011

Maven Spring MVC 3 with JBOSS 6 example

Goals :

The main goal of this example is to show a maven configuration for Spring MVC3 and JBoss 3 (without database).
The source code is available on Google code : http://code.google.com/p/lin-mon-webapp/ (cf tutorial1 in wiki)


Project :



Maven :

We use the Spring's version 3.0.5 because older version doesn't work with JBOSS 6 (there is a bug with VFS).



Here is my pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>fr.dr.monitor</groupId>
    <artifactId>monitor</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Monitor app</name>
    
    <dependencies>
      <dependency>
            <groupId>org.springframework</groupId>
     <artifactId>spring-beans</artifactId>
     <version>${org.springframework.version}</version>
      </dependency>

      <dependency>
    <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
    <version>${org.springframework.version}</version>
      </dependency>
      <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
     <version>${org.springframework.version}</version>
      </dependency>

      <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      </dependency>   

      <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>1.1.2</version>
      </dependency>
      <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.1.2</version>
      </dependency>

      <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.5</version>
      <scope>runtime</scope>
      </dependency>
      <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.14</version>
      </dependency>
</dependencies>

<build>
<finalName>monitor</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<verbose>true</verbose>
</configuration>
</plugin>
<!-- Permet de créer un projet eclipse avec Maven -->
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.4</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
  
<properties>
     <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
</project>


src/main/resources/spring.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/tx/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire="byName">
<!--
Activates various annotations to be detected in bean classes: Spring's
@Required and @Autowired, as well as JSR 250's @PostConstruct,
@PreDestroy and @Resource (if available) and JPA's @PersistenceContext
and @PersistenceUnit (if available).
-->
<context:annotation-config/>
</beans>



/WEB-INF/web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
   <display-name>Maven Spring MVC 3 with JBOSS 6 </display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/spring.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>     
  
   <!-- declare la servlet frontale centrale  -->
   <servlet>
<servlet-name>monitor</servlet-name>
<display-name>monitor</display-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>/WEB-INF/monitor-servlet.xml</param-value>
    </init-param>
<load-on-startup>1</load-on-startup>
   </servlet>
  
   <servlet-mapping>
<servlet-name>monitor</servlet-name>
<url-pattern>/</url-pattern>
   </servlet-mapping>
</web-app>


/WEB-INF/monitor-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Fichier de conf du contexte d'application pour spring (fichier nommé spring-mvc-webapp-servlet.xml selon la convention. -->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire="byName">
<!-- - Tous les controlleurs sont automatiquement détectés grâce à l'annotation @Controller.
- On définit ici dans quel package le post processor doit chercher ces beans annotés. -->
   <context:component-scan base-package="fr.dr.monitor.controller"/>   
<!-- Activates various annotations to be detected in bean classes: Spring's
@Required and @Autowired, as well as JSR 250's @PostConstruct,@PreDestroy and 
@Resource (if available) and JPA's @PersistenceContext & @PersistenceUnit.
-->
<context:annotation-config/>
<!--
- Les controlleurs de cette application fournissent une annotation @RequestMapping 
- Qui peuvent être déclaré de deux manière différentes:
-  Au niveau de la classe : 
-      par exemple @RequestMapping("/addVisit.html")
-      Pour ce type de controlleurs on peut annoter les méthodes pour une requete Post ou Get,
- Au niveau de chaque méthodes, différents exemples  seront fournis.  
-->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<!--
Ceci est le view resolver, il permet de définir la technologie de vue utilisée et comment
sélectionner une vue. Ici on prendra la solution la plus simple elle permet de mapper 
le nom de la vue retournée avec la sélection d'une jsp. Ex. si le nom de la vue retournée est "hello" alors on utilisera le fichier
WEB-INF/jsp/hello.jsp pour constuire la vue. 
-->
<bean 
 class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
 p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
</beans>


/WEB-INF/jsp/index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page isELIgnored ="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home</title>
</head>
<body>

Bonjour ${name},

</body>
</html>


fr.dr.monitor.controller.MainController

package fr.dr.monitor.controller;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


@Controller
public class MainController  {

 final Logger logger=Logger.getLogger(getClass().getName());

 /**
    * Handler de la méthode Get pour l'URL /helloSpringMVC.html. 
    * 
    * @param name le nom que l'on doit afficher dans la vue.
    * @param model une map de toutes les données qui seront utilisables dans la vue 
    * @return le nom de la vue qu'il faudra utiliser.
    */
  @RequestMapping(value="/")
  public  String toIndex(
    @RequestParam(value="name",required=false) String name, 
    ModelMap model) 
  {
logger.info(">toIndex");
    model.addAttribute("name",name);
    logger.info(">add attribute name " + name);
    
    // on utilisera donc le fichier /WEB-INF/jsp/index.jsp
    //au regard de la stratégie de résolution des vues 
    //utilisée dans cette application.
    return "index";
  }

}

Réferences :

Sunday, November 21, 2010

Project status

Hi all,

This week I tried to put maven for the "sweetydontforget" project without success ... So I've create a classical structure for GWT project and add the first login box. Now I add to learn more with GWT.

Sunday, November 14, 2010

Project status

- Source code has been commit.(It's only the source code you obtain when you create a new Google web application)
- First documentation of the project about installation.(on the project's wiki).

So now the project does nothing ...

News

For now tasks are :
- Configure project.
- Begin installation documentation.

Saturday, November 13, 2010

Sweety Don' t forget ....

Every time, I hear something like :
Sweety , after work, don't forget to take the bread ...

And every time, I forget ! So I decided to create a we project that will resolve my problem ! Ambitious ? isn't it !
I have just created a new project on google code
In this project, we will use GWT, java and many many cool things !
All the project news will be publish on sweetydontforget label.

Note about project status : I will try to be regular in work and to produce code and documentation often ... ( At the project's beginning it's always like that ...)

Saturday, June 12, 2010

java.lang.ClassCastException: org.hibernate.type.StringType cannot be cast to org.hibernate.type.VersionType

Problème


java.lang.ClassCastException: org.hibernate.type.StringType cannot be cast to org.hibernate.type.VersionType

Solution
        <version name="version" type="string">
           
        version>


I rename version in property and i also rename the field of my table.

In file.hbm.xml :

        <property name="arteVersion" type="string">
           
        property>

In Mysql :  alter table t_dependency CHANGE version dep_version VARCHAR(150);