Java 如何从.jar访问xml文件,以便从shell_exec php函数执行jar

Java 如何从.jar访问xml文件,以便从shell_exec php函数执行jar,java,php,xml,executable-jar,shell-exec,Java,Php,Xml,Executable Jar,Shell Exec,使用php从apache服务器获取jar。 我使用shell_exec并将我的jar文件交给她 但因为我在java类上解析xml文件,所以我遇到了问题。Jar无法访问xml 档案 SampleSax.java package phpJavaPack; import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; imp

使用php从apache服务器获取jar。 我使用shell_exec并将我的jar文件交给她

但因为我在java类上解析xml文件,所以我遇到了问题。Jar无法访问xml

档案

SampleSax.java

package phpJavaPack;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;


public class SampleSAX {

    public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException {        
        /*int i=0;
        MyBufferedReaderWriter f = new MyBufferedReaderWriter();
        f.openRFile("dblp.xml");
        String sLine="";
        while ((i<10) && (sLine=f.readLine()) != null) {
            System.out.println(sLine);
            i++;
        }*/

        int i=0;     
        while(i<args.length){

        System.out.println("Argument's: " + args[0]);
        System.setProperty("entityExpansionLimit", "1000000");  

        SAXParserFactory spfac = SAXParserFactory.newInstance();
        spfac.setNamespaceAware(true);

        SAXParser saxparser = spfac.newSAXParser();



            MyHandler handler = new MyHandler(args[i]);



        InputSource is = new InputSource("dblpmini.xml");
        is.setEncoding("ISO-8859-1");
        System.out.println("Please wait...");
        saxparser.parse(is, handler);

        System.out.println("---->" + handler.getprofessorsPublications());

        i++;
        }

        //System.out.println("#####################################################################################################");
        //System.out.println("List of George A. Vouros: " + handler.getprofessorsPublicationsValue("George A. Vouros"));


        //System.out.println(handler.getProfessors());

        //handler.createHtmlPage();//emfanizei mia html selida me ta apotelesmata
    }
}
包phpJavaPack;
导入java.io.IOException;
导入javax.xml.parsers.parserConfiguration异常;
导入javax.xml.parsers.SAXParser;
导入javax.xml.parsers.SAXParserFactory;
导入org.xml.sax.InputSource;
导入org.xml.sax.SAXException;
公共类样本{
公共静态void main(字符串[]args)引发IOException、SAXException、ParserConfiguration异常{
/*int i=0;
MyBufferedReaderWriter f=新的MyBufferedReaderWriter();
f、 openRFile(“dblp.xml”);
字符串sLine=“”;
而((isee)-最有可能的建议/示例是最好的

在该线程中也可以看到其他建议,比如chdir

package phpJavaPack;

import java.util.ArrayList;
import java.util.Hashtable;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class MyHandler extends DefaultHandler {

       private Publication publication;
       protected Hashtable<String, ArrayList<Publication>> professorsPublications = new Hashtable<String, ArrayList<Publication>>();
       private String temp ;
       private ArrayList<Publication> al;

       //private EntryLd entry = new EntryLd();

//       public MyHandler() {
//         super();
//         
//         String[] namesTable = entry.getNamesInput();
//         
//         
//         for (String name: namesTable) {
//             
//             al = new ArrayList<Publication>();
//             professorsPublications.put(name, al);
//         }
//         
//         System.out.println("HashTable: " + professorsPublications);
//       }

       public MyHandler(String authorForSearch){
           super();
           String name = authorForSearch;

           al = new ArrayList<Publication>();
           professorsPublications.put(name, al);

           System.out.println("HashTable: " + professorsPublications);
       }

       public Hashtable<String, ArrayList<Publication>> getprofessorsPublications() {

           return professorsPublications;
       }

       public ArrayList<Publication> getprofessorsPublicationsValue(String author) {

           return professorsPublications.get(author);
       }


       public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException 
       {
           temp = "";
           if (qName.equalsIgnoreCase("article") || qName.equalsIgnoreCase("inproceedings") 
                   || qName.equalsIgnoreCase("proceedings") || qName.equalsIgnoreCase("book") 
                   || qName.equalsIgnoreCase("incollection") || qName.equalsIgnoreCase("phdthesis")
                   || qName.equalsIgnoreCase("mastersthesis") || qName.equalsIgnoreCase("www")) {
               publication = new Publication();
           }
       }

       public void characters(char[] ch, int start, int length) {
           temp = new String(ch, start, length);
           System.out.println("----->>>" + temp);
           //System.out.print(" <--- My temp's start: " + temp + " :My temp's end --> ");
       }


       public void endElement(String uri, String localName, String qName) throws SAXException 
       {
           if (qName.equalsIgnoreCase("article") || qName.equalsIgnoreCase("inproceedings") 
                   || qName.equalsIgnoreCase("proceedings") || qName.equalsIgnoreCase("book") 
                   || qName.equalsIgnoreCase("incollection") || qName.equalsIgnoreCase("phdthesis")
                   || qName.equalsIgnoreCase("mastersthesis") || qName.equalsIgnoreCase("www")) 
           {
               for(int i=0; i<publication.getAuthors().size(); i++) {
                   String authorName = publication.getAuthors().get(i);
                   if(this.professorsPublications.containsKey(authorName)) {
                       this.publication.setType(localName);
                      this.professorsPublications.get(authorName).add(publication);
                   }
               }
           }
           if(qName.equalsIgnoreCase("author")) {
               publication.addAuthor(temp);
           }
           else if(qName.equalsIgnoreCase("title")) {
               publication.setTitle(temp);
           }
           else if(qName.equalsIgnoreCase("year")) {
               publication.setYear(Short.parseShort(temp));
           } 
           else if(qName.equalsIgnoreCase("booktitle")) {
               publication.setBooktitle(temp);
           }

           //String xl = publication.toString();
           //System.out.println(xl);
       }

 }