I am using NETBeans IDE for developing an annotation processor. I have written the annotation processor and then convert it to a JAR and then add this JAR as a referenced library to another java application where i am using the annotations.
Now my question is inside the annotation processor if i want to access the source files( the ones which are annotated) then i try to get a FileObject using the below code
FileObject source = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH,"","demo/MainCopy.java");
but its returning null. Here demo is the package which has the annotated class MainCopy.java . When i read the documentation of StandardLocation class it says for it to work it must be supported , Could somebody help me solve this or guide me as to how to obtain the FileObject.
Thanks
Related
My idea is to write a maven plugin that generates code (just simple json) based on some annotations in my Java code. The annotated classes may be part of a used library or in my own code.
What I want is a plugin that gets a fixed set of class names (by configuration in pom). It walks through these classes, searches it for annotations on properties and generates code based on the gathered information.
Is that possible?
How can I achieve this?
Is there an existing plugin that does something like that?
I've got a project and want to share an API that can be used for building a plugin for my application.
Now I don't want to share the full source code but only class definitions and member declarations without their body.
I've seen dependencies before that without downloading the sources the IDE I'm using already knows the structure. That is what I'm going for.
A jar file already does most of what you want, as it does, if not obfuscated, contain all the class and method names in a format that will be understood by any Java IDE.
The rest can be done by preparing and delivering a javadoc jar.
I'm digging into the source code of the deeplearning for java recently. There is such a class NeuralNetConfiguration in which there are tons of fields that all requires getters and setters. The NeuralNetConfiguration.java source code does not provide any, however.
When I open this project in IntelliJ, ctrl click on the usage of this class, which are methods mostly like, NeuralNetConfiguration.getNInput() or NeuralNetConfiguration.getKernelSize(), the IDE direct me to the compiled class file in which all the getters are defined for each of the field in this class.
Just wonder how this is done since I'm a new bee to java. Posts I found about java reflect suggest that reflect can not add method to a method to a class unless you wrote your own classloader. I check the deep learning for java project and I don't think they have done that.
What bothers me too from time to time is, IntelliJ starts to report errors that those getFields methods could not be resolved since they are not in the source file at all, especially after my building the project using IntelliJ instead of using mvn command line.
The magic happens with the #Data annotation on the class. This annotation is from Project Lombok. There is probably an annotation processor somewhere that hooks into the compiling process and generates these methods.
I am trying to create and use a set of Java classes from WSDL using Apache Axis 2. I’ve successfully generated the class files using the approach described here:
http://www.gerd-riesselmann.net/scala/creating-java-classes-wsdl-file-using-apache-axis-2
I have copied the generated class files into my eclipse development environment. I have obtained all the necessary jar files and I have added them to my environment.
A single (source) problem remains that I don’t understand. The code section looks like this:
...
public org.tempuri.PreprocessingIncidentImportServiceStub.ImportResponse
import (org.tempuri.PreprocessingIncidentImportServiceStub.Import import0)
throws java.rmi.RemoteException
{
org.apache.axis2.context.MessageContext _messageContext = null;
...
Eclipse is reporting: Syntax error on token "import", expected identifier.
I don't understand the function definition that includes the "import" statement, and I am wondering if there's some eclipse setting that I must use to resolve this problem.
Thanks in advance for any help.
It seems that the method is named import. Import is a reserved word in Java so you can't name a method with it.
Assume that you have imported the classes and doesn't need to use the full qualified name of them. This is what you have:
public ImportResponse import (Import import0) throws RemoteException{
//...
}
I am newbie at Java EE and I have a simple problem.
I created a project using Maven plugin's default directory structure and I want to annotate a class as #Loggable, but I get a
Loggable cannot be resolved to a type
error. Any annotation I want to use can't be resolved to a type. What's the problem? I suspect that it has to do with dependency or build path issues but I can seem to get it working.
You will have a list of dependencies in the pom.xml file of your maven project. Make sure the jar that has Loggable is listed as a dependency.
Read here how to do it.
Your import java.lang.annotation.*; will not help as Loggable is not in that namespace.
Maybe you should write this Annotation on your own. Read this to learn more.
You have to import annotation classes just like anything else. Use an IDE such as Eclipse; it will handle and many similar tasks for you automatically.