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 :

[Embedded Tomcat] premiers pas


Sujet :

Tomcat et TomEE Java

  1. #1
    Membre régulier Avatar de eracius
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    138
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 138
    Points : 81
    Points
    81
    Par défaut [Embedded Tomcat] premiers pas
    Bonjour,

    Je teste actuellement Embedded Tomcat avec Tomcat 6 pour voir comment ça marche et éventuellement l'utiliser plus tard.

    J'ai trouvé un lien qui donnait un exemple d'utilisation mais je n'arrive pas à le faire fonctionner.

    Le problème semble interne à l'architecture de Tomcat puisque la classe Embedded n'arrive pas à créer un connector, certains classes semblant incomplètes. J'ai essayé de mettre les derniers jar les plus à jour que j'ai trouvé dans tomcat 6 (les repository Maven pour Tomcat ne semblant pas très à jour)

    Si vous avez déjà essayé et que vous avez une idée pour mon problème ....

    le code :
    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
     
    1 import java.io.File;
     2 import java.io.IOException;
     3 import java.util.Properties;
     4 
     5 import org.apache.catalina.Context;
     6 import org.apache.catalina.Engine;
     7 import org.apache.catalina.Host;
     8 import org.apache.catalina.LifecycleException;
     9 import org.apache.catalina.startup.Embedded;
    10 import org.slf4j.Logger;
    11 import org.slf4j.LoggerFactory;
    12 
    13 /**
    14  * http://www.blogjava.net/jarod
    15  * @author jarod
    16  */
    17 public class TomcatServer {
    18 
    19     private static final Logger logger = LoggerFactory
    20             .getLogger(TomcatServer.class);
    21 
    22     public static void main(String[] args) {
    23         try {
    24             new TomcatServer();
    25         } catch (Throwable t) {
    26             logger.error("", t);
    27         }
    28     }
    29 
    30     private Embedded tomcat;
    31 
    32     // tomcat主目录
    33     private String catalinaHome;
    34 
    35     private String projectHome;
    36 
    37     public TomcatServer() {
    38         initConf();
    39 
    40         tomcat = new Embedded();
    41         tomcat.setCatalinaHome(catalinaHome);
    42         Engine engine = tomcat.createEngine();
    43         Host host = tomcat.createHost("localhost", projectHome);
    44         host.addChild(tomcat.createContext("", ""));
    45         Context context = tomcat.createContext("/webapp1", "webapp");
    46         // 当以debug模式启动时,修改可立即生效
    47         context.setReloadable(true);
    48         host.addChild(context);
    49         engine.addChild(host);
    50         engine.setDefaultHost("localhost");
    51         tomcat.addEngine(engine);
    52         tomcat.addConnector(tomcat.createConnector("0", 8081, false));
    53         registerShutdownHook();
    54         try {
    55             tomcat.start();
                     Thread.sleep(Long.MAX_VALUE);
    56         } catch (Exception e) {
    57             throw new RuntimeException(e);
    58         }
    59     }
    60 
    61     private void initConf() {
    62         Properties properties = new Properties();
    63         try {
    64             properties.load(TomcatServer.class
    65                     .getResourceAsStream("/tomcat-conf.properties"));
    66             catalinaHome = properties.getProperty("catalina.home");
    67 
    68             File f = new File(".");
    69             projectHome = f.getAbsolutePath();
    70         } catch (IOException e) {
    71             throw new RuntimeException(e);
    72         }
    73     }
    74 
    75     private void registerShutdownHook() {
    76         Runtime.getRuntime().addShutdownHook(new Thread() {
    77             @Override
    78             public void run() {
    79                 try {
    80                     tomcat.stop();
    81                 } catch (LifecycleException e) {
    82                     throw new RuntimeException(e);
    83                 }
    84             }
    85         });
    86     }
    87 }
    trouvé ici

    erreur à l'exécution :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    9 sept. 2008 15:20:27 vsebom.launcher.Launcher main
    GRAVE: 
    java.lang.NoSuchMethodError: org.apache.tomcat.util.IntrospectionUtils.setProperty(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)Z
    	at org.apache.catalina.startup.Embedded.createConnector(Embedded.java:437)
    	at org.apache.catalina.startup.Embedded.createConnector(Embedded.java:384)
    	at vsebom.launcher.Launcher.<init>(Launcher.java:53)
    	at vsebom.launcher.Launcher.main(Launcher.java:21)
    Merci d'avance et bonne journée à tous.

  2. #2
    Membre régulier Avatar de eracius
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    138
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 138
    Points : 81
    Points
    81
    Par défaut
    Personne n'a essayé Tomcat Embdded ici ?

    Même avec une version plus ancienne ça pourrait m'aider à trouver une piste.

    Merci de vous manifester nous pourrons en discuter.

    Bonne journée.

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mars 2007
    Messages : 38
    Points : 47
    Points
    47
    Par défaut
    Salut,

    Ce code fonctionne bien chez moi, avec Tomcat 6.0.18, jdk1.6.0_11.
    As-tu bien ajouté les jars de tomcat à ton classpath ?

  4. #4
    Membre régulier Avatar de eracius
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    138
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 138
    Points : 81
    Points
    81
    Par défaut
    Désolé le topic date d'il y a 6 mois et j'ai laissé tombé depuis, je n'en ai pas encore eu besoin pour mon projet actuel.

Discussions similaires

  1. premier pas dans la vie active
    Par godik dans le forum Emploi
    Réponses: 12
    Dernier message: 10/10/2005, 16h27
  2. [TOMCAT][LOGS]pas d'affichage de trace dans la console
    Par fabszn dans le forum Tomcat et TomEE
    Réponses: 3
    Dernier message: 23/08/2005, 02h28
  3. [debutant] tomcat trouve pas mon servlet
    Par zerovolt dans le forum Tomcat et TomEE
    Réponses: 6
    Dernier message: 28/08/2004, 15h18
  4. [debutant] premier pas avec le SDK directX9
    Par arno2004 dans le forum DirectX
    Réponses: 6
    Dernier message: 27/05/2004, 21h03
  5. Réponses: 2
    Dernier message: 14/04/2004, 19h37

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