-3

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

Ali
  • 3
  • 1
  • 3
  • 1
    Like you want to look at the contents of a text file that happens to be in the java programming language, find something in the that text file, and save parts of that text file to a database? – tkone Jul 02 '12 at 20:04
  • There are some good answers on SO already. This one points to some java source parser: http://stackoverflow.com/questions/2206065/java-parse-java-source-code-extract-methods – Andreas Dolk Jul 02 '12 at 20:09
  • I know how I can parse it in both languages, I just dont know which way wound be the best to use in this particular situation. – Ali Jul 02 '12 at 20:13

1 Answers1

1

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

Community
  • 1
  • 1
Francisco Spaeth
  • 23,493
  • 7
  • 67
  • 106