title: How to call cplex .mod and .data from Java
body: <p>I have an optimization problem modelled and written in IBM ILOG CPLEX Optimization Studio. I want to call .mod and .dat from Java. I found some example to do it. However, I got some error.   </p>
  
  <p>My code is shown below. I also added all cplex and opl library </p>
  
  <pre><code>package cplexJava;
  import ilog.concert.*;
  import ilog.cplex.*;
  import ilog.opl.*;
  
  
  public class main {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
                model();
      }
       public static void model() {
            int status = 127;                                                       
  
                IloOplFactory.setDebugMode(true);                                     
                IloOplFactory oplF = new IloOplFactory();                             
                IloOplErrorHandler errHandler = oplF.createOplErrorHandler();         
                IloOplModelSource modelSource = oplF.createOplModelSource("D:/Cplex project/Example_2/Example_2.mod");                                            
                IloOplSettings settings = oplF.createOplSettings(errHandler);         
                IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource,settings);
                IloCplex cplex = oplF.createCplex();                                  
                cplex.setOut(null);                                                   
                IloOplModel opl = oplF.createOplModel(def, cplex);                    
                IloOplDataSource dataSource = oplF.createOplDataSource("D:/Cplex project/Example_2/Example_2.dat");                                            
                opl.addDataSource(dataSource);                                        
                opl.generate();                                                       
                if (cplex.solve())                                                    
                {                                                                     
                    System.out.println("OBJECTIVE: " + opl.getCplex().getObjValue()); 
                    opl.postProcess();                                                
                    opl.printSolution(System.out);                                    
                }                                                                     
                else                                                                  
                {                                                                     
                    System.out.println("No solution!");                               
                }                                                                     
                oplF.end();                                                           
                        status = 0;                                                   
  
              System.exit(status);
       }
  }
  </code></pre>
  
  <p>In my code, the errors came from from  <code>oplF.createCplex()</code> and  <code>cplex.solve()</code>. When I tried to run it, this is the error I got.
  <a href="https://i.stack.imgur.com/6faMe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6faMe.png" alt="enter image description here"></a>
  I could not figure out why I got the errors from  <code>oplF.createCplex()</code> and  <code>cplex.solve()</code> although I already added the <code>cplex</code> and <code>opl</code> library</p>