Home > Enterprise >  NetBeans 12.6, Spring Boot / Maven, Cisco AXL Schema - Background scanning of projects
NetBeans 12.6, Spring Boot / Maven, Cisco AXL Schema - Background scanning of projects

Time:12-22

Often related to Background scanning of projects people complain that this happens when NetBeans is started.

I have a Spring Boot 2.6.x with Maven 3.8.2 project, using Cisco AXL Schema 12.5.

With Apache CXF from this AXL Schema a lot of Java source code files are generated.

When I do a Clean and Build on my project afterwards immediatly the Background scanning of projects starts.

And it takes most of the times recently quite long.

I see for example that it scans also

netbeans-12.6/webcommon/jsstubs/corestubs.zip

Why should it scan this too when building my project?

But most of the time, although it shows 100% scanning done, it spends in the folder where the generated Java source code files are

<project folder>/target/generated/cxf

There are 2282 generated Java source code files.

I'm not sure if NetBeans hangs or really scans these files, it shows 100% scanning so it should be done.

Often it takes too long so I have to terminate NetBeans from the console. After a restart of NetBeans the Background scanning for projects starts and takes much shorter time, but this is annoying.

What can I do about it?

When I start NetBeans from console I do only ./netbeans. Is there a difference if starting NetBeans with sudo ./netbeans?

Here is how my project folder/file structure looks like, maybe I don't use correctly:

First of all I extracted the AXL Schema next to my src folder

<project folder>
-> schema
   -> 12.5
      AXLAPI.wsdl
      AXLEnums.xsd
      AXLSoap.xsd
-> src
   -> main/...
   -> test/...

In pom.xml I use

...
<build>
...
<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>3.4.5</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${basedir}/schema/12.5/AXLAPI.wsdl</wsdl>
                        <wsdlLocation>classpath:schema/12.5/AXLAPI.wsdl</wsdlLocation>
                        <extraargs></extraargs>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>
...
<resources>
...
    <resource>
        <directory>./</directory>
        <includes>
            <include>schema/**</include>
        </includes>
    </resource>  
    <resource>
        <directory>target/generated/cxf</directory>
        <includes>
            <include>**/*.java</include>
        </includes>
    </resource>
...
</resources>
</build>
...

Maybe this pom.xml setup is not correct, and that's why the Background scanning for projects works wrongly.

When I look into the resulting war file after build, I see

WEB-INF
-> classes
   -> com/cisco/axl/api/_12
   -> schema/12.5

and there are artifacts which might not belong there.

For example in com/cisco/axl/api/_12 there are not only the class files but all related generated Java source code files (all 2282).

And perhap schema/12.5 shouldn't be in the war file too.

CodePudding user response:

I tried this pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>cxf</artifactId>
  <version>1.0-SNAPSHOT</version>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>3.4.5</version>
        <executions>
          <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
              <wsdlOptions>
                <wsdlOption>
                  <wsdl>src/main/resources/wsdl/CustomerService.wsdl</wsdl>
                </wsdlOption>
              </wsdlOptions>
            </configuration>
            <goals>
              <goal>wsdl2java</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
    </dependency>
  </dependencies>
</project>

(Latest nice picture

..this nice picture (resolution of generated sources! grouped by provider (cxf)...we could have more).

Conclusion

Netbeans is mature regarding "generated sources". (As long as they are in target/generated-sources/<provider>;).

With "generated projects" (maven/gradle e.g. bigger project, no problems screenshot


Some Tweaks

..Yoda added to the build:

  • moved cxf-execution to profile:

    <profiles>
      <profile>
        <id>gen</id>
        <build>
          <plugins>
            <plugin>
              <groupId>org.apache.cxf</groupId>
              <artifactId>cxf-codegen-plugin</artifactId>
              ...
    

    to activate it (only) with mvn install -Pgen (or in netbeans (Project>Properties>Run>) Configuration(drop-down)).

  • applied this: How to protect auto-generated sources during clean package in maven? like:

    <build>
       <plugins>
         <plugin>
           <artifactId>maven-clean-plugin</artifactId>
           <version>3.1.0</version>
           <configuration>
             <excludeDefaultDirectories>true</excludeDefaultDirectories>
             <filesets>
               <fileset>
                 <directory>${project.build.directory}</directory>
                 <excludes>
                   <exclude>generated-sources/**</exclude>
                   <exclude>classes/com/cisco/**</exclude>
                 </excludes>
               </fileset>
             </filesets>
           </configuration>
         </plugin>
       </plugins>
    </build>
    

    I don't agree with "recommended solution"! For "thousands of" classes that b/rarely change, who wants to clean & re-generate them "hundreds" times/day?

Which accelerates us from (mvn -Pgen clean install):

------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time:  44.515 s

To "Project>Clean and Build" (mvn clean install):

------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time:  4.494 s
  • Related