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

Java Discussion :

Créer un fichier jar sans avoir de main()


Sujet :

Java

  1. #1
    Débutant   Avatar de t.n.b.g
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    237
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 237
    Points : 99
    Points
    99
    Par défaut Créer un fichier jar sans avoir de main()
    bonjours j'ai un programme en java et je veux crée un fichier JAR associé, mais le problem c'est qu'l me demande la methode main or dans le code j'en utilise pas
    voila 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
     
    package parser;
    import java.applet.*;
    import java.awt.event.*;
    import java.awt.*;
     
    //import javax.swing.tree.TreeModel;
     
    public class ParserXML extends Applet{
    	private static final long serialVersionUID = 1L;
    	static PARSER P;
    	TextField fichier;
    	Button par=new Button("Parser");
    	String sFile="";
     
    	public void init(){
    		fichier=new TextField("",20);
    		par.addActionListener(new ParserFile());
    		add(fichier);
    		add(par);
    }    
    	PARSER s=new PARSER();
     
    	class ParserFile implements ActionListener{
     
    		public void actionPerformed(ActionEvent e){
    			sFile=fichier.getText();
    			//s.PARSER(sFile);
    			s.Construire(sFile);
    		}
    	}
    }
    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
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
     
    package parser;
     
    import java.io.File;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreeModel;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
     
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    import org.xml.sax.*;
    //import org.xml.sax.helpers.*;
    //import javax.xml.parsers.* ; 
    //import java.io.* ; 
    //import java.util.*;
    public class PARSER {
    	public void Construire(String NameFile){
    		JFrame frame = new JFrame("ANIS PARSER XML");
    		PARSER parser = new PARSER();
    		JTree tree = new JTree(parser.parse(NameFile));
    		frame.getContentPane().add(new JScrollPane(tree));
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setSize(300, 400);
    		frame.setVisible(true);
    }
      public TreeModel parse(String filename) {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        XMLTreeHandler handler = new XMLTreeHandler();
        try {
          // Parse the input.
          SAXParser saxParser = factory.newSAXParser();
          //saxParser.parse(new File(filename), handler);
          File f =new File(filename);
          saxParser.parse( f, handler);
        } catch (Exception e) {
          System.err.println("File Read Error: " + e);
          e.printStackTrace();
          return new DefaultTreeModel(new DefaultMutableTreeNode("Error:   "  +e));
        }
        return new DefaultTreeModel(handler.getRoot());
     
      }
     
      public static class XMLTreeHandler extends DefaultHandler {
        private DefaultMutableTreeNode root, currentNode;
        public void error(SAXParseException saxparseexception)throws SAXException {
              System.out.println("Error");
             }
     
       public void fatalError(SAXParseException saxparseexception)throws SAXException {
              System.out.println("FATAL error");
             }
        public DefaultMutableTreeNode getRoot() {
          return root;
        }
     
        // SAX Parser Handler methods...
        public void startElement(String namespaceURI, String lName,
            String qName, Attributes attrs) throws SAXException {
          String eName = lName; // Element name
          if ("".equals(eName))
            eName = qName;
          Tag t = new Tag(eName, attrs);
          DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(t);
          if (currentNode == null) {
            root = newNode;
          } else {
            // Must not be the root node...
            currentNode.add(newNode);
          }
          currentNode = newNode;
        }
     
        public void endElement(String namespaceURI, String sName, String qName)
            throws SAXException {
          currentNode = (DefaultMutableTreeNode) currentNode.getParent();
        }
     
        public void characters(char buf[], int offset, int len)
            throws SAXException {
          String s = new String(buf, offset, len).trim();
          ((Tag) currentNode.getUserObject()).addData(s);
        }
      }
     
      public static class Tag {
        private String name;
     
        private String data;
     
        private Attributes attr;
     
        public Tag(String n, Attributes a) {
          name = n;
          attr = a;
        }
     
        public String getName() {
          return name;
        }
     
        public Attributes getAttributes() {
          return attr;
        }
     
        public void setData(String d) {
          data = d;
        }
     
        public String getData() {
          return data;
        }
     
        public void addData(String d) {
          if (data == null) {
            setData(d);
          } else {
            data += d;
          }
        }
     
        public String getAttributesAsString() {
          StringBuffer buf = new StringBuffer(256);
          for (int i = 0; i < attr.getLength(); i++) {
            buf.append(attr.getQName(i));
            buf.append("=\"");
            buf.append(attr.getValue(i));
            buf.append("\"");
          }
          return buf.toString();
        }
     
        public String toString() {
          String a = getAttributesAsString();
          return name + ": " + a + (data == null ? "" : " (" + data + ")");
        }
      }
     
      //public static void main(String args[]) {
        //JFrame frame = new JFrame("ANIS PARSER XML");
        //PARSER parser = new PARSER();
        //JTree tree = new JTree(parser.parse("bdd.xml"));
        //frame.getContentPane().add(new JScrollPane(tree));
        //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //frame.setSize(300, 400);
        //frame.setVisible(true);
      //}
    }
    comment faire?

  2. #2
    oca
    oca est déconnecté
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    354
    Détails du profil
    Informations personnelles :
    Âge : 51
    Localisation : Suisse

    Informations forums :
    Inscription : Octobre 2004
    Messages : 354
    Points : 421
    Points
    421
    Par défaut
    Pas besoin de "main" pour faire un jar...
    tu as essayé de faire ton jar avec quel outil ?

    Un jar, c'est juste un fichier zip qui contient les fichiers ".class"
    et qui a une extension ".jar"

  3. #3
    Débutant   Avatar de t.n.b.g
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    237
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 237
    Points : 99
    Points
    99
    Par défaut
    avec eclipse

  4. #4
    Expert confirmé
    Avatar de krachik
    Inscrit en
    Décembre 2004
    Messages
    1 964
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 1 964
    Points : 4 015
    Points
    4 015
    Par défaut
    Bonjour
    Tu peux utiliser fatjar (cf la FAQ

    Cordialement
    Je suis ce que je suis grâce à ce que nous sommes tous Humanité aux Humains!! !

    Entre ce que je pense, ce que je veux dire, ce que je crois dire, ce que je dis ce que vous avez envie d'entendre, ce que vous croyez entendre, ce que vous entendez, ce que vous avez envie de comprendre, ce que vous comprenez ... Il y a dix possibilités que nous ayons des difficultés à communiquer. Mais essayons quand meme ....... E. Wells

  5. #5
    Débutant   Avatar de t.n.b.g
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    237
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 237
    Points : 99
    Points
    99
    Par défaut
    oui krachik je sais ca mais le probleme c'est que j'ai pas de class main
    donc pour choisir la class main je trouve pas de choix a faire....!

    en fait c'est un jar executable ce que je veux faire et la je me trouve avec seulement un fichier jar compressé qui ne s'execute pas!!

  6. #6
    Expert éminent
    Avatar de djo.mos
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    4 666
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2004
    Messages : 4 666
    Points : 7 679
    Points
    7 679
    Par défaut
    Bonsoir,
    Suffit de laisser le champ de la class main vide

  7. #7
    Débutant   Avatar de t.n.b.g
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    237
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 237
    Points : 99
    Points
    99
    Par défaut
    j'ai essayer comme ca mais en double cliqueant sur le fichier JAR apres creation il me sort un message d'erreur:

    "Failed to load Main-Class manifest attribute from C:\..........\parser.jar" !!!

  8. #8
    Expert éminent
    Avatar de djo.mos
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    4 666
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2004
    Messages : 4 666
    Points : 7 679
    Points
    7 679
    Par défaut
    Attends, tu veux un jar exécutable ou pas ?
    Si tu veux un jar exécutable tu dois créer un main et le préciser lors de l'export
    si pas, alors ne doubles cliques pas sur jar

  9. #9
    oca
    oca est déconnecté
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    354
    Détails du profil
    Informations personnelles :
    Âge : 51
    Localisation : Suisse

    Informations forums :
    Inscription : Octobre 2004
    Messages : 354
    Points : 421
    Points
    421
    Par défaut
    Si tu veux un main (donc un jar executable) pourquoi ne pas supprimer les commentaire à la fin de ton deuxième fichier ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    //public static void main(String args[]) {
        //JFrame frame = new JFrame("ANIS PARSER XML");
        //PARSER parser = new PARSER();
        //JTree tree = new JTree(parser.parse("bdd.xml"));
        //frame.getContentPane().add(new JScrollPane(tree));
        //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //frame.setSize(300, 400);
        //frame.setVisible(true);
      //}

  10. #10
    Expert confirmé
    Avatar de krachik
    Inscrit en
    Décembre 2004
    Messages
    1 964
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 1 964
    Points : 4 015
    Points
    4 015
    Par défaut
    Mais attend un peu tu veux crée un jar executable pour un applet c'est ça?
    Je suis ce que je suis grâce à ce que nous sommes tous Humanité aux Humains!! !

    Entre ce que je pense, ce que je veux dire, ce que je crois dire, ce que je dis ce que vous avez envie d'entendre, ce que vous croyez entendre, ce que vous entendez, ce que vous avez envie de comprendre, ce que vous comprenez ... Il y a dix possibilités que nous ayons des difficultés à communiquer. Mais essayons quand meme ....... E. Wells

  11. #11
    Débutant   Avatar de t.n.b.g
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    237
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 237
    Points : 99
    Points
    99
    Par défaut
    oui c'est ca Krachik

  12. #12
    Membre actif Avatar de hydraland
    Profil pro
    Développeur Java
    Inscrit en
    Mai 2006
    Messages
    179
    Détails du profil
    Informations personnelles :
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Mai 2006
    Messages : 179
    Points : 239
    Points
    239
    Par défaut
    Salut,

    A ma connaissance ce n'est pas possible sans méthode main.
    Mais tu peux lancer ton applet comme une application "normale"
    A+
    Hydraland

  13. #13
    Débutant   Avatar de t.n.b.g
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    237
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 237
    Points : 99
    Points
    99
    Par défaut
    merci beaucoup hydraland
    ça marche 5/5

    encore

Discussions similaires

  1. Créer un Runnable JAR sans avec le fichier XML
    Par Robert222 dans le forum Format d'échange (XML, JSON...)
    Réponses: 7
    Dernier message: 04/05/2011, 15h18
  2. créer .exe à partir d'un .jar sans avoir besion de la JVM
    Par boumacmilan dans le forum Général Java
    Réponses: 1
    Dernier message: 02/09/2009, 17h47
  3. Créer un fichier .jar exécutable avec Eclipse
    Par Bloodscalp dans le forum Eclipse Java
    Réponses: 21
    Dernier message: 22/05/2009, 23h22
  4. Executer fichier .jar sans avoir jvm installé
    Par fafoula dans le forum Général Java
    Réponses: 2
    Dernier message: 17/09/2008, 13h23
  5. créer un fichier Jar sous eclipse
    Par gagalive dans le forum Eclipse Java
    Réponses: 7
    Dernier message: 18/07/2006, 11h46

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