doucao8982 2012-07-02 20:01
浏览 28

使用php或java解析java?

I am building a web application which in the back end needs to parse a java file and save certain values in a database. This has to be triggered by the user and set on a schedule.

What is the best way of doing this? Should I do this using php or java? Know how to parse the file in both languages however java has reflection which would make it easier and reduce the likelihood of error however I have no idea now to call a java file from the front end e.g. onclick of a button.

The front end technologies I'm looking to use are html, css, javascript and ajax. I'm not looking to use struts e.t.c as I am not familiar with them and I am limited on time.

Thanks

  • 写回答

1条回答 默认 最新

  • dongsou0083 2012-07-02 20:27
    关注

    Reflection will not help in this case, because you need to parse the code (Java in this case) and interpret as you which. Therefore you will need to build an AST of your file.

    AST (Abstract Syntax Tree) could be build in Java using Eclipse JDT. On maven central:

        <dependency>
            <groupId>org.eclipse.jdt</groupId>
            <artifactId>org.eclipse.jdt.core</artifactId>
            <version>3.12.2</version>
        </dependency>
    

    Eclipse JDT is a document model that could be compared to a DOM Tree, with the DOM Tree you can access elements, attributes and so on of an XML. The AST has the same scope, you can access for example the class Name, or methods of that class extracting parameters names and types for each method without instantiate an Object based on that class. Other artefacts like documentation or comments are accessible over JDT.

    Reflection can be applied just in case that you have the class loaded on to some class loader, and even so, there are some information like documentation or parameters names that you cannot access through reflection.

    A good start is read this hands post: http://www.vogella.com/articles/EclipseJDT/article.html#jdt

    And a simple start could be done using the code I posted on this answer

    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题