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

avec Java Discussion :

Utilisation d'une libraire en mode cmd !


Sujet :

avec Java

  1. #21
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Novembre 2008
    Messages
    143
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2008
    Messages : 143
    Points : 60
    Points
    60
    Par défaut
    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
    //---------------------------------Compile	
     
    public static boolean compile(File filename, String classsource)
    			throws IOException {
     
    		// Create file
    		FileWriter fstream = null;
    		try {
    			fstream = new FileWriter(filename);
    			BufferedWriter out = new BufferedWriter(fstream);
    			out.write(classsource);
    			out.flush();
    		} finally {
    			if (fstream != null) {
    				try {
    					fstream.close();
    				} catch (IOException e) {
    					// silent
    				}
    			}
    		}
     
    		Process processCompile = Runtime.getRuntime().exec(   new String[] { JAVA_BIN_PATH + "javac.exe", "-classpath", "./weka.jar", FOLDER + "Out1.java" }  );
    		return printResult("Compile", processCompile)==0;
     
    	}
    //------------------run
    public static void run(File file) throws IOException {
    		System.out.println("Run java program: " + file);
     
    		Process processRun = Runtime.getRuntime().exec(new String[] { JAVA_BIN_PATH + "javaw.exe", "Out1"  },null, file.getParentFile());
     
    		printResult("Run", processRun);
    	}
     
    	private static String getClassName(File file) {
    		String name = file.getName();
    		return name.substring(0,name.indexOf('.'));
    	}
    voila ce que j'ai fait ,
    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
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
      [javadoc] Loading source files for package FitnessEvaluation.LSystem...
      [javadoc] Loading source files for package FitnessEvaluation.MaxProblem...
      [javadoc] Loading source files for package FitnessEvaluation.ParityProblem...
      [javadoc] Loading source files for package FitnessEvaluation.PatternMatch...
      [javadoc] Loading source files for package FitnessEvaluation.RoyalTree...
      [javadoc] Loading source files for package FitnessEvaluation.SantaFeAntTrail...
      [javadoc] Loading source files for package FitnessEvaluation.Sudoku...
      [javadoc] Loading source files for package FitnessEvaluation.SymbolicRegression...
      [javadoc] Loading source files for package FitnessEvaluation.externalInterpreters.ParityProblem
    ...
      [javadoc] Loading source files for package FitnessEvaluation.externalInterpreters.SantaFeAntTra
    il...
      [javadoc] Loading source files for package FitnessEvaluation.externalInterpreters.SymbolicRegre
    ssion...
      [javadoc] Loading source files for package FitnessEvaluation.util...
      [javadoc] Loading source files for package Fractal...
      [javadoc] Loading source files for package Individuals...
      [javadoc] Loading source files for package Individuals.FitnessPackage...
      [javadoc] Loading source files for package Individuals.Populations...
      [javadoc] Loading source files for package Main...
      [javadoc] Loading source files for package Main.Tutorials...
      [javadoc] Loading source files for package Mapper...
      [javadoc] Loading source files for package Operator...
      [javadoc] Loading source files for package Operator.Operations...
      [javadoc] Loading source files for package Operator.Operations.ContextSensitiveOperations...
      [javadoc] Loading source files for package Parameter...
      [javadoc] Loading source files for package UI...
      [javadoc] Loading source files for package Util...
      [javadoc] Loading source files for package Util.Random...
      [javadoc] Loading source files for package Util.Statistics...
      [javadoc] Loading source files for package Util.Structures...
      [javadoc] Loading source files for package com.rie.rieps.engine...
      [javadoc] Loading source files for package com.rie.rieps.engine.color...
      [javadoc] Loading source files for package com.rie.rieps.engine.factories...
      [javadoc] Loading source files for package com.rie.rieps.engine.fonts...
      [javadoc] Loading source files for package com.rie.rieps.engine.image...
      [javadoc] Loading source files for package com.rie.rieps.exception...
      [javadoc] Loading source files for package com.rie.rieps.simpletest...
      [javadoc] Constructing Javadoc information...
      [javadoc] Standard Doclet version 1.7.0_45
      [javadoc] Building tree for all the packages and classes...
      [javadoc] C:\Users\Phd\Desktop\MyTrial\GEVA\src\Fractal\GuiComp.java:160: warning - @return tag
     has no arguments.
      [javadoc] C:\Users\Phd\Desktop\MyTrial\GEVA\src\Util\GEVAHelper.java:74: warning - @return tag
    has no arguments.
      [javadoc] Building index for all the packages and classes...
      [javadoc] Building index for all classes...
      [javadoc] Generating C:\Users\Phd\Desktop\MyTrial\GEVA\docs\api\help-doc.html...
      [javadoc] 2 warnings
     
    dist:
        [mkdir] Created dir: C:\Users\Phd\Desktop\MyTrial\GEVA\dist\docs
         [copy] Copying 555 files to C:\Users\Phd\Desktop\MyTrial\GEVA\dist\docs
         [copy] Copying 1 file to C:\Users\Phd\Desktop\MyTrial\GEVA\dist
         [copy] Copying 1 file to C:\Users\Phd\Desktop\MyTrial\GEVA\dist
         [copy] Copying 1 file to C:\Users\Phd\Desktop\MyTrial\GEVA\dist
        [mkdir] Created dir: C:\Users\Phd\Desktop\MyTrial\GEVA\dist\src
         [copy] Copying 194 files to C:\Users\Phd\Desktop\MyTrial\GEVA\dist\src
     
    clean.module.gui_rc1_exp:
     
    clean:
     
    get-jdk:
     
    pre-compile:
     
    compile.module.gui_rc1_exp.production:
        [mkdir] Created dir: C:\Users\Phd\Desktop\MyTrial\GUI\out\production\GUI_rc1_exp
        [javac] C:\Users\Phd\Desktop\MyTrial\GUI\build.xml:146: warning: 'includeantruntime' was not
    set, defaulting to build.sysclasspath=last; set to false for repeatable builds
        [javac] Compiling 87 source files to C:\Users\Phd\Desktop\MyTrial\GUI\out\production\GUI_rc1_
    exp
        [javac] Note: Some input files use unchecked or unsafe operations.
        [javac] Note: Recompile with -Xlint:unchecked for details.
         [copy] Copying 4 files to C:\Users\Phd\Desktop\MyTrial\GUI\out\production\GUI_rc1_exp
     
    compile.module.gui_rc1_exp.tests:
     
    compile.module.gui_rc1_exp:
     
    jar:
        [mkdir] Created dir: C:\Users\Phd\Desktop\MyTrial\GUI\dist
        [mkdir] Created dir: C:\Users\Phd\Desktop\MyTrial\GUI\dist\Grammars
         [copy] Copying 18 files to C:\Users\Phd\Desktop\MyTrial\GUI\dist\Grammars
        [mkdir] Created dir: C:\Users\Phd\Desktop\MyTrial\GUI\dist\Parameters
         [copy] Copying 15 files to C:\Users\Phd\Desktop\MyTrial\GUI\dist\Parameters
        [mkdir] Created dir: C:\Users\Phd\Desktop\MyTrial\GUI\dist\lib
         [copy] Copying 4 files to C:\Users\Phd\Desktop\MyTrial\GUI\dist\lib
          [jar] Building jar: C:\Users\Phd\Desktop\MyTrial\GUI\dist\GUI.jar
     
    javadoc:
      [javadoc] Generating Javadoc
      [javadoc] Javadoc execution
      [javadoc] Loading source files for package Fractal...
      [javadoc] Loading source files for package UI...
      [javadoc] Loading source files for package UI.Run...
      [javadoc] Loading source files for package UI.Run.JSci...
      [javadoc] Loading source files for package Util...
      [javadoc] Loading source files for package com.rie.rieps.engine...
      [javadoc] Loading source files for package com.rie.rieps.engine.color...
      [javadoc] Loading source files for package com.rie.rieps.engine.factories...
      [javadoc] Loading source files for package com.rie.rieps.engine.fonts...
      [javadoc] Loading source files for package com.rie.rieps.engine.image...
      [javadoc] Loading source files for package com.rie.rieps.exception...
      [javadoc] Loading source files for package com.rie.rieps.simpletest...
      [javadoc] Constructing Javadoc information...
      [javadoc] Standard Doclet version 1.7.0_45
      [javadoc] Building tree for all the packages and classes...
      [javadoc] C:\Users\Phd\Desktop\MyTrial\GUI\src\UI\GEVAChoiceProperty.java:288: warning - @retur
    n tag has no arguments.
      [javadoc] C:\Users\Phd\Desktop\MyTrial\GUI\src\UI\Run\GEVAGraphPaneItem.java:110: warning - @re
    turn tag has no arguments.
      [javadoc] C:\Users\Phd\Desktop\MyTrial\GUI\src\Util\GEVAHelper.java:74: warning - @return tag h
    as no arguments.
      [javadoc] Building index for all the packages and classes...
      [javadoc] Building index for all classes...
      [javadoc] Generating C:\Users\Phd\Desktop\MyTrial\GUI\docs\api\help-doc.html...
      [javadoc] 3 warnings
     
    dist:
        [mkdir] Created dir: C:\Users\Phd\Desktop\MyTrial\GUI\dist\docs
         [copy] Copying 290 files to C:\Users\Phd\Desktop\MyTrial\GUI\dist\docs
         [copy] Copying 1 file to C:\Users\Phd\Desktop\MyTrial\GUI\dist
         [copy] Copying 1 file to C:\Users\Phd\Desktop\MyTrial\GUI\dist
         [copy] Copying 1 file to C:\Users\Phd\Desktop\MyTrial\GUI\dist
        [mkdir] Created dir: C:\Users\Phd\Desktop\MyTrial\GUI\dist\src
         [copy] Copying 98 files to C:\Users\Phd\Desktop\MyTrial\GUI\dist\src
     
    build:
         [copy] Copying 2 files to C:\Users\Phd\Desktop\MyTrial\bin
          [jar] Building jar: C:\Users\Phd\Desktop\MyTrial\GEVA_GUI.jar
     
    all:
     
    BUILD SUCCESSFUL
    Total time: 1 minute 28 seconds
     
    C:\Users\Phd\Desktop\MyTrial>cd bin
     
    C:\Users\Phd\Desktop\MyTrial\bin>java -classpath GEVA.jar   Main.Tutorials.Tutorial6
    Loading properties from file system: C:/Users/Phd/Desktop/MyTrial/param/Parameters/HelloWorld.pro
    perties
    mutation_probability=0.02
    tail_percentage=0.5
    initialiser=Operator.RampedHalfAndHalfInitialiser
    generations=2
    replacement_type=generational
    generation_gap=0.5
    individual_catch_interval=-1
    main_class=Main.Run
    crossover_operation=Operator.Operations.SinglePointCrossover
    evaluate_elites=false
    derivation_tree=Mapper.DerivationTree
    userpick_size=2
    grammar_file=C:/Users/Phd/Desktop/javaFun.bnf
    grow_probability=0.5
    population_size=4
    output=
    fitness_function=FitnessEvaluation.PatternMatch.MyFitness
    max_wraps=1
    selection_operation=Operator.Operations.TournamentSelect
    crossover_probability=0.7
    mutation_operation=Operator.Operations.IntFlipMutation
    max_depth=2
    elite_size=3
    word=rome
    tournament_size=3
    fixed_point_crossover=false
    stopWhenSolved=true
    ----------------------  []
    ----------------------  []
    ----------------------  []
    ----------------------  []
    Output directory is C:\Users\Phd\Desktop\MyTrial\bin\
    ----***------double y= eval.pctCorrect() ; -----***------
     
    ----***------Start Compiling File----***------
     
     
     
    Run java program: C:\Users\Phd\Desktop\MyTrial\bin\Out1.class
    Exception in thread "main" java.lang.NoClassDefFoundError: weka/classifiers/C
    lassifier
            at java.lang.Class.getDeclaredMethods0(Nat----***------Finish Compiling -----***------
    i
    ve Method)
            at java.lang.Class.privateGetDeclaredMethods(----***------double y= eval.pctCorrect() ; -
    ----***------
    Class.ja
    va:----***------Start Compiling File----***------
    25
    31)
            at java.lang.Class.getMethod0(Class.java:2774)
            at java.lang.Class.getMethod(Class.java:1663)
            at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
            at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
    Caused by: java.lang.ClassNotFoundException: weka.classifiers.Classifier
            at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
            ... 6 more
     
     
     
    Run java program: C:\Users\Phd\Desktop\MyTrial\bin\Out1.class
    Exception in threa
    d----***------Finish Compiling -----***------
     
    "----***------double y= eval.pctCorrect() ; -----***------
    m
    a----***------Start Compiling File----***------
    i
    n" java.lang.NoClassDefFoundError: weka/classifiers/Classifier
            at java.lang.Class.getDeclaredMethods0(Native Method)
            at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
            at java.lang.Class.getMethod0(Class.java:2774)
            at java.lang.Class.getMethod(Class.java:1663)
            at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
            at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
    Caused by: java.lang.ClassNotFoundException: weka.classifiers.Classifier
            at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
            ... 6 more
     
     
     
    Run java program: C:\Users\Phd\Desktop\MyTrial\bin\Out1.class
    Exception in thread "main" java.lang.NoClassDefFoundError: weka/classifiers/Cla
    ssifier
            at java.----***------Finish Compiling -----***------
    la
    ng.Class.----***------double y= eval.pctCorrect() ; -----***------
    g
    etDe----***------Start Compiling File----***------
    c
    laredMethods0(Native Method)
            at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
            at java.lang.Class.getMethod0(Class.java:2774)
            at java.lang.Class.getMethod(Class.java:1663)
            at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
            at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
    Caused by: java.lang.ClassNotFoundException: weka.classifiers.Classifier
            at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
            ... 6 more
     
     
     
    Run java program: C:\Users\Phd\Desktop\MyTrial\bin\Out1.class
    Exception in thread "main" java.lang.NoClassDefFoundError: weka/classif
    iers/Classifier
            at java.lang.----***------Finish Compiling -----***------
    Clas
    s.getDeclaredMe#---Data---thods
    0(NaGen FitEvals        Time(ms)        Invalids        BestFit AveFit  VarFit  AveUsedGenes    A
    veLength        AveDTDepthtive
    Method)
            at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
            at java.lang.Class.getMethod0(Class.java:2774)
            at java.lang.Class.getMethod(Class.java:1663)
            at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
            at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
    Caused by: java.lang.ClassNotFoundException: weka.classifiers.Classifier
            at java.net.URLClassLoader$1.run(URLClassLoader.   0java:366)
            at java.net.URLClassLoader$1.run(URLClassL      oader.java:35    05)
            at java .security.Acc 17961essContr     oller.doPri   0vileg    ed(Native Method)
            at java.net.URLCl 6,000assL     oad 6,000e      r.   0,000fi    nd 0,000Class(  U 0,000RL
            Class 2,000L
    oader.java:354)
            ----------------------  [double y= eval.pctCorrect() ; ]a
    t j----------------------  [double y= eval.pctCorrect() ; ]a
    va----------------------  [double y= eval.pctCorrect() ; ].
    lan----------------------  [double y= eval.pctCorrect() ; ]g.Cl
    assLoException: java.lang.ArithmeticException: / by zero
    ader.loadClajava.lang.ArithmeticException: / by zero
            at Operator.Operations.SinglePointCrossover.getMaxXOPoint(SinglePointCrossover.java:204)
            at Operator.Operations.SinglePointCrossover.doOperation(SinglePointCrossover.java:141)
            at Operator.CrossoverModule.perform(CrossoverModule.java:81)
            at Algorithm.SimplePipeline.step(SimplePipeline.java:63)
            at Algorithm.MyFirstSearchEngine.step(MyFirstSearchEngine.java:50)
            at Main.AbstractRun.run(AbstractRun.java:372)
            at Main.Tutorials.Tutorial6.experiment(Tutorial6.java:48)
            at Main.Tutorials.Tutorial6.main(Tutorial6.java:122)
    ss(Cl
    C:\Users\Phd\Desktop\MyTrial\bin>cd bin
    et je comprends pas l'erreur !

  2. #22
    Membre expert

    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2004
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 2 301
    Points : 3 675
    Points
    3 675
    Par défaut
    haa ba on avance gentiment...

    est-ce qu'un fichier .class a été généré suite à la compilation de ton source?

    si oui -> vérifier de où tu lances les commandes, et adapter en conséquence
    si non -> surveiller l'output de compilation, il y a peut-être des erreurs qui empêchent la génération du .class.

  3. #23
    Membre expert

    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2004
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 2 301
    Points : 3 675
    Points
    3 675
    Par défaut
    Citation Envoyé par benooo Voir le message
    public static void run(File file) throws IOException {
    System.out.println("Run java program: " + file);

    Process processRun = Runtime.getRuntime().exec(new String[] { JAVA_BIN_PATH + "javaw.exe", "Out1" },null, file.getParentFile());
    rooo mais pourquoi tu a viré les arguments de la commande d'exécution?

    tu dois setter le classpath A LA FOIS pour compiler ET pour exécuter, sinon, comment veux-tu que java s'y retrouve?

  4. #24
    Membre expert

    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2004
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 2 301
    Points : 3 675
    Points
    3 675
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Caused by: java.lang.ClassNotFoundException: weka.classifiers.Classifier
            at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
            ... 6 more
    ça ça devrait te faire tilt non?

  5. #25
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Novembre 2008
    Messages
    143
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2008
    Messages : 143
    Points : 60
    Points
    60
    Par défaut
    parceque ca me donner l'erreur : impossible de trouver ou charger la class Out1 et quand je les enlever j'ai eu une erreur :
    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
    Run java program: C:\Users\Phd\Desktop\MyTrial\bin\Out1.class
    Exception in thread "main" java.lang.NoClassDefFoundError: weka/classifi
    ers/Classifier
            at java.lang.Class.getDeclaredMethod----***------Finish Compiling -----***------
    s
    0(N----***------double y= eval.pctCorrect() ; -----***------
    a
    t----***------Start Compiling File----***------
    i
    ve Method)
            at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
            at java.lang.Class.getMethod0(Class.java:2774)
            at java.lang.Class.getMethod(Class.java:1663)
            at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
            at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
    Caused by: java.lang.ClassNotFoundException: weka.classifiers.Classifier
            at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
            ... 6 more
    et apres le Compile j'obtiens Out1.class dans le dossier bin la ou je suis !

  6. #26
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Novembre 2008
    Messages
    143
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2008
    Messages : 143
    Points : 60
    Points
    60
    Par défaut
    Mais pour quoi il n a pas pu charger la class Classifer , j'ai verifier dans weka.jar et il ya Classifier.class ?!

  7. #27
    Membre expert

    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2004
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 2 301
    Points : 3 675
    Points
    3 675
    Par défaut
    Il devrait, si le classpath était setté correctement...

    A toi de trouver, ou de préparer un projet de test que je puisse débugger à la maison ce soir (mais si tu le fais, il doit être MINIMALISTE mais COMPLET: le minimum de code qui simule le problème rencontré, pour que quelqu'un qui n'a pas accès aux mêmes outils&librairies que toi puisse exécuter le code)

  8. #28
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Novembre 2008
    Messages
    143
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2008
    Messages : 143
    Points : 60
    Points
    60
    Par défaut
    ok,
    mais pourquoi quand je mets -classpath weka.jar dans compile et run
    il me dit impossible de charger ou trouver Out1
    et si je la mets que dans compiler il me donne l 'erreur de classifiers.Classifier ?

  9. #29
    Membre expert

    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2004
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 2 301
    Points : 3 675
    Points
    3 675
    Par défaut
    Je ne sais pas... je t'ai dit tout ce que je pouvais avec les éléments en ma possession... sans pouvoir exécuter et voir tourner l'appli moi-même, je ne sais pas trop quoi te dire...

  10. #30
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Novembre 2008
    Messages
    143
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2008
    Messages : 143
    Points : 60
    Points
    60
    Par défaut
    le premier code c'est MyFitness.java
    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
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    package FitnessEvaluation.PatternMatch;
    import Exceptions.BadParameterException;
    import Individuals.Individual;
    import Individuals.Phenotype;
    import java.util.Properties;
    import FitnessEvaluation.FitnessFunction;
    import Util.Constants;
    //import jxl.*;
    //import jxl.Workbook;
    //import jxl.read.biff.*;
    //import jxl.write.WriteException;
    import java.util.Locale;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.ObjectInputStream;
    import java.io.PrintWriter;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Random; 
    import java.awt.BorderLayout;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    /*import weka.core.converters.ArffLoader;
    import weka.core.*;
    import weka.classifiers.*;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Random;
    import weka.classifiers.evaluation.ThresholdCurve;
    import weka.classifiers.rules.JRip;
    import weka.classifiers.rules.OneR;
    import weka.classifiers.rules.Ridor;
    import weka.classifiers.rules.Rule;
    import weka.classifiers.trees.J48;
    import weka.gui.visualize.PlotData2D;
    import weka.gui.visualize.ThresholdVisualizePanel;*/
     
    //*************************************************************************************************************************************************************
    //*************************************************************************************************************************************************************
    //*************************************************************************************************************************************************************
     
    public class MyFitness implements FitnessFunction {
     
        private static String s;
     
        /** Creates a new instance of MyFitness  */
        public MyFitness () {
    	s = "geva";
        }
     
        /**
         * Creates a new instance of MyFitness 
         * @param s String to match
         */
        public MyFitness (String s) {
            MyFitness .s = s;
        }
        public void setProperties(Properties p) {
            String key = Constants.WORDMATCH_WORD;
            String value;
    	value = p.getProperty(key,"geva");
    	MyFitness .s = value;
        }
    //*************************************************************************************************************************************************************
    //*************************************************************************************************************************************************************
    //*************************************************************************************************************************************************************
    	private static final String FOLDER = "C:\\Users\\Phd\\Desktop\\MyTrial\\bin\\";
    	private static final String JAVA_BIN_PATH = "C:\\Program Files\\Java\\jdk1.7.0_21\\bin\\";
     
     
     
     
     
    //----------------------------Compile and Run the file
        public static void compileAndRun(String className, String source) {
     
    		File sourceFile = new File(FOLDER+className+".java");
    		File classFile = new File(FOLDER+className+".class");
     
    		try {
    		    if ( compile(sourceFile,source) ) {
    				run(classFile);
    		    }			
    		} catch (Exception e) {System.err.println("Error: " + e.getMessage());}
     
    	}
    //---------------------------------Compile	
     
    public static boolean compile(File filename, String classsource)
    			throws IOException {
     
    		// Create file
    		FileWriter fstream = null;
    		try {
    			fstream = new FileWriter(filename);
    			BufferedWriter out = new BufferedWriter(fstream);
    			out.write(classsource);
    			out.flush();
    		} finally {
    			if (fstream != null) {
    				try {
    					fstream.close();
    				} catch (IOException e) {
    					// silent
    				}
    			}
    		}
     
    		Process processCompile = Runtime.getRuntime().exec(   new String[] { JAVA_BIN_PATH + "javac.exe", "-classpath", "./weka.jar", FOLDER + "Out1.java" }  );
    		return printResult("Compile", processCompile)==0;
     
    	}
    //------------------run
    public static void run(File file) throws IOException {
    		System.out.println("Run java program: " + file);
     
    		Process processRun = Runtime.getRuntime().exec(new String[] { JAVA_BIN_PATH + "javaw.exe", "Out1"  },null, file.getParentFile());
     
    		printResult("Run", processRun);
    	}
     
    	private static String getClassName(File file) {
    		String name = file.getName();
    		return name.substring(0,name.indexOf('.'));
    	}
     
    //-------------------------Print Result	
    	private static int printResult(String prog, final Process process) {
    		new Thread() {
    			public void run() {
    				try {
    					InputStream stream = process.getErrorStream();
    					try {
    						int read;
    						while ((read = stream.read()) != -1) {
    							System.err.print((char) read);
    						}
    						System.err.println();
    					} finally {
    						try {
    							stream.close();
    						} catch (IOException e) {
    							// silent
    						}
    					}
    				} catch (IOException e) {
    					e.printStackTrace();
    				}
    			};
    		}.start();
    		new Thread() {
    			public void run() {
    				try {
    					InputStream stream = process.getInputStream();
    					try {
    						int read;
    						while ((read = stream.read()) != -1) {
    							System.out.print((char) read);
    						}
    						System.out.println();
    					} finally {
    						try {
    							stream.close();
    						} catch (IOException e) {
    							// silent
    						}
    					}
    				} catch (IOException e) {
    					e.printStackTrace();
    				}
    			};
    		}.start();
    		try {
    			process.waitFor();
    			return process.exitValue();
    		} catch (InterruptedException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    			return -1;}
     
    }	
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    //*************************************************************************************************************************************************************
    //****************************************************************------*Fitness*------***********************************************************************
    //*************************************************************************************************************************************************************
     
     
     
        /**
         * Compare a string to the word. Each symbol not matching increases the fitness by 1.
         * Max fitness is max(length of the word, phenotype).
         * @param p Compared phenotype
         * @return Number of missmatches
         */
        public double evaluateString(Phenotype p) throws IOException{
     
    //----------------------Deleting the Fitness file content value of the individual-------------------------------------------	    
    PrintWriter writer = new PrintWriter("c:\\myobj.obj");
    writer.print("");
    writer.close();
    //--------------------------------------------------------------------------------------------------------------------------
     
     
     
    //----------------------Creating the whole complete java Program-------------------------------------------	
    	    System.out.println("----***------"+p+"-----***------\n");
       	    System.out.println("----***------Start Compiling File----***------\n");
    	    String className = "Out1";
    		StringBuilder classSource=new StringBuilder();
    		//classSource.append("package out1;");
    		classSource.append("import java.io.BufferedReader;  import java.io.FileReader;  import java.io.FileOutputStream;import java.io.ObjectOutputStream; import java.io.IOException; import java.util.Random; import java.awt.BorderLayout;import java.io.BufferedReader;import java.io.BufferedWriter;import weka.core.converters.ArffLoader;import weka.core.*;import weka.classifiers.*;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.Random;import weka.classifiers.evaluation.ThresholdCurve;import weka.classifiers.rules.JRip;import weka.classifiers.rules.OneR;import weka.classifiers.rules.Ridor;import weka.classifiers.rules.Rule;import weka.classifiers.trees.J48;import weka.gui.visualize.PlotData2D;import weka.gui.visualize.ThresholdVisualizePanel;");
    		classSource.append(" public class Out1 {");
    		classSource.append("  public static void main(String[] args) throws IOException , Exception {");
    		classSource.append("BufferedReader breader= null;breader=new BufferedReader(new FileReader(\"C:/Users/Phd/Downloads/vowel.arff \"));Instances train1 = new Instances(breader);train1.setClassIndex(train1.numAttributes() - 1);");
    		classSource.append("  breader.close();");
    		classSource.append("  Ridor cls = new Ridor();cls.buildClassifier(train1); Evaluation eval =new Evaluation(train1);eval.crossValidateModel(cls, train1, 10, new Random(1));");
    		classSource.append(p);
    	    classSource.append(" System.out.println(\"[----------Printing Fitness----------]\"+ y);   ");
    		classSource.append("  File f = new File( \"c:\\\\Users\\\\pc\\\\Desktop\\\\myobj.obj\"); ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f)); out.writeDouble(y); out.flush(); out.close();");
    		classSource.append("}");
            classSource.append("}");
    //------------------------------------------------------------------------------------------------------------		
     
     
    //----------------------Compiling and Runing the individual---------------------------------------------------		
    		compileAndRun(className, classSource.toString());
    	    System.out.println("----***------Finish Compiling -----***------\n");
    //------------------------------------------------------------------------------------------------------------
     
    //----------------------reading the fitness value of the individual-------------------------------------------
     
       ObjectInputStream restore = new  ObjectInputStream(new FileInputStream("c:\\Users\\Phd\\Desktop\\myobj.obj"));
       int ftnss =  restore.readInt();
        restore.close();
     
     //------------------------------------------------------------------------------------------------------------	
     
     
     
     
     
            return ftnss;
        }
     
        public void getFitness(Individual i)  {
    	try{ i.getFitness().setDouble(this.evaluateString(i.getPhenotype()));
    		 } catch(IOException ex){ }
        }
     
        public boolean canCache()
        {   return true;
        }
     
    }
    2 eme code c'est : Tutorial6.java
    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
     
    package Main.Tutorials;
     
    import Algorithm.MyFirstSearchEngine;
    import Algorithm.Pipeline;
    import Algorithm.SimplePipeline;
    import FitnessEvaluation.FitnessFunction;
    import Main.AbstractRun;
    import Mapper.GEGrammar;
    import Operator.*;
    import Operator.Operations.*;
    import Util.Constants;
    import Util.Random.MersenneTwisterFast;
    import Util.Statistics.IndividualCatcher;
    import Util.Statistics.StatCatcher;
     
    public class Tutorial6 extends AbstractRun {
     
        private long startTime;
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/   
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/    
        public Tutorial6() {
            this.rng = new MersenneTwisterFast();
            super.propertiesFilePath = "C:/Users/Phd/Desktop/MyTrial/param/Parameters/HelloWorld.properties";
            this.startTime = System.currentTimeMillis();
        }
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/   
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/        
        public void setup() {
        }
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/   
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/        
        @Override
        public void experiment(String[] args) {
            try{
     
                //Read the command-line arguments
                if(this.commandLineArgs(args)) {
                    //Initialize timing the excecution
                    long st = System.currentTimeMillis();
     
                    //Create the Main object
                    //Setup the algorithm
                    this.setup(args);
                    //Initialize the algorithm
                    this.init();
                    //Hack for number of iterations!!?? Create a proper method
                    int its = this.run();
                    //Print collected data
                    this.printStuff();
                    //Time the excecution
                    long et = System.currentTimeMillis();
                    System.out.println("Done running: Total time(Ms) for " 
                                + its + " generations was:"+(et-st));
     
                }
            } catch(Exception e) {
                System.err.println("Exception: "+e);
                e.printStackTrace();
            }
        }    
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/   
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/        
     
        public void setup(String[] args) {
     
            this.readProperties(args);
            GEGrammar grammar = new GEGrammar(this.properties);
    		MyFirstSearchEngine alg = new MyFirstSearchEngine();
            initialiser = getInitialiser(grammar, this.rng, this.properties);
    		CrossoverOperation singlePointCrossover = new SinglePointCrossover(this.rng, this.properties);
            CrossoverModule crossoverModule = new CrossoverModule(this.rng, singlePointCrossover);
            IntFlipMutation mutation = new IntFlipMutation(this.rng, this.properties);
            MutationOperator mutationModule = new MutationOperator(this.rng, mutation);
            SelectionOperation selectionOperation = getSelectionOperation(this.properties, this.rng);
            SelectionScheme selectionScheme = new SelectionScheme(this.rng, selectionOperation);
            ReplacementOperation replacementOperation = new ReplacementOperation(this.properties);
            JoinOperator replacementStrategy = this.getJoinOperator(this.properties, this.rng, selectionScheme.getPopulation(), replacementOperation);
            FitnessFunction fitnessFunction = getFitnessFunction(this.properties);
    		FitnessEvaluationOperation fitnessEvaluationOperation = new FitnessEvaluationOperation(fitnessFunction);
            FitnessEvaluator fitnessEvaluator = new FitnessEvaluator(this.rng, fitnessEvaluationOperation);
              //Statistics
               StatCatcher stats = new StatCatcher(Integer.parseInt(this.properties.getProperty("generations")));
               IndividualCatcher indCatch = new IndividualCatcher(this.properties);
               stats.addTime(startTime);//Set initialisation time for the statCatcher (Not completly accurate here)
               StatisticsCollectionOperation statsCollection = new StatisticsCollectionOperation(stats, indCatch, this.properties);
               Collector collector = new Collector(statsCollection);
              //End
            Pipeline pipelineInit = new SimplePipeline();
            alg.setInitPipeline(pipelineInit);
            FitnessEvaluator fitnessEvaluatorInit = new FitnessEvaluator(this.rng, fitnessEvaluationOperation);
            fitnessEvaluatorInit.setPopulation(initialiser.getPopulation());
    		collector.setPopulation(initialiser.getPopulation());
            pipelineInit.addModule(initialiser);
            pipelineInit.addModule(fitnessEvaluatorInit);
            pipelineInit.addModule(collector); 
            Pipeline pipelineLoop = new SimplePipeline();
            alg.setLoopPipeline(pipelineLoop);
            selectionScheme.setPopulation(initialiser.getPopulation()); // The selectionScheme takes one population and splits it
            replacementStrategy.setPopulation(initialiser.getPopulation());// The replacement takes to populations and joins them (The population that will be joined is here specified in the constructor.
            crossoverModule.setPopulation(selectionScheme.getPopulation()); // Crossover will be performed on the selected population
            mutationModule.setPopulation(selectionScheme.getPopulation()); // Mutation will be performed on the selected population
            fitnessEvaluator.setPopulation(selectionScheme.getPopulation()); // Fitness evaluation will be performed on the selected population
    	    collector.setPopulation(initialiser.getPopulation());
            pipelineLoop.addModule(selectionScheme); //Select the population according to the in the properties file specified criteria, here tournament selection
            pipelineLoop.addModule(crossoverModule); //Perform crossover on the setPopulation, here the selected population will be subjected to single point crossover
            pipelineLoop.addModule(mutationModule); //Mutate the setPopulation. Here int-flip mutation is performed on the selected population
            pipelineLoop.addModule(fitnessEvaluator); //The population will be assigned new fitness
            pipelineLoop.addModule(replacementStrategy); //Replace the old population with the selected population.
            pipelineLoop.addModule(collector);
            // Finally we set the algorithm
            this.algorithm = alg;
     
        }
     
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/   
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/       
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/   
    /*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/    
     public static void main(String[] args) { 
            Tutorial6 mainTutorial6 = new Tutorial6();
            mainTutorial6.experiment(args);
    	System.exit(0);
        }
     
    }
    3 eme c'est un fichier HelloWorld.properties
    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
    #Fri Aug 29 12:18:13 BST 2008
    main_class=Main.Run
    mutation_probability=0.02
    initialiser=Operator.RampedHalfAndHalfInitialiser
    grow_probability = 0.5
    derivation_tree=Mapper.DerivationTree
    max_depth = 2
    tail_percentage=0
    generations=2
    replacement_type=generational
    generation_gap=0.5
    crossover_operation=Operator.Operations.SinglePointCrossover
    fixed_point_crossover=false
    evaluate_elites=false
    userpick_size=2
    grammar_file=C:/Users/Phd/Desktop/javaFun.bnf
    population_size=4
    output=
    fitness_function=FitnessEvaluation.PatternMatch.MyFitness
    max_wraps=1
    selection_operation=Operator.Operations.TournamentSelect
    crossover_probability=0.7
    mutation_operation=Operator.Operations.IntFlipMutation
    elite_size=3
    tournament_size=3
    stopWhenSolved=true
    word = rome
    tail_percentage = 0.5
    individual_catch_interval = -1
    4eme c'est un fichier : JavaFun.bnf
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <fun> ::= <header>
    <header> ::=   double y= eval.pctCorrect()  ;
    En lancant Tutorials6.java ( le HelloWorld.properties va etre lu donc MyFitness.java va etre lancer automatiquement )
    pour executer on fait : ant puis cd bin puis java -classpath GEVA.jar Main.Tutorials.Tutorial6
    mais maintenant vous aurez besoin de GEVA http://ncra.ucd.ie/Site/GEVA.html
    dedans il faut remplacer Tutorial6.java ( par le code que j'ai donner ) et ajouter (MyFitness.java au: GEVA\src\FitnessEvaluation\PatternMatch)
    remplacer aussi le fichier HelloWorld.properties dans : param\Parameters\
    et poser JavaFun.bnf sur le desktop
    c'est long comme processus mais c'est le plus minimaliste que j'ai pu faire ,
    Merci pour votre aide

  11. #31
    Membre expert

    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2004
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 2 301
    Points : 3 675
    Points
    3 675
    Par défaut
    Ok, on n'a pas tout à fait la même définition de "minimal"

    Ton problème (réel) n'a rien à voir avec ton implémentation (donc le traitement via cette librairie spécifique), on peut plutôt dire que tu dois faire une appli qui:

    - créé un fichier .java référençant une librairie externe
    - le compiler
    - l'exécuter

    Que cela soit GEVA ou autre n'a pas d'importance dans la résolution de ton souci...

    J'ai fait un exemple minimaliste qui fonctionne (pour l'exemple, j'ai utilisé un librairie très connue et assez légère, apache commons language en version 2.6, dispo ici: http://commons.apache.org/proper/com...oad_lang.cgi):

    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
    package temp;
     
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
     
    public class Temp {
    	private static final String JAVA_BIN_PATH = "C:\\Program Files\\Java\\jdk1.7.0_10\\bin\\";
     
    	public static void main(String[] args) throws Exception {
    		StringBuilder sb = new StringBuilder();
    		sb.append("import org.apache.commons.lang.StringUtils;");
    		sb.append("public class Test {");
    		sb.append("  public static void main(String[] arg) {");
    		sb.append("    System.out.println(StringUtils.trim(\"  ça fonctionne!  \"));");
    		sb.append("  }");
    		sb.append("}");
    		compileAndRun("Test", sb.toString());
    	}
     
    	public static void compileAndRun(String className, String source) {
    		try {
    			if (compile(className, source)) {
    				run(className);
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
     
    	public static boolean compile(String clazz, String source)
    			throws IOException {
     
    		FileWriter fstream = null;
    		try {
    			fstream = new FileWriter(new File(clazz + ".java"));
    			BufferedWriter out = new BufferedWriter(fstream);
    			out.write(source);
    			out.flush();
    		} finally {
    			if (fstream != null) {
    				try {
    					fstream.close();
    				} catch (IOException e) {
    					// silent
    				}
    			}
    		}
     
    		Process processCompile = Runtime.getRuntime().exec(
    				new String[] { JAVA_BIN_PATH + "javac.exe", "-classpath",
    						"./commons-lang-2.6.jar", clazz + ".java" }, null,
    						new File(System.getProperty("user.dir")));
    		return printResult("Compile", processCompile) == 0;
     
    	}
     
    	public static void run(String clazz) throws IOException {
    		System.out.println("Run java program: " + clazz);
     
    		Process processRun = Runtime.getRuntime().exec(
    				new String[] { JAVA_BIN_PATH + "javaw.exe", "-classpath",
    						".;./commons-lang-2.6.jar", clazz }, null,
    				new File(System.getProperty("user.dir")));
     
    		printResult("Run", processRun);
    	}
     
    	private static int printResult(String prog, final Process process) {
    		new Thread() {
    			public void run() {
    				try {
    					InputStream stream = process.getErrorStream();
    					try {
    						int read;
    						while ((read = stream.read()) != -1) {
    							System.err.print((char) read);
    						}
    						System.err.println();
    					} finally {
    						try {
    							stream.close();
    						} catch (IOException e) {
    							// silent
    						}
    					}
    				} catch (IOException e) {
    					e.printStackTrace();
    				}
    			};
    		}.start();
    		new Thread() {
    			public void run() {
    				try {
    					InputStream stream = process.getInputStream();
    					try {
    						int read;
    						while ((read = stream.read()) != -1) {
    							System.out.print((char) read);
    						}
    						System.out.println();
    					} finally {
    						try {
    							stream.close();
    						} catch (IOException e) {
    							// silent
    						}
    					}
    				} catch (IOException e) {
    					e.printStackTrace();
    				}
    			};
    		}.start();
    		try {
    			process.waitFor();
    			return process.exitValue();
    		} catch (InterruptedException e) {
    			e.printStackTrace();
    			return -1;
    		}
    	}
    }
    Pour info, lors de l'exécution, il faut ajouter le répertoire courant dans le classpath (le ".;" dans le code d'exécution), mais ce n'est pas nécessaire lors de la compilation (oui c'est bizarre, mais c'est quelque chose à savoir...)

    bon courage!


  12. #32
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Novembre 2008
    Messages
    143
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2008
    Messages : 143
    Points : 60
    Points
    60
    Par défaut
    mais c'est le vilain ".;" qui causait le probleme , c'est bon maintenant ça marche tres bien

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. Réponses: 57
    Dernier message: 02/06/2020, 20h54
  2. utiliser une libraire
    Par chris069 dans le forum Visual C++
    Réponses: 1
    Dernier message: 24/04/2009, 14h02
  3. [integration] utilisation optionnelle d'une libraire externe
    Par Grand sorcier dans le forum Général Java
    Réponses: 6
    Dernier message: 09/06/2006, 17h06
  4. utilisation d'une base Firebird en mode server
    Par richard038 dans le forum Bases de données
    Réponses: 11
    Dernier message: 31/10/2005, 18h47

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