I am using Eclipse and JBoss Tools to generate Java classes from existing Hibernate mappings. Whenever the classes get generated, they have a comment at the top of the class that indicates when the class was auto-generated.
I really want to prevent this from happening since it is a nuisance when these classes are under configuration management. I've looked through all the settings I can think of and online and haven't found out how to do this yet. It seems like it should be very simple, but it hasn't been.
Anyone know how to suppress this comment from being created?
You can edit the tempalte files in the jar file of jboss tools so it does not generate that info. As far as I can remember it uses velocity templates, so you just need to delete that bit from the template files and it wont generate those comments.
When I was using eclipse to generated the POJO's I had the same problem (when working with GIT reporitory). I build a simple program in .Net in order to clean the comments. After I run the hibernate configuration, I run the .exe (it must be located in the same folder of the POJO's files)
You can find the code and an .exe app in https://github.com/jaimeimarin/HibernateHeadersCleaner . If you are working with git remember to add an exception in order to commit the tool.
#Add this line to your .gitignore file
!HibernateHeadersCleaner.exe
Related
How to understand which are the auto-generated files in a huge Java project developed in Eclipse?
I am a newbie. For example, little by little, I am discovering that many files are generated by using xcore plug-in. Other with xtend. Just going through the code and trying I am learning and that's ok. The question is: is there a way to understand which files to modify to automatically regenerate the others? My error was to start modifying all the files manually.
Usually you set up different source directories for your code and generated code.
For example, a project using Xtend and EMF would have following source directories in its build path:
src contains all Java and Xtend files that you write
xtend-gen contains generated Java files created by Xtend
src-gen contains generated Java files created by EMF
In this setup you should only edit files in src. Files in xtend-gen will be updated automatically if you edit Xtend files in src. Files in src-gen will be updated if you regenerate the model.
I'm not that familiar with Xcore, but since it is based on EMF I think you just have to set the "model directory" property of the genmodel.
This should make the distinction between your code and generated code more clear. You may still feel the need to modify generated code sometimes. EMF actually supports this by adding special annotations in the generated file but I would not recommend this, because it's very hard to see if a file has been modified this way. If you really need to change the generated behavior, the first approach described in this article about properly overriding generated EMF code is better. Basically you extend and override methods of some generated classes and the factory and then use Eclipse extension points to replace the generated factory with your extended one.
If you are looking at a project of someone else and don't know which code generating tools are used:
You should try to ask the authors if possible or check if there is any documentation about building the project. Otherwise I guess you'll need to analyze the project structure to see which plugins are used to generate code. This might be a bit hard if you don't already know which plugins actually can generate code though.
Check the Eclipse "Project Nature" to see which plugins are used to build
Check build configuration (Ant, Maven, Gradle) for plugins that might generate code
Look for special files (xcore, genmodel, etc) and figure out to which
Check if there are any Annotation Processors configured and check if they create any files
(Xtend only) Check if there are Active Annotation and check if they create any files
Check if #Generated annotations is used in the code, which is used to mark generated files
If you have Identified all tools, then try to change the model destination directory and regenerate the code. Then compare the generated files with your original code - all duplicated files are likely generated.
I am building a desktop application with NetBeans 8.0.2. For my application, I have to manage 3 differents projects : The main project, and two "tool" projects that are linked to the main.
When I run the main project, it will check the JARs present in his classpath in order to retrieve the Manifest files and do some work with.
In order to have my application run correctly, it has to see the two linked projects' JARs but it doesn't, because NetBeans deals with the compiled classes of the project instead of the JAR (for debugging purposes I presume).
I found nothing about it on the Oracle documentation, and the only thing looking a bit like what I search is to create a big-fat-JAR by using another component.
Is there a way to tell NetBeans to "compile the linked projects and use the JARs instead of the .class" files ? Thanks in advance
EDIT : Here is an example when I add the project with "Add Project .." option
/C:/Users/xxxxx/Documents/GuiceProjectsRD/xxxReaderRef/build/classes/
And here is an example when I add the JAR
/C:/Users/xxxxx/Documents/JavaLib/xxxReaderRef.jar
When I add the JAR, I have the ".jar" extension which helps me identify a JAR and then look into it for a Manifest. When I add the Project, there is no path to the JAR but only to the compiled classes, and I can't work with that.
I would not depend on the Manifests in Jars since you then get this kind of issues.
Have a look at the Typesafe Config library. It's a small 100% pure Java library to work with Json/Hokon configuration.
Instead of relying on a Manifest, create a 'reference.conf' in each tool project. In your application, create an 'application.conf' (if needed). Load the config via 'ConfigFactory.load()'. It will automatically search all available reference.conf's, and application.conf, on the classpath, whether in a jar or not, and merge those configs into a single configuration.
I use this approach in project to be able to plugin extension. Have for example in tool A a configuration like
tool.A.class = 'my-tool-A.class'
or used nested structures like
tool {
A {
class = 'my-tool-A.class'
}
}
Do something similar voor tool B.
Then in your application, from the Config, you can get a list of 'tool' configs and detect the available tools like that.
Our organization invested in a java web application that we want to be able to develop upon. Unfortunately last developer left with only the .war file. How can we recover some of the class files, change them then redeploy as war again. We tried to do that in Eclipse but after importing as war, we could not configure build path. (which in my understanding, the war was imported as static project). I could not find "Convert to dynamic project" as said in eclipse help document.
A .jar/.war file is compressed using the ZIP format. You can decompress it using any zip utility like WinZIP/WinRAR/etc. and then use your favorite decompiler on the .class files.
Java Decompiler is the best I've ever come across. You could open your entire war with this.
There is another option for special cases: Have a look at aspectj, so you can
weave in additional code around method calls to fix bugs etc.
add fields or methods etc.
It works on the byte code level (it works with .class files).
As for the long run, grab what you recover using a decompiler, and start to replace class files step by step.
I have a small project created with IntelliJ IDEA, using Jersey.
I already created the server part working just fine and hosted on a GAE server.
I try to connect to it via a Jersey Client, and here comes the strange stuff.
Everything works fine if I run my application from inside the IntelliJ IDEA. However, once I run the jar JSON support seems to be gone, however XML works. Any ideas?
I feel I need to mention that the jersey-json is packaged with the generated jar.
Here it is the jar file in question. You'll need both the jar and the dll file, one near the other and just run it.
The Console Output (Error): https://docs.google.com/open?id=0B42XvjSlpDCtTTdwQl9MSTBlQ0U
The JAR file I used (all dependencies extracted into it). Any JRE6 may run it. https://docs.google.com/open?id=0B42XvjSlpDCtTVNUQTQ4SXFCcDg
The DLL required for the JAR (although, it should work without this too): https://docs.google.com/open?id=0B42XvjSlpDCtNXpabVk5RDkyRW8
And here's the source code on the github (public): https://github.com/gaborbernat/fs_viewer
Finally, I attach a picture with the settings of the artifact (JAR) generate rules.
Thanks for your support, :)
please see http://java.net/projects/jersey/sources/svn/content/trunk/jersey/jersey-tests/src/test/java/com/sun/jersey/impl/json/ListOfJAXBBeanTest.java?rev=5698
(your usecase can be extracted from there; the point is that you need to configure Jersey Client to be able to handle json by a) registering JAXBContextResolver or b) explicitly adding MessageBodyWriters (jackson))
And dont forget to use GenericEntity (as in linked test).
I'm currently working on a Java project which uses Tibco rendezvous control.
I have the tibrvj.jar file on my build path. But I'm not able to see the classes which are there in the package "com.tibco.tibrv".
This package is in the jar which is on my build path.
When I try to open the class in that package , the message displayed on class editor is : "Source not found. the jar file tibrvj.jar has no source attachment".
Is there anything that could be done to set it right ?
This looks like an IDE specific message. Which IDE are you using?
The jar in your classpath only contains the java classes (bytecode) and not the source files (.java files). It looks like you are trying to open the class in your IDE/editor. Since you do not have the java files corrsponding to these classes, the editor is comlaining.
As these are Tibco specific classes, the only option is to "decompile" the classes to see the corresponding java code. Consider using a decompiler like DJ Java Decompiler
It depends on what you mean by "I'm not able to see the classes." If you mean you're getting build failures, that's possibly a matter of not actually having it properly in your build path (how are you building?) or maybe not having the right imports.
If you mean you can't see the source code, you'll need to get hold of it somehow (is Tibco open source?) and then configure your IDE so that it knows where the source is. Of course you don't need to source just to be able to build your app which uses Tibco.
If you could give more information about exactly which problem you're facing, along with what IDE you're using (if any) we could probably help more.