Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't NetBeans IDE see the generated sources?

Tags:

I have a Maven-built web-app that uses JPA 2.0 at the back end. The JPA provider is EclipseLink 2.3.2.

When I build the project (and it deploys runs successfully) it builds the JPA meta-model in the directory

${basedir}/target/generated-sources/annotations/

Yet the IDE doesn't see the classes defined there. Little red dots with an exclamation point everywhere. Yet I can navigate to those files in the Projects window and open the generated source files.

Does this happen to anyone else and does anyone know of a way to fix it?

UPDATE:

As a work-around I have discovered that I can exit NetBeans, delete the NetBeans cache directory, then restart. This forces NetBeans to rebuild the cache and then the classes become visible again. Should I submit a bug to the NetBeans bug tracker? I can't come up with a test case to make it happen, but it does fairly often.

like image 395
AlanObject Avatar asked Mar 23 '12 22:03

AlanObject


People also ask

How configure maven settings XML in NetBeans?

Check your Maven settings Maven is bundled with the IDE and installed when you install the IDE. Open the Options window in the IDE (Tools > Options; NetBeans > Preferences on Mac). Select the Java category in the Options window and click the Maven tab. Confirm that a Maven Home is specified.

What is the latest version of NetBeans IDE that is released?

Apache NetBeans 12.0 was released on June 4, 2020. See Apache NetBeans 12.0 Features for a full list of features. Apache NetBeans 12.0 is available for download from your closest Apache mirror.

Is NetBeans free IDE?

NetBeans IDE is a free and open source integrated development environment for application development on Windows, Mac, Linux, and Solaris operating systems.


2 Answers

If you go to project properties/sources there is a note about this: you need to generate sources under

${basedir}/target/generated-sources/FOOBAR 

where FOOBAR is the name of your plugin.

enter image description here

like image 97
jeqo Avatar answered Sep 27 '22 23:09

jeqo


After reading @jeqo answer, I tested if, by manually renaming:

 "${project.build.directory}/generated-sources/annotations" to ".../generated-sources/hibernate-jpamodelgen" 

would make a difference to Nebeans (I'm using v8.2 on ubuntu 16.04).

Everything worked like a charm.

I then modified the pom file as follows:

1) removed the "org.hibernate: hibernate.jpamodelgen" dependency.

2) configured the maven-compiler-plugin as follows:

   <plugin>
    <groupId>>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.1</version>
    <configuration>
      <compilerArgument>-proc:none</compilerArgument>        
    </configuration>
  </plugin>
  • These two steps is to make sure that the hibernate-jpamodelgen does not run on auto-pilot just by adding it in the project dependency list. Please refer to JPA Static MetaModel Generator doc.

3) added the following plugin with configuration

  <plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <version>3.2.0</version>
    <executions>
      <execution>
        <id>process</id>
        <goals>
          <goal>process</goal>
        </goals>
        <phase>generate-sources</phase>
        <configuration>
          <processors>
            <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
          </processors>
          <defaultOutputDirectory>${project.build.directory}/generated-sources/hibernate-jpamodelgen/</defaultOutputDirectory>
        </configuration>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-jpamodelgen</artifactId>
        <version>5.2.9.Final</version>
      </dependency>
    </dependencies>
  </plugin>

This config is directly from the Hibernate JPA Static Metamodel Generator documentation page except for the following line:

<defaultOutputDirectory>${project.build.directory}/generated-sources/hibernate-jpamodelgen/</defaultOutputDirectory>

This line simply generates the metamodel in the directory named after the maven plugin name. From this point, I got all Netbeans references working at design time as if the generated classes were in the src directory subtree.

Hope this helps,

J

like image 36
softjake Avatar answered Sep 27 '22 21:09

softjake