如何从.jar访问来自shell_exec php函数的执行jar的xml文件

时间:2016-01-28 12:25:48

标签: 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;
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
    }
}

MyHandler.java

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);
       }

 }

如何在可运行的jar上给出正确的xml?

日Thnx

1 个答案:

答案 0 :(得分:0)

请参阅PHP exec() command: how to specify working directory? - 最有可能的proc_open建议/示例中有最好的

也可以看到该主题的其他建议,例如chdir