2

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.

neblaz
  • 683
  • 10
  • 32
  • `target/generated/cxf` has "flavors"! what are you trying to achieve? (with this...browse the generated sources in project explorer!? ..please try the defaults (cxf-output-folder...) – xerx593 Dec 20 '21 at 13:59
  • `./` also not as designed/not good for netbeans – xerx593 Dec 20 '21 at 14:04
  • NetBeans complained that it couldn't find the generated Java source files, so I solved it with the target/generated/cxf.... After I added this to pom.xml no errors in NetBeans. – neblaz Dec 20 '21 at 14:07
  • Could you please provide an answer with some code snippet for the pom.xml, I'm not sure how to change it. Firstly the AXL Java source code files have to be generated, for this the was specified, and the folder where those are generated is ${project.build.directory}/generated/cxf. But when I tried to use one of the generated Java source code files, for example RPhone.java, NetBeans didn't know about it. – neblaz Dec 20 '21 at 14:12

1 Answers1

0

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 cxf-codegen-plugin, no additional config, wsdl file from here, java ee dependencies)

Running mvn clean install ("Clean and Build Project"...takes less than 5 seconds with this wsdl), and gets us:

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. openapi-plugin) on the other hand, I experienced (netbeans) issues...and had to externalize/"source control" the "generated stuff" (/project!).


Don'ts

  • build>resources>resource>directory>. This will(try to) package your project root (additionally) to target/classes!! (This may confuse any IDE.)
  • ...>resource>directory>target, for similar reasons esp. in Netbeans.

Hints

  • When we want the schemas & definitons to reside in (packaged) class path, we place them within src/main/resources. Otherwise: outside.

  • We add <resources/> to our <build/>, only when we decided so/know what we do/don't create "circles" (with existing maven-defaults), notto "trick netbeans"! (this is out-dated;)


Update:

  • I updated same project with this wsdl (axl-demo/schema).
  • It generated 1647 classes.
  • Netbeans took a while to scan:
  • But then (once scan was completed): Still "nice picture", we can import/declare/use the generated classes:

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
xerx593
  • 12,237
  • 5
  • 33
  • 64
  • Cool!?? Just give me a more complex wsdl! :):) – xerx593 Dec 20 '21 at 15:31
  • 1
    I created back then this thread and answer my qestion myself: https://stackoverflow.com/questions/63297393/spring-boot-project-maven-with-axl-netbeans-cannot-find-generated-axl-packag But didn't recognize at that time the drawbacks. I wil give you a linkt to the WSDL, which is more complex, as soon as possible. I don't build it via command line with mvn. – neblaz Dec 20 '21 at 19:31
  • You might try this https://pubhub.devnetcloud.com/media/axl/docs/java-jax-ws-quickstart/assets/axl-demo.zip It is up to 8.5, but should suffice. Extract it, copy the 'schema' folder into your Spring Boot with Maven project (might generate one from start.spring.io). You might remove everythiing else within the schema folder but leave just the '8.5' folder), and try to generate the AXL Java source code files, and try to use those within you project, like RLine.java or so. – neblaz Dec 20 '21 at 20:15
  • found it already! ;) (v8!;) – xerx593 Dec 20 '21 at 20:20
  • ..now my netbeans also stunnning :):) ~1500 classes: it took some time to scan, i could not cancel + had exception – xerx593 Dec 20 '21 at 20:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/240292/discussion-between-xerx593-and-neblaz). – xerx593 Dec 20 '21 at 20:23
  • I tried your Hint, and have an improvement so far in regards that my war file is much cleaner now, no generated AXL Java source code files and no AXL schema folder in there. BUT still I cannot mark your answer as correct, because the main problem here is the Background scanning for project time. The build time (with generating the AXL Java source code files) is about 38 sec, but that is not the problem. – neblaz Dec 21 '21 at 09:01
  • Also, the maven-clean-plugin (according to the link it is not recommended), prevents generating the AXL Java source code files each time, OK, but stil after the Clean and Build it scans them. – neblaz Dec 21 '21 at 09:18
  • 1
    Maybe for this particular project, with so many generated Java source files it might be a solution, to only once generate the AXL Java source code files, put them into a package in the project structure (for example src/main/java/myprojcect/cisco/...) and comment out the CXF plugin in the pom.xml, so when Clean and Build is done, no generation happens, and no large amount of generated files are scanned. – neblaz Dec 21 '21 at 10:38
  • yeah..the scanning is a problem... but only 1 time! ...the axl wsdl (version 12) will never ever change! "Not recommended": By Whom for what reasons!? ;) I *recommend* (now) opposite! (for the mentioned reasons) – xerx593 Dec 21 '21 at 13:37
  • clean& build costs me now (with >1k classes): 5 seconds, no scanning takes place after that. netbeans startup: <10 seconds. – xerx593 Dec 21 '21 at 13:40
  • With my "solution": after clean build, netbeans has to scan your (main) classes, but not the generated ones! – xerx593 Dec 21 '21 at 13:45
  • yes, your approach in "the maven way": put it (the wsdl + cxf-plugin) into a separate module/project/pom!(with identifying group:artifact:version...) "check it in", build release deploy...and in your "main project" just: `that-lib` – xerx593 Dec 21 '21 at 14:44