Comment compiler un code java

salut
comment je peut compiler un code java a partir d'un fichier .bat
et merci d'avance

3 réponses

  1. Modérateur
    Tu dois mettre la commande javac et ses options dans ton fichier .bat
    0
    1. merci de ton reponse
      voila le fichier .bat

      set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_24"
      set JAVA_EXE="C:\Program Files\Java\jdk1.6.0_24\bin\java"
      set SWEC_DIR=..\lib

      set CLASSPATH=
      set CPATH=.;%SWEC_DIR%\swec.jar;%JAVA_HOME%\lib\rt.jar;%SWEC_DIR%\iaik_jce_full.jar;%SWEC_DIR%\iaik_ssl.jar;%SWEC_DIR%\acmecrypt.jar

      %JAVAC_EXE% -cp %CPATH% .\swecexample.\SwecExample1

      mais la compilation n'a pas réussi
      et voila mon code java

      /**
      * Title: Swec Example 1<p>
      * Description: Example program to demostrate the SafeWord EASSP Client library.<p>
      * Company: Secure Computing Corp.<p>
      * @version 1.0
      */
      package swecexample;

      import java.io.*;
      import securecomputing.swec.SafeWordClient;
      import securecomputing.swec.SafeWordClientPool;
      import securecomputing.swec.Authentication;
      import securecomputing.swec.AuthenticationException;
      import securecomputing.swec.SwecConfig;
      import securecomputing.swec.SwecUIHandler;
      import securecomputing.ssl.SimpleSSLClient;
      import securecomputing.util.SccDebug;
      //import securecomputing.swec.EasspMessage;

      /**
      * This example program demonstrates a single session authentication.
      * It shows how an application can fullfill authentication requirements
      * through a simple callback mechanism.
      */
      public class SwecExample1
      {
      static boolean mPrintTrace = true; // print trace messages to console

      static boolean mUseSwingUI = true; // if false, use console

      static boolean mTransaction = true; // if true, do transaction oriented

      static boolean smStartSession = false; // require PremierAccess AAA to create a session

      static String CONFIG_FILEPATH;
      static { CONFIG_FILEPATH = System.getProperty("user.dir") +
      System.getProperty("file.separator") + "SwecExample.conf"; }
      static final int MAX_CERT_SIZE = 4096;

      static SafeWordClientPool mPool = null;

      public static void main(String argv[])
      {
      // examples of setting debug levels from app
      /* SccDebug.setGlobalEnable(SccDebug.DEFAULT);
      SccDebug.setDebugLevel( SccDebug.DEBUG );
      SccDebug.setPrinting(true, true);
      SccDebug.setDebug( EasspMessage.class.getName(), SccDebug.DEBUG );
      SccDebug.setDebug( SimpleSSLClient.class.getName(), SccDebug.DEBUG );
      /**/
      String userIpAddr = null;
      String cert = null;
      byte certBytes[] = new byte[MAX_CERT_SIZE];

      System.out.println("SLSLSLSLSL");

      pl("Parsing command line arguments");
      for (int iArg = 0; iArg < argv.length; iArg++)
      {
      if (argv[iArg].startsWith ("-i"))
      {
      // user ip addr
      userIpAddr = argv[iArg].substring(2);
      }
      else if (argv[iArg].startsWith ("-f"))
      {
      // read certificate from file
      pl("Reading certificate file: "+ argv[iArg].substring(2));
      try{
      FileInputStream fis = new FileInputStream(argv[iArg].substring(2) );
      int nr = fis.read(certBytes, 0, MAX_CERT_SIZE);
      fis.close();

      if(nr > 0)
      cert = new String(certBytes,0,nr);
      else
      {
      System.out.println("Could not read certificate from file: " + argv[iArg].substring(2));
      System.exit(0);
      }
      }
      catch(FileNotFoundException e) {
      System.out.println(e);
      System.exit(0);
      }
      catch(IOException e) {
      System.out.println(e);
      System.exit(0);
      }
      }
      } // for

      SccDebug.setAppName("SwecExample1");
      try
      {
      // create a configuration object
      pl ("Creating configuration object");
      SwecConfig config = new SwecConfig();
      config.loadFromFile(CONFIG_FILEPATH);
      String easspVer = config.getProperty(SwecConfig.EASSP_VERSION);
      if (easspVer.equals("201") || easspVer.equals("200"))
      {
      // required if using SSL
      pl("Seeding random number generator");
      SimpleSSLClient.seedRandomGenerator();
      }
      AuthenResult result;
      if (cert == null)
      result = authenticate(config, null, "name", userIpAddr);
      else
      result = authenticate(config, cert, "certificate", userIpAddr);
      System.out.println(result.toString());
      }
      catch (Exception ex)
      {
      System.out.println("Exception: "+ex);
      System.out.println("Exiting program");
      }
      System.exit(0);
      }

      static AuthenResult authenticate(SwecConfig config, String idData, String idType, String userIpAddr)
      {
      AuthenResult result = new AuthenResult();
      SafeWordClient swClient;

      SwecUIHandler ui = createUIHandler();

      try
      {
      pl("Getting SafeWordClient from pool");
      swClient = getClient(config);
      pl(swClient.getResultText());
      }
      catch (Exception ex)
      {
      result.statusMsg = "Failed to create new SafeWordClient\n"+ex;
      return result;
      }
      /* This is the place to add optional authentication context data
      * such as the user IP address and agent comment.
      */
      swClient.setAgentComment("my comment");
      if (userIpAddr != null)
      swClient.setClientAddress(userIpAddr);

      pl("Creating an Authentication object");
      /* If agentName needs to be changed on a per authentication basis,
      * it can be done here by overriding the value placed in the message
      * from the configuration. It would look like this:
      */
      // Authentication authen =
      // new Authentication(ui,swClient,config.getProperty(SwecConfig.SYSTEM_NAME), "myAgentName");
      Authentication authen = new Authentication(ui,swClient,config.getProperty(SwecConfig.SYSTEM_NAME));
      if (smStartSession)
      authen.setRequireSession(true);

      // example of setting an agent comment
      authen.setAgentComment("an agent comment");

      boolean passed = false;
      try
      {
      pl("Calling authenticate method");
      if(idType.equals("certificate"))
      passed = authen.authenticate(idData);
      else
      passed = authen.authenticate(idData, null);
      pl("Collecting authentication result data");
      result.id = authen.getUserId();
      result.result = passed ? "passed" : "failed";
      result.resultCode = authen.getFailCode();
      result.actionData = authen.getAuthenicatedAction();
      result.statusMsg = authen.getStatusText();
      result.sessionID = authen.getSessionID();
      }
      catch (AuthenticationException ae)
      {
      System.out.println("Caught exception authenticating..." + ae);
      result.statusMsg = "Authentication exception: "+ae;
      }
      // tell em they passed in dialog if using swing
      if (mUseSwingUI && passed)
      {
      ui.showAlert("Passed authentication");
      if (smStartSession)
      ui.showAlert("Session ID: "+result.sessionID);
      }
      pl("Closing SafeWordClient");
      swClient.close();
      return result;
      }

      // example of creating and using a pool of connections
      // it is not really useful in this example, but would be if many simultaneous
      // authentications were required
      synchronized static SafeWordClient getClient(SwecConfig config) throws AuthenticationException
      {
      if (mPool == null)
      mPool = new SafeWordClientPool(config);
      return mPool.getClient();
      }

      static SwecUIHandler createUIHandler()
      {
      pl("Creating UI Handler");
      SwecUIHandler ui;
      if (mUseSwingUI)
      ui = new SwingUI();
      else
      ui = new ConsoleUI();
      return ui;
      }

      public static void pl(String s) { if (mPrintTrace) System.out.println(s); }
      }
      0
      1. Modérateur
        Ton code ne nous sers à rien car il fait appel à des librairies que l'on n'a pas !

        JAVA_EXE correspond à java.exe, or c'est javac.exe dont tu as besoin...
        Tu devrais avoir quelque chose comme ça :

        set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_24" 
        set JAVA_EXE=%JAVA_HOME%\bin\java.exe
        set JAVA_COMPILE=%JAVA_HOME%\bin\javac.exe
        set SWEC_DIR=..\lib
        
        set CLASSPATH=.;%SWEC_DIR%\swec.jar;%JAVA_HOME%\lib\rt.jar;%SWEC_DIR%\iaik_jce_full.jar;%SWEC_DIR%\iaik_ssl.jar;%SWEC_DIR%\acmecrypt.jar 
        
        %JAVAC_COMPILE% -cp %CLASSPATH% swecexample\SwecExample1.java
        %JAVA_EXE% swecexample.SwecExample1
        0