NetBeans 12.6、Sping Boot / Maven、Cisco AXL架构-项目的后台扫描

jq6vz3qz  于 2022-11-10  发布在  Maven
关注(0)|答案(1)|浏览(141)

经常与Background scanning of projects相关的人抱怨说,当NetBeans启动时会发生这种情况。
我有一个带有Maven 3.8.2Spring Boot 2.6.x项目,使用Cisco AXL Schema 12.5
Apache CXF从这个AXL 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。如果用sudo ./netbeans启动NetBeans,有什么区别吗?
下面是我的项目文件夹/文件结构的样子,可能我没有正确使用:
首先,我提取了src文件夹旁边的AXL Schema

<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文件中。

cbwuti44

cbwuti441#

我试了这个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文件from here,java ee依赖项)
运行mvn clean install(“清理并生成项目......”使用此wsdl只需不到5秒的时间),并获得以下结果:

..这张漂亮的图片(生成的源文件的分辨率!按提供商(cxf)分组...我们可以有更多)。
结论
Netbeans在“生成的源代码”方面是成熟的。(只要它们在target/generated-sources/<provider>中;).
另一方面,对于“生成的项目”(maven/gradle,例如openapi-plugin),我 * 遇到了(netbeans)问题 *......并且不得不将“生成的东西”(/project!)外部化/“源代码控制”。

不要做的事

  • build>resources>resource>directory>.这会(尝试)将您的项目根目录(额外)封装到target/classes!!(这可能会混淆 * 任何 * IDE。)
  • ...>resource>directory>target,原因与此类似,特别是在Netbeans中。

提示

  • 当我们想让模式和定义驻留在(打包的)类路径中时,我们将它们放在src/main/resources中。否则:外面。
  • 我们把<resources/>添加到<build/>,只有当我们决定这样做/知道我们做什么/不创建“圆”(用现有的maven默认值),而不是“欺骗netbeans”!(这是过时的;)

更新:

  • 我用this wsdlaxl-demo/schema)更新了同一个项目。
  • 它生成了1647个类。
  • Netbeans花了一些时间进行扫描:
  • 我增加记忆:/etc/netbeans.conf文件中指定的文件类型:
netbeans_default_options="-J-Xmx4g ..."

(感谢发送至:How to assign more memory to Netbeans?、...)

  • (重新启动netbeans,)喝咖啡
  • 但随后(一旦扫描完成):仍然是“漂亮的图片”,我们可以导入/声明/使用生成的类:

一些调整

..尤达补充道:

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

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

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

我不同意“推荐的解决方案”!对于“成千上万”的类,*B/很少改变 *,谁愿意清理和重新生成他们“数百”次/天?
它使我们从(mvn -Pgen clean install)加速:

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

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

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

相关问题