IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tomcat et TomEE Java Discussion :

Intéractions Eclipse <--> Tomcat


Sujet :

Tomcat et TomEE Java

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Novembre 2007
    Messages : 44
    Par défaut [Résolu] Intéractions Eclipse <--> Tomcat
    Bonjour,

    J'ai développé un petit servlet java avec Eclipse et un serveur tomcat.
    Lorsque je lance le servlet depuis Eclipse, tout se passe bien, j'arrive à l'exécuter et il marche parfaitement.
    Pour passer en production : je créé un WAR à l'aide du menu exporter d'Eclipse. Je le copie dans webapp : tout se passe bien, Tomcat detecte/decompresse/installe. Cependant, dès que je lance le servlet, j'ai des messages d'erreur qui empêchent son fonctionnement :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    21-Sep-2009 11:42:18 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet test_Serv threw exception
    java.lang.NullPointerException
    	at test.web.XMLDocument.<init>(XMLDocument.java:47)
    	at test.web.test_Serv.ItemList(test_Serv.java:33)
    	at test.web.test_Serv.doGet(test_Serv.java:58)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    	at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
    	at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574)
    	at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527)
    	at java.lang.Thread.run(Unknown Source)
    21-Sep-2009 11:42:22 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet test_Serv threw exception
    java.lang.NullPointerException
    	at test.web.XMLDocument.<init>(XMLDocument.java:47)
    	at test.web.test_Serv.ItemList(test_Serv.java:33)
    	at test.web.test_Serv.doGet(test_Serv.java:58)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    	at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
    	at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574)
    	at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527)
    	at java.lang.Thread.run(Unknown Source)
    Je suis débutant en développement Web, mais j'ai l'impression que dès que le servlet est exécuté par Tomcat, dès que j'essaye d'avoir accès à des fichiers sur le réseau il ne les trouve pas (d'où les null pointer exception).
    Ce que je comprends pas : queles sont les différences entre Eclipse qui exécute le servlet à l'aide de Tomcat et Tomcat qui exécute le servlet ??

    N'hésitez pas à me demander des trucs si je suis pas clair ou imprécis

    Et surtout....

    Merci d'avance

  2. #2
    Membre éprouvé
    Avatar de Deadpool
    Homme Profil pro
    Inscrit en
    Novembre 2005
    Messages
    1 312
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2005
    Messages : 1 312
    Par défaut
    Bonjour,

    L'idéal serait que l'on ai le code de la classe test_Serv, histoire de pouvoir comprendre le problème.

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Novembre 2007
    Messages : 44
    Par défaut
    test_Serv
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    package test.web;
     
    import java.io.*;
    import java.util.List;
    import java.util.Vector;
    import java.io.File;
     
    import javax.servlet.*;
    import javax.servlet.http.*;
     
    import org.jdom.Element;
    import org.jdom.JDOMException;
    public class test_Serv extends HttpServlet{
    	private static final long serialVersionUID = 1L;
    	// variables d'instance
    	private String title="Conversion checker";
    	private final String HTML1=
    		"<html>" +
    		"<head>" +
    		"<title>"+title+"</title>"+
    		"</head>" +
    		"<body>" +
    		"<p>" +
    		"<img src=\"file:///\\\\10.10.1.4\\ParProjets\\X_system\\conversion_checker\\logo_ITI.bmp\" />" +
    		"</p>"+
    		"<hr>" +
    		"<h3>Choississez un projet à vérifier</h3>"+
    		"<form method=\"POST\">";
    	private final String HTML2="<input type=\"submit\" value=\"Vérifier\">";
    	private final String HTML3="</form>\n</body>\n</html>";
     
    	public Vector<String> ItemList(){
    		Vector<String> vectorList = new Vector<String>();
    		//XMLDocument xmlDoc = new XMLDocument("\\\\10.10.1.4\\ParProjets\\X_system\\liste.xml");
    		XMLDocument xmlDoc = new XMLDocument("N:\\X_system\\liste.xml");
    		try {
    			List<?> liste = xmlDoc.getProjectList(xmlDoc.getRacine());
    			for (int i=0;i<liste.size();i++){
    				Element tempElement = (Element) liste.get(i);
    				String name = tempElement.getAttributeValue(XMLAttributes.NAME);
    				if (name.matches("^[0-9]{4} - [a-z0-9._ -+-]+$")){
    					vectorList.add(name);
    				}
    			}
    		} catch (JDOMException e) {e.printStackTrace();}
    		return vectorList;
     
    	}
    	// GET
    	public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException, ServletException{
     
    		// on indique au client le type de document envoyé
    		response.setContentType("text/html");
    		// on envoie le formulaire
    		PrintWriter out=response.getWriter();
    		// début
    		out.println(HTML1);
    		// combo
    		out.println("<select name=\"cmbValeurs\" size=\"1\">");
    		Vector<String> listeProjets = ItemList();
    		for (int i=0;i<listeProjets.size();i++){
    			out.println("<option>"+listeProjets.get(i)+"</option>");
    		}//for
    		out.println("</select>");
    		// fin formulaire
    		out.println(HTML2+HTML3);
    	}//GET
    	// POST
    	public void doPost(HttpServletRequest request,HttpServletResponse response)
    	throws IOException, ServletException{
    		// on récupère le choix de l'utilisateur
    		String choix=request.getParameter("cmbValeurs");
    		if(choix==null) {
    			doGet(request,response);
    		}else{
    			conversion_check test = new conversion_check();
    			String arg = "\\\\10.10.1.4\\ParProjets\\" +choix+"\\00-ITHIBAULT\\02-TRANSFERT PRODUCTVIEW (CAO)\\MOULE";
    			String reportLink = test.check(arg,true);
    			File[] filesToDelete = new File(".").listFiles((FilenameFilter) new xmlFilter ());
    			for(int i=0;i<filesToDelete.length;i++){
    				filesToDelete[i].delete();
    			}
    			// on prépare la réponse
    			String réponse="<html><head><title>Veuillez ouvrir le rapport généré en cliquant sur le lien</title></head>";
    			réponse+="<body><a href=\"" + reportLink +"\">Lien vers le rapport</a></body></html>";
    			// on indique au client le type de document envoyé
    			response.setContentType("text/html");
    			// on envoie le formulaire
    			PrintWriter out=response.getWriter();
    			out.println(réponse);
    		}
    	}//POST
    }//classe
    La classe XMLDocument (qui plante lorsqu'on essaye de récupérer la racine du fichier chargé)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    package test.web;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.util.List;
     
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.input.SAXBuilder;
    import org.jdom.output.Format;
    import org.jdom.output.XMLOutputter;
    import org.jdom.xpath.XPath;
     
    public class XMLDocument {
    	private org.jdom.Document document;
    	private Element racine;
     
    	/**
             * Gets the XML document root element.
             * @return The XML document root element.
             */
    	public Element getRacine() {
    		return racine;
    	}
    	/**
             * Gets the XML document.
             * @return The XML document.
             */
    	public org.jdom.Document getDocument() {
    		return document;
    	}
    	/**
             * Creates and initializes an XML Document object from an existing XML file.
             * @param filePath The path of the file to initialize the XMLDocument object from.
             */
    	public XMLDocument(String filePath){
    		SAXBuilder sxb = new SAXBuilder();
    		File file = new File(filePath);
    		//TODO if file exists ! sinon erreur :)
    		try
    		{
    			//Creation of of new JDOM document using XML file
    			document = sxb.build(file);
    		}
    		catch(Exception e){e.printStackTrace();}
    		//Initialization of the root element with the XML's root element
    		racine = document.getRootElement();
    	}
    	/**
             * Constructor that creates the XMLDocument object and initializes it.
             * @param rootname The name of the XML's root element to create.
             * @param createFirst Necessarily True.
             */
    	public XMLDocument(String rootname,Boolean createFirst){
    		racine = new Element(rootname);
    		document = new Document(racine);
    	}
    	/**
             * Save the XMLDocument object into an XML file (*.xml).
             * @param FilePathToSave The file path where the file is saved.
             */
    	public void SaveXML(String FilePathToSave){
    		//TODO Tester que le fichier existe sinon renvoyer la bonne erreur
    		File xmlFile = new File(FilePathToSave);
    		try
    		{
    			XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
    			FileOutputStream writer = new FileOutputStream(xmlFile);
    			sortie.output(document,writer );
    			writer.flush();
    			writer.close();
    		}
    		catch (Exception e){}
    	}
    	/**
             * Write attributes of the specified element accordingly to a file (or a directory) on the hard-disk.
             * @param file The file to write attribute from.
             * @param bufferElement The element corresponding to the file in the XML.
             * @param migrateState The state of migration in the process of migration.It doesn't accept null. 'false' correspond to 'non-migrated state' and is the default value.
             */
    	public void writeAttributes (File file, Element bufferElement, Boolean migrateState){
    		if (file != null){
    			bufferElement.setAttribute(XMLAttributes.NAME, file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf('\\') +1).toLowerCase());
    		}
     
    	}
    	public List<?> getProjectList(Element element) throws JDOMException{
    		String xPath = "child::"+XMLAttributes.DIR_ELEMENT;
    		XPath test = XPath.newInstance(xPath.toString());
    		List<?> liste = test.selectNodes(element);
    		return liste;
    	}
    }
    N'hésitez pas si vous avez besoin de plus d'informations

    edit : Est ce possible que ce soit dû à des restrictions sécurité de TomCat qui empêchent l'accès à des fichiers du réseau ? Et qu'Eclipse bypaase ces sécurités ?

  4. #4
    Rédacteur/Modérateur
    Avatar de Laurent.B
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Novembre 2004
    Messages
    3 468
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2004
    Messages : 3 468
    Par défaut
    Bonjour,

    Décompresse ton war exporté et regarde s'il ne lui manque pas un fichier xml, du style le web.xml dans WEB-INF par exemple.
    Responsable FAQ Eclipse | Maintiens et développe un des logiciels destinés aux rédacteurs sur developpez.com
    Gardons toujours à l'esprit que le forum constitue une base documentaire, dont l'utilité et la qualité dépendent du soin apporté à nos questions et nos réponses. Soyons polis, précis (dans le titre et dans le corps des questions), concis, constructifs et faisons de notre mieux pour respecter la langue française et sa grammaire. Merci pour nous (les modérateurs) mais aussi et surtout, merci pour vous.
    Problème solutionné => je vais au bas de la page et je clique sur le bouton (qui suite à mise à jour du forum, a légèrement changé d'aspect).

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Novembre 2007
    Messages : 44
    Par défaut
    Je viens de le faire et tout y est :
    -Mes classes (*.class + sources *.java)
    -Mes librairies (jdom, mail, etc... *.jar)
    -le web.xml, avec les bonnes infos de contexte et mappage servlet,
    -Le manifest.inf, que je sais pas à quoi il sert.

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Novembre 2007
    Messages : 44
    Par défaut
    Je me permet d'upper ma question : malgré toutes mes recherches sur les derniers jours, impossible de trouver une réponse. Je m'en remet donc entièrement à vous !

    Edit : Piste : est ce possible que ce soit dû au fait que Tomcat n'a pas dans son classpath les librairies systèmes à l'inverse de'Eclipse ?
    Dans ce cas là, comment je les configure ?

    Edit de résolution : Tomcat ne savais effectivement pas où se situaient les classes système : je lance donc tomcat via un .bat
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    @echo off
    set CLASSPATH=CLASSPATH;".";"C:\Program Files (x86)\Java\jre6\lib\ext";"C:\Program Files (x86)\Java\jre6\lib"
    call "C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\bin\tomcat6.exe"
    exit

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Eclipse 3.1][Tomcat][Axis]Probleme execution WebService
    Par beZor dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 08/02/2006, 13h55
  2. [Eclipse 3.0] [Tomcat] problème dans la création du .war
    Par lipao17 dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 12/03/2005, 13h45
  3. [ECLIPSE 3.0][Tomcat]
    Par cicko dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 13/12/2004, 14h20
  4. [Plugin][easystruts]Probleme avec eclipse struts et tomcat
    Par chng001 dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 09/10/2004, 09h12
  5. [Eclipse 3.0]Tomcat ne veut plus se lancer
    Par tic42 dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 18/08/2004, 17h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo