eclipse java annotation processing commit generated java classes with subclipse to svn - java

I'm using Java annotation processing to generate a couple of Java source files. I enabled it on the project specific settings (Properties -> Java Compile -> Annotation Processing). The generation works fine and the classes end up in the .apt_generated source folder.
Unfortunately, I'm not able to commit the generated Java source files with Subversive to the svn server. If I selected the .apt_generated source folder and perform Team -> Add to Version Control ... the dialog doesn't list any files to commit. So far, I have been committing .apt_generated source folder from the command line. Can I customize this behavior? I wasn't able to find anything on this in the team preferences.
I'm aware of the option adjusting the headless build. Since my files won't be changed to often, I just would like to commit the generated files for the moment. Thank you!

The reason for this behaviour can be found in this thread: Subversive doesn't allow to commit "derived" resources. The folder used by the annotation processing and all contained resources automatically get the "derived" flag, which you can verify on their Properties->Resource page.
I'm in a similar situation as you wanting to commit generated files at least initially. There is a plugin that apparently makes it possible to override the behaviour of setting the "derived" flag, which I'm going to test now: AutoDeriv

Since this has been unanswered for over a year, I'll take a stab at it. I had a similar problem with Eclipse's .project and .classpath files, which I wanted maintained in Subversion.
I believe you may have to tell Eclipse not to ignore "resources." These are files that have extensions but no names (e.g. .project or .classpath or .apt_generated). From Eclipse's Project Explorer click on the View Menu icon (the upside down triangle icon). Then Customize View... then remove the check from the checkbox labeled .* resources.

Related

How to import JAR file as a project into an IDE?

