2

经常有相关的Background scanning of projects人抱怨这种情况在NetBeans开始的时候会发生。

我有一个项目,Spring Boot 2.6.x使用.Maven 3.8.2Cisco AXL Schema 12.5

由此生成Apache CXFAXL Schema大量的Java源代码文件。

当我Clean and Build在我的项目之后立即Background scanning of projects开始时。

而且最近大部分时间都需要很长时间。

例如,我看到它也扫描

netbeans-12.6/webcommon/jsstubs/corestubs.zip

为什么在构建我的项目时也要扫描它?

但大多数时候,虽然它显示 100% 扫描完成,但它花费在生成的 Java 源代码文件所在的文件夹中

<project folder>/target/generated/cxf

有 2282 个生成的 Java 源代码文件。

我不确定是否NetBeans挂起或真正扫描这些文件,它显示 100% 扫描,所以应该完成。

通常它需要太长时间,所以我必须NetBeans从控制台终止。重新启动后NetBeans开始Background scanning for projects并需要更短的时间,但这很烦人。

我能做些什么呢?

当我NetBeans从控制台开始时,我只做./netbeans. 如果从 开始有区别NetBeanssudo ./netbeans

这是我的项目文件夹/文件结构的样子,也许我没有正确使用:

首先,我提取了我的文件夹AXL Schema旁边的src

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

pom.xml我使用

...
<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>
...

也许这个pom.xml设置不正确,这就是Background scanning for projects工作错误的原因。

war当我在构建后查看生成的文件时,我看到

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

并且有些文物可能不属于那里。

例如,com/cisco/axl/api/_12不仅有class文件,还有所有相关的生成Java源代码文件(全部 2282)。

也许schema/12.5也不应该在war文件中。

4

1 回答 1

0

我试过这个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>

(最新的 cxf-codegen-plugin ,没有额外的配置,来自这里的wsdl 文件,java ee 依赖项)

运行mvn clean install(“清理和构建项目”......使用这个 wsdl 不到 5 秒),并得到我们:

漂亮的图片

..这张漂亮的图片(生成源的分辨率!按提供者(cxf)分组......我们可以有更多)。

结论

Netbeans 在“生成的资源”方面是成熟的。(只要他们在target/generated-sources/<provider>;)。

另一方面,使用“生成的项目”(maven/gradle 例如openapi-plugin ),我遇到了(netbeans)问题......并且不得不将“生成的东西”(/project!)外部化/“源代码控制”。


不要做

  • build>resources>resource>directory>.这将(尝试)将您的项目根(另外)打包到目标/类!(这可能会混淆任何IDE。)
  • ...>resource>directory>target,出于类似的原因,尤其是。在 Netbeans 中。

提示

  • 当我们希望模式和定义驻留在(打包的)类路径中时,我们将它们放在src/main/resources. 否则:在外面。

  • 我们添加<resources/>到我们的<build/>,只有当我们决定/知道我们做什么/不创建“圈子”(使用现有的 maven-defaults),而不是“欺骗 netbeans”!(这已经过时了;)


更新:

  • 我用这个 wsdl ( )更新了同一个项目axl-demo/schema
  • 它生成了 1647 个类。
  • Netbeans 扫描了一段时间:
  • 但是然后(一旦扫描完成):仍然“漂亮的图片”,我们可以导入/声明/使用生成的类:

更大的项目,没问题截图


一些调整

.. Yoda添加到构建中:

  • 将 cxf-execution 移至配置文件

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

    (仅)使用mvn install -Pgen(或在netbeans(项目>属性>运行>)配置(下拉)中激活它。

  • 应用了这个:如何在 Maven 中的清洁包期间保护自动生成的源?像:

    <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>
    

    我不同意“推荐的解决方案”!对于“数以千计”很少改变的类,谁愿意每天“数百”次清理和重新生成它们?

从 ( ) 加速我们mvn -Pgen clean install

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

到“项目>清理和构建”(mvn clean install):

------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time:  4.494 s
于 2021-12-20T15:07:16.950 回答