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..
Re: Error while running in Command prompt only, In eclipse running fine.
A first step could be to tell us the error details.
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
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
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?
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.