Results 1 to 6 of 6
  1. #1
    gvs048 is offline Member
    Join Date
    Apr 2013
    Posts
    16
    Rep Power
    0

    Default Error while running in Command prompt only, In eclipse running fine.

    This is my program: RemoteXMLRead.java

    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;

    import org.apache.commons.io.filefilter.WildcardFileFilte r;
    import org.w3c.dom.Document;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.Node;
    import org.w3c.dom.Element;
    import java.io.File;
    import java.io.FileFilter;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;

    public class RemoteXMLRead {

    public static void main(String argv[]) {
    Connection conn = null;

    try {

    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    String url3 = "jdbc:sqlserver://127.0.0.1:1433;databaseName=TestPerfomenceTrack";
    conn = DriverManager.getConnection(url3, "reliantUser", "F4C78266-021e");

    Statement stmt = conn.createStatement();
    String sql = "";

    List<File> files = listf("C:\\jenkins\\jobs\\AdvBackOffice\\builds");

    File dir = new File(files.get(258), sql);
    FileFilter fileFilter2 = new WildcardFileFilter("*.xml");
    File[] files2 = dir.listFiles(fileFilter2);

    File fXmlFile = files2[1];
    System.out.println(fXmlFile);
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);


    doc.getDocumentElement().normalize();
    NodeList nList = doc.getElementsByTagName("case");

    for (int temp = 0; temp < nList.getLength(); temp++) {
    Node nNode = nList.item(temp);
    if (nNode.getNodeType() == Node.ELEMENT_NODE) {
    Element eElement = (Element) nNode;

    sql="EXEC [spXMLDataForTestCasesTrack] " +
    "'"+eElement.getElementsByTagName("duration").item (0).getTextContent()+"'," +
    "'"+eElement.getElementsByTagName("className").ite m(0).getTextContent()+"'," +
    "'"+eElement.getElementsByTagName("testName").item (0).getTextContent()+"'," +
    "'"+eElement.getElementsByTagName("skipped").item( 0).getTextContent()+"'," +
    ""+eElement.getElementsByTagName("failedSince").it em(0).getTextContent()+"";
    stmt.executeUpdate(sql);



    /*--EXEC [spXMLDataForTestCasesTrack] '123.00','test class name','test test name','test skipped',3
    --SELECT * FROM [dbo].[ExecutionTimeTrack]*/

    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    public static List<File> listf(String directoryName) {
    File directory = new File(directoryName);

    List<File> resultList = new ArrayList<File>();

    // get all the files from a directory
    File[] fList = directory.listFiles();
    resultList.addAll(Arrays.asList(fList));
    for (File file : fList) {
    if (file.isFile()) {
    System.out.println(file.getAbsolutePath());
    } else if (file.isDirectory()) {
    resultList.addAll(listf(file.getAbsolutePath()));
    }
    }
    //System.out.println(fList);
    return resultList;
    }

    }

    It is working fine when i run in Eclipse, but is giving error when i run in cmd..
    what i need to do to over come this..

  2. #2
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: Error while running in Command prompt only, In eclipse running fine.

    A first step could be to tell us the error details.

  3. #3
    gvs048 is offline Member
    Join Date
    Apr 2013
    Posts
    16
    Rep Power
    0

    Default Re: Error while running in Command prompt only, In eclipse running fine.

    This is the error i am getting ...


    RemoteXMLRead.java:4: error: package org.apache.commons.io.filefilter does not e
    xist
    import org.apache.commons.io.filefilter.WildcardFileFilte r;
    ^
    RemoteXMLRead.java:35: error: cannot find symbol
    FileFilter fileFilter2 = new WildcardFileFilter("*.xml")
    ;
    ^
    symbol: class WildcardFileFilter
    location: class RemoteXMLRead
    2 errors

  4. #4
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: Error while running in Command prompt only, In eclipse running fine.

    Hi,
    It seems to be a problem with your classpath. Make sure that the libraries that you added in eclipse are in your classpath when you start your application on the commandline.

    Apache commons lib is not found so WildcardFileFilter class is not known.

    Konrad

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,848
    Rep Power
    5

    Default Re: Error while running in Command prompt only, In eclipse running fine.

    HOW are you running this on the command prompt? Executable jar? Just run the main class?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    444
    Rep Power
    6

    Default Re: Error while running in Command prompt only, In eclipse running fine.

    I do not know why you are worrying even if it's working fine in eclipse. Wanna run Java with out IDE, first you have to learn what PATH and CLASSPATH mean.

    Hope you could be able to run the same on command prompt once you understand PATH and CLASSPATH.
    Mak
    (Living @ Virtual World)

Similar Threads

  1. Running .jar in command prompt
    By wonstatus in forum New To Java
    Replies: 7
    Last Post: 07-17-2011, 11:35 PM
  2. error in the Command Prompt when running a bat file
    By bluesagemedia in forum New To Java
    Replies: 1
    Last Post: 10-03-2010, 01:05 AM
  3. Compiling/Running in Command Prompt
    By coke_in_a_can in forum New To Java
    Replies: 12
    Last Post: 05-31-2010, 09:05 AM
  4. running command prompt using java
    By xclaim in forum New To Java
    Replies: 1
    Last Post: 01-14-2010, 03:46 AM
  5. Running eclipse java project on command prompt
    By hnmapara in forum New To Java
    Replies: 1
    Last Post: 07-09-2008, 08:29 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •