I have successfully run annotation processor for CLASS level retention annotations via command prompt compiling using Java 8.
However, when I tried to configure the annotation processor in eclipse and tried to run it with "-proc:only" option, it didn't get effective.
I have included the Jar file containing the custom annotation processor class file into the Project Properties -> Annotation Processing -> Factory Path. I have also provided the -proc:only option in Project Properties -> Annotation Processing -> Processor Options, still the annotation processor isn't getting called when a class containing my annotation is executed.
Please help me identifying the required setting or mistake or additional step for running the annotation processor via eclipse.
I was finally able to enable my own annotation processor by adding my jar file.
Right click on the project and select Properties.
Open Java Compiler -> Annotation Processing. Check "Enable annotation processing".
Open Java Compiler -> Annotation Processing -> Factory Path. Check "Enable project specific settings". Add your JAR file to the list.
Clean and build the project.
And it finally worked.
It is very much straightforward provided that whatever APT plug in you are trying to use is correctly configured.
Follow the steps mentioned in above post and the reference image to visualize it. Image showing QueryDsl APT configuration for maven project.
While compiling via command prompt or terminal, you can see all the logs in same screen after the compilation command. In eclipse, these logs can be seen at
Window->show view->General->Error Log
If you want the IDE(Eclipse) to point out the warning, error or other diagnostic message exactly at the particular element in the code editor, we have to call the printMessage method of javax.annotation.processing.Messager with 3 arguments as shown below.
messager.printMessage(Kind.ERROR, "Error Message", element);
So i am using the Plugin Eclipse-PMD (http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/) in a shared version control enviroment.
We have multiple smaller projects in the entire project.
Out of the box it seems that this plugin requires individual configuration for every single project.
The way it works it that it searched for a .pmd file in the project and read information from that.
But it's really inconvenient to do that for 10-20 subprojects.
There is a general setting under Preferences -> PMD. But this doesn't seem to apply globally, even if that global checkbox is checked.
What i basically want: I want to configure the plugin to respect a single ruleSet-file in one place.
There is another problem with configuring it subproject-specific: I cannot configure a relative path for the ruleSetFile in the .pmd-file.
The problem with absolute path is that the file is checked into version control ... so with every commit everyone else would have to readjust.
I found this commit: https://github.com/pmd/pmd/pull/36 but i cannot seem to make it work the way it's roughly described.
So, did anyone achieve what i am looking for?
Edit: Actually i cannot even specify any other file that is not ".ruleset" in the .pmd-file as <ruleSetFile> without specifying an absolute path??
The default value for ruleSetFile is ".ruleset". So i thought, analogous to that, i could create a file in the exact same dir, call it fooRules.xml, and specify it via <ruleSetFile>fooRules.xml</ruleSetFile> but it can only find it if put the entire path to fooRules.xml in there?!
Try eclipse-pmd (available in the Eclipse marketplace or via the update site http://www.acanda.ch/eclipse-pmd/release/latest). With eclipse-pmd you can configure your projects to use a single rule set file for several projects. It also stores its path relative to the workspace. You still have to configure each project individually though (for now, this will change in a future release).
To set up eclipse-pmd in the way you described you have to open the project properties of your first project, select the "PMD" property page and add the rule set. Select the rule set type "Workspace" and pick your rule set file.
For every other project you have to open the project's PMD property page where you'll find the previously selected rule set file which simply needs to be checked to activate.
If you set it up this way there will be a .eclipse-pmd file in each project containing the settings. If you check this into your version control system then no one else in your team has to set up anything (apart from installing eclipse-pmd).
Disclaimer: I wrote eclipse-pmd. Mostly because I had the exact same problems as you with the other plugin.
I've been struggling a long time to get this working with PMD for Eclipse. While Eclipse-PMD has this feature built-in, I had some other issues with it (e.g. I think it is not meant to create reports).
The trick was adding the rules to the project as a link.
Create the rule file, e.g. pmd.xml, in the parent folder of the project. Add the file to the projects to be checked, but add it as a reference. Therefore, drag the file from the explorer to the bundle and select:
In the project properties, in the PMD section, check Enable PMD and Apply and Close the settings.
Now close Eclipse. Edit the file with the name .pmd in the project folder by replacing the content with the following:
<?xml version="1.0" encoding="UTF-8"?>
<pmd>
<useProjectRuleSet>true</useProjectRuleSet>
<ruleSetFile>pmd.xml</ruleSetFile>
<includeDerivedFiles>false</includeDerivedFiles>
<violationsAsErrors>true</violationsAsErrors>
<fullBuildEnabled>true</fullBuildEnabled>
</pmd>
Restart Eclipse and right click the project. Select PMD/Check Code. Now, only the violations defined in pmd.xml should be reported.
Configuring PMD only using the GUI does not seem to work for me.
Here is the code:
package mscontroller;
import javax.swing.*;
import com.apple.eawt.Application;
public class Main {
public static void main(String[] args)
{
Application app = new Application();
app.setEnabledAboutMenu(true);
AMEListener listener = new AMEListener();
app.addApplicationListener(listener);
JFrame mainFrame = new JFrame("Application Menu Example");
mainFrame.setSize(500, 500);
mainFrame.setVisible(true);
}
}
here is the error:
Exception in thread "main" java.lang.Error: Unresolved compilation
problems: Access restriction: The type 'Application' is not API
(restriction on required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
Access restriction: The constructor 'Application()' is not API
(restriction on required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
Access restriction: The type 'Application' is not API (restriction on
required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
Access restriction: The method
'Application.setEnabledAboutMenu(boolean)' is not API (restriction on
required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
AMEListener cannot be resolved to a type AMEListener cannot be
resolved to a type
at mscontroller.Main.main(Main.java:9)
eclipse says this:
Access restriction: The type 'Application' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
This happened to me as well, and the answers given here already were not satisfying, so I did my own research.
Background: Eclipse access restrictions
Eclipse has a mechanism called access restrictions to prevent you from accidentally using classes which Eclipse thinks are not part of the public API. Usually, Eclipse is right about that, in both senses: We usually do not want to use something which is not part of the public API. And Eclipse is usually right about what is and what isn't part of the public API.
Problem
Now, there can be situations, where you want to use public Non-API, like sun.misc (you shouldn't, unless you know what you're doing). And there can be situations, where Eclipse is not really right (that's what happened to me, I just wanted to use javax.smartcardio). In that case, we get this error in Eclipse.
Solution
The solution is to change the access restrictions.
Go to the properties of your Java project,
i.e. by selecting "Properties" from the context menu of the project in the "Package Explorer".
Go to "Java Build Path", tab "Libraries".
Expand the library entry
select
"Access rules",
"Edit..." and
"Add..." a "Resolution: Accessible" with a corresponding rule pattern.
For me that was "javax/smartcardio/**", for you it might instead be "com/apple/eawt/**".
I was having the same problem. When I initially created the java project in Eclipse I specified JRE 8. When I went into the project's build path and edited the JRE System Library, the Java 8 execution environment was selected. When I chose to use an "Alernate JRE" (still java 8) it fixed the error for me.
Adding javafx accessible permission in eclipse oxygen
go to project> properties> java build path> libraries> then expand the libraries and double click on> Access rules there you set the permission
Resolution : Accessible
Rule Pattern : javafx/**
To begin with (and unrelated), instantiating the Application class by yourself does not seem to be its intended use. From what one can read from its source, you are rather expected to use the static instance returned by getApplication().
Now let's get to the error Eclipse reports. I've ran into a similar issue recently: Access restriction: The method ... is not API (restriction on required project). I called the method in question as a method of an object which inherited that method from a super class. All I had to do was to add the package the super class was in to the packages imported by my plugin.
However, there is a lot of different causes for errors based on "restriction on required project/library". Similar to the problem described above, the type you are using might have dependencies to packages that are not exported by the library or might not be exported itself. In that case you can try to track down the missing packages and export them my yourself, as suggested here, or try Access Rules. Other possible scenarios include:
Eclipse wants to keep you from using available packages that are not part of the public Java API (solution 1, 2)
Dependencies are satisfied by multiple sources, versions are conflicting etc. (solution 1, 2, 3)
Eclipse is using a JRE where a JDK is necessary (which might be the case here, from what your errors say; solution) or JRE/JDK version in project build path is not the right one
This ended up as more like a medley of restriction-related issues than an actual answer. But since restriction on required projects is such a versatile error to be reported, the perfect recipe is probably still to be found.
We had to change our application to build against the JDK 1.8 using Window->Preferences->Java->Installed JREs. However, after changing that, the JRE System Library specified in the Project Explorer was still incorrect. To fix this, right click on "JRE System Library [wrong-jre-here]" and change from Execution environment: to "Workspace Default (yer-default-here)"
I had this problem because the project facet associated with my project was the wrong java version.
To fix this is I did the following:
Right click on the project and select Properties
Select 'Project Facets' and change version of java to something greater than 1.4.
Click [Apply]
This will rebuild your project and hopefully the error will be resolved.
It worked: Project Properties -> ProjectFacets -> Runtimes -> jdk1.8.0_45 -> Apply
In the Eclipse top menu bar:
Windows -> Preferences -> Java -> Compiler -> Errors/Warnings ->
Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning
If you're having this same issue using Spring Tool Suite:
The Spring Tool Suite's underlying IDE is, in fact, Eclipse. I've gotten this error just now trying to use some com.sun.net classes. To remove these errors and prevent them from popping up in the Eclipse Luna SR1 (4.4.2) platform of STS:
Navigate to Project > Properties
Expand the Java Compiler heading
Click on Errors/Warnings
Expand deprecated and restricted API
Next to "Forbidden reference (access rules)" select "ignore"
Next to "Discouraged reference (access rules)" select "ignore"
You're good to go.
Had the same problem. Here's how I solved it:
Go to Package Explorer. Right click on JRE System Library and go to Properties. In the Classpath Container > Select JRE for the project build path select the third option (Workspace default JRE).
Source : https://thenewboston.com/forum/topic.php?id=3917
We use IBM Rational Application Developer (RAD) and had the same problem.
ErrorMessage:
Access restriction: The type 'JAXWSProperties' is not API (restriction on required library 'C:\IBM\RAD95\jdk\jre\lib\rt.jar')
Solution:
go to java build path and under Library tab, remove JRE System Library. Then again Add Library --> JRE System Library
Go to the following setting:
Window -> Preferences -> Java-Compiler-Errors/Warnings-Deprecated and restricted API-Forbidden reference (access rules)
Set it to Warning or Ignore.
In Eclipse Mars.2 Release (4.5.2):
Project Explorer -> Context menu -> Properties -> JavaBuildPath -> Libraries
select JRE... and press Edit: Switch to Workspace JRE (jdk1.8.0_77)
Works for me.
Even if its old question, for me in Eclipse I just right click on Src folder and properties (Alt+Enter) and the check for the Ignore optional compile problems removed the error.
I have eclipse JRE 8.112 , not sure if that matters but what i did was this:
Right clicked on my projects folder
went down to properties and clicked
clicked on the java build path folder
once inside, I was in the order and export
I checked the JRE System Library [jre1.8.0_112]
then moved it up above the one other JRE system library there (not sure if this mattered)
then pressed ok
This solved my problem.
I simply just add e(fx)clipse in eclipse marketplace. Easy and simple
Remove Existing/Configured System Library:
Eclipse(IDE) -> Project Explorer -> Project Name-> (Option) Build Path -> Configure Build Path -> Java Build Path -> Libraries -> (Select) JRE System Library [(For me)jre1.8.0_231] -> Remove.
Currently you are at same location:
Eclipse(IDE) -> Project Explorer -> Project Name-> (Option) Build Path -> Configure Build Path -> Java Build Path -> Libraries
Now Add Same System Library Again:
Add Library -> JRE System Library -> Workspace default JRE ((For me)jre1.8.0_231) -> Finish -> Apply -> Close.
Now wait to finish it.
I'm using eclipse neon 3. I just wanted to use javafx.application.Application, so I followed Christian Hujer's answer above and it worked. Just some tips: the access rules are very similar to the import statement. For me, the access rules I added was "javafx/application/**". Just replace the dot in the import statement with forward slash and that's the rule. Hope that helps.
I had a little different problem. In Project - Properties - Libraries - JRE library, I had the wrong JRE lib version. Remove and set the actual one, and voila - all Access restriction... warnings are away.
If someone is having this issue only in your CI tool while running maven, what did the trick for me was to explicitly define the execution environment in your MANIFEST.MF.
In my case, I did this by inserting the following line in my OSGi bundle manifest file:
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
What worked for me was adding the access restricted package to the MANIFEST.MF file. In Eclipse, the "Access Restricted" errors showed up in the Problems tab for several files. I just right clicked on each error, clicked "Quick Fix", and chose "Add '[package]' to imported packages".
I had faced the same error on Eclipse 4.20.0 with JRE 1.8. To get rid of this compilation error, do the following:
Project --> Properties --> Java Compiler --> Errors/Warnings --> Deprecated and Restricted API --> Forbidden Reference (access rules) --> ignore
Is there a way to set System Properties which are used for every JVM that is started by NetBeans (NB 7.3.1 on Win 7)?
In all my maven projects I use Log4j wich needs a log4j.properties file, to where I want to point to by a System Property -Dlog4j.configuration=file:/c:/log4j/log4j.properties
I could set Global Execution Options for Maven: Tools > Options > Java > Maven > Global Execution Options. But then when I run a particular JUnit test class in NetBeans (thus without Maven), NetBeans won't use these JVM System Properties set in the Global Execution Options field.
Same issue is when a Main class in a Maven module is run in NetBeans. To set JVM System Properties there are Project Properties which could be set: 'Main Class' and 'VM Options'. But these Project Properties are only used by NetBeans when the 'Run' command is used from the context menu of the maven module. (Unfortunaly this menu item doesn't have a shortcut key (normaly Shift-F6)).
I have worked around this by setting a System Variable JAVA_TOOL_OPTIONS=-Dlog4j.configuration=file:/c:/log4j/log4j.properties.
Edit
A question was asked for the same problem I ran in to: How to make Netbeans use specific JVM parameters when running tests? In my case the problem was caused by the option Compile on Save which I had swiched on (File > Project Properties > Build > Compile > Compile On Save). In that case it seems that NetBeans doesn't use Maven. For further info about CoS: http://wiki.netbeans.org/FaqCompileOnSave
There's a file called project.properties in the nbproject folder. In this file there is a lot of configurations you can do that are not in the GUI menus. I don't know exactly what to put there to achieve what you want, but I found this on one of my NetBeans projects config:
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
I have a problem. I always get an Error 206 from Java DataNucleus Enhancer, since 2 days ago... days before, it worked without errors.
Cannot run program "D:\Program Files\Java\jre6\bin\javaw.exe" (in
directory "C:\Users\schmisa2\workspace\AMS0"): CreateProcess
error=206, The filename or extension is too long Cannot run program
"D:\Program Files\Java\jre6\bin\javaw.exe" (in directory
"C:\Users\schmisa2\workspace\AMS0"): CreateProcess error=206, The
filename or extension is too long
I searched a lot at Google and Stackoverflow but could not solve the problem.
My longest path is:
C:\Users\schmisa2\workspace\AMS0\src\ch\zhaw\ams\module\football\sfv\news\server\NewsElement.java
https://groups.google.com/group/google-appengine-java/browse_thread/thread/6cde7d1695b3eff3
Does somebody know how I can fix it?
I installed a Linux Ubuntu to test it there. There it was no problem... but it doesn't work on Windows 7.
I have GWT 2.4, App engine 1.6.5. SDK and Eclipse 3.7
Or can someone explain me how to run it on command line?
This worked for me.
"If you're using eclipse plugin go to Project | Properties, choose
Google \ App Engine \ ORM and only include directories that you have
classes that you want enhanced. By default it does the entire project
so that includes a lot of needless files."
Source here
I have a project which I was using DataNucleus, JDO and Annotations. I ran into the same issue on Windows with Eclipse (It was fine on my Mac). To fix, I did the following:
Created a .jdo file for each #PersistenceCapable class (see example JDO file below) and kept them alongside the class files.
Right-click project -> Preferences -> DataNucleus -> Enhancer -> Input File Extensions. Remove the "class" entry here.
Do the same as above for the SchemaTool configuration if this is also required for your project.
This should now work.
JDO file example:
<?xml version="1.0" encoding="UTF-8"?>
<jdo>
<package name="my.package">
<class name="MyPersistenceCapableClass"/>
</package>
</jdo>
So you hit Windows antiquated limits on command line length. Change the invocation of the enhancer to use a persistence.xml for example.
Another way you can fix this issue or workaround it I should say in Eclipse is to create a new run configuration in eclipse copying the parameters from the datanucleus one which is created by the plugin Run Configurations -> Java Application -> DataNucleus Enhancer. Copy Main tab, Arguments, and you might need to add the Datanucleus jars to the classpath tab.
In the arguments tab, remove all the classes you don't need enhanced. Next I'll shut off the plugin by removing the classes extension under the projects Properties -> DataNucleus -> Enhancer -> Input File Extensions.
You'll just need to manually run this enhancer after each time you build now. If I need to add new classes to enhance, I'll just add it to my manual one.