I am trying to create a java file from scratch using AST but it is painstakingly taking me longer to finish. What I have in mind is create the java file, then create the project and package and then copy that file to that package. Is there a way to do this?
Thanks.
I use Apache Velocity, in order to create Java classes from templates. In my case, i had to create from (velocity) templates some classes (and maven pom) using Eclipse Wizards. But if you want to modify these classes, then the best choice would be AST/JDT.
http://sdqweb.ipd.kit.edu/wiki/JDT_Tutorial:_Creating_Eclipse_Java_Projects_Programmatically
shows how to create a java project using JDT and configure your classpaths subsequently.
You can use JBoss forge to generate java classes problematically. it has api to write scaffolding plugins. it uses Apache Velocity templates to do that.
Also Spring Roo can be another choice, if you are a Spring guy ;)
IFile#setContents(InputStream ...) would seem like a good candidate.
You can also use the ImportOperation to import files from anywhere (incl. the filesystem outside of the workspace) into a project.
Related
I want to create one external jar for Logging Purposes,so that i can import this jar in any java project.But i would like to use the classes and methods of java project in external jar.
Is it possible ?If yes,please help.
I think it's possible from Reverse Engineering,but not able to figure out how to use class and specially methods in external jar.
It is possible, but very bad practice.
You need to import each project into eachother.
Project A imports Project B
and
Project B imports Project A.
I would recommend you to use eclipse and add the projects as source. You can read how to do that here:
Creating a java library with Eclipse
You can read about the bad practice of what you ara about to do here:
Two java libraries importing each other?
I'm programming in Java, and I usually prefer git when programming in Python. So I want to use it for Java too. I'm using Eclipse, but other people may use Netbeans or IntelliJ IDEA or whatever. How is this usually managed when putting Java code into version control?
I'm making a game which uses the library LWJGL, and that library needs to be added to the project file to be used. Therefore, I still need to check the project file into my project.
Short answer, it doesn't matter at all. Create a file called .gitignore in the root of your project file to ignore your IDE's project files or anything like that, then add your code into the git repository. For example, a good Eclipse .gitignore can be found here.
That way the other collaborators won't see your project files, and if they do the same with their .gitignore for their IDE, you won't see theirs.
I wish to write a shared library to be used in various GWT applications. The shared library will leverage GWT APIs and should not be able to use non-emulated Java classes.
Two questions:
Is there a plugin for Eclipse that will let me use GWT APIs and flag if I use a non-emulated class (but will simply build a compliant jar rather than a war)? (I know that the standard plugin does this when working in the 'client' area, I just want the same behaviour for the entire source tree)
If not, is there a Maven/Ant plugin that will help?
For a GWT library, you have to include a GWT module (*.gwt.xml file) and the *.java files in your *.jar (or in a distinct JAR if you prefer).
AFAIK, the Google Plugin for Eclipse uses the information from the *.gwt.xml files, the client subpackage is not hard-coded; so you should be able to use it the same way as with a GWT application.
Finally, you can call the GWT compiler with the argument -validateOnly to check that your GWT module uses only translatable classes.
I am pretty sure that you can't develop a gwt shared library and pack it into a jar file. Gwt require access to all source code when compiling files. It can't read class files at all. Or have I misunderstood what you are trying to do?
As I do more and more coding in Java I am creating a library of methods that I use often. Is there a way in Eclipse to set it so that I can import these methods from the source folder of the library project to other projects without copying them to each individual project?
I know there is something that I can do with the Build Path, but when I try to add the source for my library I get a package error in the project it is linked to.
Thanks
Don't import/copy the code from another project--the point is to use the output of the shared project. Just indicate that the project depends on the other project; don't think about the shared project's source.
Does Eclipse support the concept of reusable "project structures" via scripting/configging?
For instance if I want all of my projects - upon creation - to take on the form:
MyProjectRoot/
src/
fizz/
buzz/
docs/
Is there a way to define this project structure somewhere (XML, etc.), and then link a new project to that structure?
I know I can write an ant/maven script to do this for me, but having a resource like this would save me from a lot of manual copying & pasting the same buildscript.
Thanks in advance!
Out of the box, I don't think this exists.
One option is to create a template project and save the dir tree off somewhere. Then when you need a new project that should follow template, you can copy the dir tree and use File -> Import.
Another option that I'd recommend is to just use Maven and have Maven dictate dir structure. Eclipse can then import that maven project.
Yes it is possible. But not easily. You basically have to create your own plugin, which frankly I don't see the juice being worth the squeeze. Now, if you are learning/using Maven, then you already have a very good directory layout defined for you. Getting that directory structure imported into Eclipse is a one-line command in your shell. And if you decide to switch to NetBeans then you don't even have too run that shell command (native integration ftw)!
But of course, you are constrained to Maven best-practices for directory layout (good, bad or indifferent).
I'm including a link to the Eclipse Help documentation, in the case you decide to go down the custom plugin route. Good luck!
Custom project types in Eclipse