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.
preguntado el 02 de julio de 12 a las 21:07
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.
<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.
Reflexión 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 https://www.youtube.com/watch?v=xB-eutXNUMXJtA&feature=youtu.be