I have a Maven project. After I make changes to the project, I package the project up into an Uber Jar file and upload that to my backups. I am wondering, if my computer were to break or I lose all the code to the project, can I get the project back using only the Uber Jar file or would the project be gone forever?
How can I open this Jar file as a project and view all the Java code inside of it?
It would be entirely gone; that jar file contains only class files, not your source files, and you can't 'recover' source files from class files (you can decompile them which is mostly useless for this purpose; all comments, most names, most structure - all gone. You can't feasibly continue your project with this).
As it isn't in there, it's not possible to 'open a jar file and see all java code inside it'.
You'll need to set up backups.
The proper way forward is to first set up version control; this ensures that you don't just have a backup of the latest state of your source files, but every state of it - you can travel back to any time. Protects against code you deleted by accident, and means you can freely remove code you think you no longer need without that nagging feeling of: Yeah but what if.... maybe later? - so stop commenting out stuff you don't need, just get rid of it. It also means if there's a bug, you can time travel to the exact point in time when you added the line, and you can review the changes made by others in a project (presumably you're writing this on your own for now, but at some point you'll work with more people than just yourself!)
Read up on git which is the version control system that 80%+ or so of the community uses, probably best not to spring for exotic options if you aren't familiar. There are a billion tutorials out there to find if you search the web.
Host your git on a site like github or bitbucket which therefore also takes care of backups. Alternatively, host it on your own server (it's not complicated; git is open source). If you can't do that either, just let git write to a local directory and then use e.g. backblaze or something similar to ensure that file is backed up.
Yes, you can view your code by using a decompiler. I have experience mostly with IntelliJ, and this IDE includes a decompiler of its own. In case you lose everything and have only the jar file. You can use this included decompiler to get your source back from your .class files. But instructions on doing that are a story for another question...
If you want to secure your code use GIT. A version control tool that is a must when it comes to programming. Google about it and after a few days of playing around with it, you will never worry about such things.
Right-click on your project.
Select Build Path.
Click on Configure Build Path.
Click on Libraries, select Modulepath and select Add External JARs.
Select the jar file from the required folder.
Click and Apply and Ok.

Include/exclude IDE-specific configuration files from Mercurial version control

The IntelliJ 2017.2 documentation suggests including the .idea folder that contains that IDE’s own configuration files (excepting the workspace.xml and tasks.xml files). I can understand the sense in this, as I could incorrectly configure the project settings and want to revert.
Yet, I want to post this open-source multi-module Maven-driven project to BitBucket for public access. Obviously, not everybody uses IntelliJ as their IDE, so I do not want to force my IDE settings on them.
➠ How do open-source authors resolve this conundrum?
My suggestion that comes from experience is to always explicitly ignore (that is, add to .hgignore or .gitignore) IDE configuration files or directories.
It is not only a question of not spamming a project with configuration files for a specific IDE. The real problem begins when more that one person uses the same IDE. Depending on the IDE and on how it is configured, you can fall in a situation where each commit contains changes to these files, and will confuse all the other developer using the same IDE, which in turn will overwrite the changes again in a infinite loop.
Some of your IDE settings will be global and stored in your home directory. The ones that are project specific will survive as long as you don't change the local directory in which you cloned the repo. If you change directory, in my experience it is always tolerable to reconfigure the IDE. There are at least two situations when the local directory changes: (1) you remove the directory and clone the repository again (2) you use more than one computer.
If you are concerned for things like coding style, then the best approach is to use a command-line formatter tool that works for any editor or IDE. That tool will have its configuration file committed in the repo, since coding style is something that should be equal for all developers and files of a repo.

Eclipse Java Project - Open Declaration always opens class file instead of .java

I'm posting this query after doing lots of googling and trying out different options for last few days. Is there an easy way to attach source in Eclipse? is the closest answer I found to my question.
From above post, I tried all solutions but each time Eclipse is opening .class file instead of .java file.
Eclipse Details:
Kepler Service Release 2
Build id:20140224-0627
Please let me know if this is a bug with Eclipse or if I am missing something.
If you are using Maven, try this:
Double click on your project in eclipse -> Maven -> Enable Workspace Resolution
This is most likely because Eclipse actually use the class file for declaring the item you have requested the declaration for, and not the source file you think it should be using.
The typical reason for this is if you have a jar file containing previously compiled classes on your build path before (or instead) of the project containing the source you want. This is very rarely desirable as it can take quite a while to discover that your edits do not take effect.
Examine your build path carefully and ensure it is as you want it to be.
Maven is likely supplying a Classpath Container to your project, and generating entries for the Java Build Path based on the pom.xml contents (the JRE System Library is another example of this). Its entries will not have source attachment unless the container decides it will, which is why the Installed JREs preference page offers to let you set Source Attachments. If the pom.xml has something like that, see if you can use it. If not, see if you can configure the Maven container from its context menu. Otherwise, you may simply be stuck.
I had this same problem: when I pressed F3 or tried to open Declaration (after right click) for any element, it took me to the bytecode .class file.
My solution:
I went to the project in Project Explorer:
right click on project name->Properties
Then in Porject Properties window,
Java Build Path->"Order and Export" tab
There I selected the folder with the .java files (source code), which was below the folder having the .class files -in my case "JRE System Library [java-11-openjdk-amd64]", and pressed 'Top' button on the right frame. Then the folder with source files moved to the top.
Finally, pressed "Apply and Close" button.
That solved my problem forever and ever.
The folder
I installed a plug-in which allows me to download the sources for a maven project.
I'm not by my develop machine right now, but I think it was this:
http://marketplace.eclipse.org/content/m2e-dynamic-sources-lookup#.U8gjGWIaySM
With this, you can select a project an have maven download the sources and make then available when you navigate the code in Eclipse. All without "leaving" Eclipse.
Check into your project modules the Java Build Path, look inside the Source tab and verify if you have "Allow output folders for source folders" checkbox flagged; in this case you just need to uncheck it and you will be able to see again the right source from java files.
This is related to the Call Hierarchy in Eclipse IDE.
If you are in a situation, where you're seeing duplicate methods inside the call hierarchy showing Members calling 'myMethod(...)', double-clicking on one of the listed methods may open the .class file instead of the .java file.
When this happens, the solution is to set the search scope in the call hierarchy to Project instead of Workspace.
After setting the search scope, you won't be seeing duplicate methods listed in the call hierarchy, and double-clicking on the listed methods will only open the .java files.
(Using Eclipse DevStyle Dark Theme)

Loading a eclipse pluggin from jar files

I am trying to run a sample plugin
The extracted zip comprises of 2 jar files . So i loaded them into the eclipse by using the New->PluginDevelopment->Plugin form existing jar files wizard .
This loads the plugin but it does not run as expected . Comparing it with a sample Hello world plugin i realize that it does not have a Activator.java file and a SampleAction.java file within the src folder .
How do i get this plugin to work ? Surely there must be a way .
That example is very old and so is difficult to get going in modern eclipse. It still is a good introduction to writing debugger plugins but after you get the gist of the article, I advise looking at the current source code for any debuggers that you might be familiar with using.
You should note that there are two plugins. Keep them separate. I found it useful to extract the jar and src zip files into their respective plugin projects.
Then you have to upgrade the plugin manifest format. There should be a warning about each item that needs to changed. There might be a upgrade function in some versions of eclipse but I couldn't find in 3.7.1.
Open the manifest in the editor and select the MANIFEST.MF and plugin.xml bottom tabs to see the raw manifest. The work is mostly to move the data from plugin.xml to MANIFEST.MF. You can see it in plugin.xml and the use the editor pages to add the same information. Then delete it from plugin.xml. As you point out, one of the manifest items is the activation class. In the old plugin.xml format, this in in the Plugin/#Class attribute, so move it to the Activator field.
You'll end up with a few warnings about deprecated APIs. You can leave them or rewrite the simple functions that use them.
To run the plugins you need to run an Eclipse Application launch (run/debug configuration).
The two plugins in the example don't create main toolbars or menus. You can see that they are loaded via Help > About > Installation Details > Plug-ins. You should now be able to switch to the Debug perspective and open the Data Stack view. And, also Debug > Debug Configurations > Push Down Automata will list PDA launch configurations. Note: You can set breakpoints in .pda files (Ctrl+Shift+B) but the plugins don't implement vertical editor ruler markers so you can only see them in the Breakpoints view.

How can I stop Eclipse warning about target folder's contents?

I'm getting loads of warnings from generated files in my target folder (e.g. Java code generated from XSDs or surefire reports) that I can't fix, and it's hiding proper warnings in my source code.
Does anyone know of a way to tell Eclipse not to display warnings in certain folders, or just the "Derived" or target folders?
I've only been able to find the following two "almost" solutions:
The filter in the "Problems" view allows you to hide warnings containing (or not containing) a specific String in their description, but not part of their path or resource (file). Even if you could, this wouldn't be an ideal solution as the warnings would still be displayed on the project in the package explorer, hiding potential real warnings.
With the latest Eclipse version (Juno / 4.2) in the "Java Build Path" settings under the "Source" tab, you can "ignore optional compile problems" from each source folder. But this obviously doesn't work for cases where the folders aren't source folders (like the surefire reports). It does however fix one specific problem with warnings about generated sources, but might not in others, where the sources aren't (can't be) included as source.
It would just be nice if there was a way to tell eclipse not to display warnings about things in the target folder altogether, as it's often not very useful and might hide actual problems.
Cheers,
Svend.
It turns out you can do this fairly simply (at least in Eclipse Kepler).
Open up the Preferences panel, either for Eclipse as a whole or for the project. Select the Validation pane (if you're using the project preferences panel, you may need to enable project-specific settings). Now go to the validator that's causing you problems (in my case, it was the HTML validator, but it depends on what you're doing) and click the button to edit its settings, which pops up another dialog.
In this dialog you want to make sure that there is an Exclude Group that excludes Folder: target. If there's no exclude group at all, add one with the button on the right. Then select the exclude group and Add Rule… to bring up another dialog/wizard. You want to add a Folder or file name, and in the next step pick the target folder to exclude (using the Browse Folder… button) and keeping the checkbox for using just the simple filename checked. If you're adding a global rule, it doesn't matter which target folder you pick.
The OK/Apply back out of all the dialogs to apply the change you've made (or maybe add more exclusion rules). You'll need a rebuild so that the rule change is applied correctly, but that's straight-forward.
Folders that are not source folders are not compiled by Eclipse. So you should not have Java error/warning for those.
For source folder, you already have the solution ('Ignore optional compile problems' parameter).

Categories

Resources