Maven将生成的文件夹(使用Maven插件)添加为源文件夹,IntelliJ无法识别 - java

在我的maven Web项目中,cxf-codegen-plugin生成JAVA类并将其放入文件夹中

 ${basedir}/src/generated

我在Java类中使用这些生成的类,

src/main/java

我正在使用IntelliJ IDE,并且IntelliJ似乎无法识别

${basedir}/src/generated

作为源文件夹(是正确的)。

我的问题是如何使Maven和IntelliJ都将生成的文件夹重新识别为源文件夹。

我的项目结构是

    .
    ├── HOWTO.txt
    ├── pom.xml
    ├── src
    │   ├── generated
    │   │   └── com
    │   │       └── bharath
    │   │           └── ws
    │   │               └── trainings
    │   │                   ├── CreateOrdersRequest.java
    │   │                   ├── CreateOrdersResponse.java
    │   │                   ├── CustomerOrdersPortType.java
    │   │                   ├── CustomerOrdersService.java
    │   │                   ├── GetOrdersRequest.java
    │   │                   ├── GetOrdersResponse.java
    │   │                   ├── ObjectFactory.java
    │   │                   ├── Order.java
    │   │                   ├── Product.java
    │   │                   └── package-info.java
    │   ├── main
    │   │   ├── java
    │   │   │   └── com
    │   │   │       └── bharath
    │   │   │           └── ws
    │   │   │               └── trainings
    │   │   │                   └── impl
    │   │   │                       └── CustomersOrdersWSImpl.java
    │   │   └── webapp
    │   │       ├── WEB-INF
    │   │       │   ├── cxf-servlet.xml
    │   │       │   ├── web.xml
    │   │       │   └── wsdl
    │   │       │       └── CustomerOrders.wsdl
    │   │       └── index.jsp
    │   └── test
    │       └── java
    ├── target
    │   ├── classes
    │   │   └── com
    │   │       └── bharath
    │   │           └── ws
    │   │               └── trainings
    │   │                   ├── CreateOrdersRequest.class
    │   │                   ├── CreateOrdersResponse.class
    │   │                   ├── CustomerOrdersPortType.class
    │   │                   ├── CustomerOrdersService.class
    │   │                   ├── GetOrdersRequest.class
    │   │                   ├── GetOrdersResponse.class
    │   │                   ├── ObjectFactory.class
    │   │                   ├── Order.class
    │   │                   ├── Product.class
    │   │                   ├── impl
    │   │                   │   └── CustomersOrdersWSImpl.class
    │   │                   └── package-info.class
    │   ├── cxf-codegen-plugin-markers
    │   ├── generated-sources
    │   │   └── annotations
    │   ├── maven-archiver
    │   │   └── pom.properties
    │   ├── maven-status
    │   │   └── maven-compiler-plugin
    │   │       ├── compile
    │   │       │   └── default-compile
    │   │       │       ├── createdFiles.lst
    │   │       │       └── inputFiles.lst
    │   │       └── testCompile
    │   │           └── default-testCompile
    │   │               └── inputFiles.lst
    │   ├── surefire
    │   ├── wsdlfirstws
    │   │   ├── META-INF
    │   │   ├── WEB-INF
    │   │   │   ├── classes
    │   │   │   │   └── com
    │   │   │   │       └── bharath
    │   │   │   │           └── ws
    │   │   │   │               └── trainings
    │   │   │   │                   ├── CreateOrdersRequest.class
    │   │   │   │                   ├── CreateOrdersResponse.class
    │   │   │   │                   ├── CustomerOrdersPortType.class
    │   │   │   │                   ├── CustomerOrdersService.class
    │   │   │   │                   ├── GetOrdersRequest.class
    │   │   │   │                   ├── GetOrdersResponse.class
    │   │   │   │                   ├── ObjectFactory.class
    │   │   │   │                   ├── Order.class
    │   │   │   │                   ├── Product.class
    │   │   │   │                   ├── impl
    │   │   │   │                   │   └── CustomersOrdersWSImpl.class
    │   │   │   │                   └── package-info.class
    │   │   │   ├── cxf-servlet.xml
    │   │   │   ├── lib
    │   │   │   │   ├── aopalliance-1.0.jar
    │   │   │   │   ├── asm-3.3.1.jar
    │   │   │   │   ├── commons-codec-1.2.jar
    │   │   │   │   ├── commons-httpclient-3.1.jar
    │   │   │   │   ├── commons-logging-1.1.1.jar
    │   │   │   │   ├── cxf-core-3.0.2.jar
    │   │   │   │   ├── cxf-rt-bindings-soap-3.0.2.jar
    │   │   │   │   ├── cxf-rt-bindings-xml-3.0.2.jar
    │   │   │   │   ├── cxf-rt-databinding-jaxb-3.0.2.jar
    │   │   │   │   ├── cxf-rt-frontend-jaxws-3.0.2.jar
    │   │   │   │   ├── cxf-rt-frontend-simple-3.0.2.jar
    │   │   │   │   ├── cxf-rt-security-3.0.2.jar
    │   │   │   │   ├── cxf-rt-transports-http-3.0.2.jar
    │   │   │   │   ├── cxf-rt-transports-http-jetty-3.0.2.jar
    │   │   │   │   ├── cxf-rt-ws-addr-3.0.2.jar
    │   │   │   │   ├── cxf-rt-ws-policy-3.0.2.jar
    │   │   │   │   ├── cxf-rt-ws-security-3.0.2.jar
    │   │   │   │   ├── cxf-rt-wsdl-3.0.2.jar
    │   │   │   │   ├── ehcache-2.8.3.jar
    │   │   │   │   ├── geronimo-javamail_1.4_spec-1.7.1.jar
    │   │   │   │   ├── geronimo-servlet_3.0_spec-1.0.jar
    │   │   │   │   ├── jasypt-1.9.2.jar
    │   │   │   │   ├── jaxb-core-2.2.10-b140310.1920.jar
    │   │   │   │   ├── jaxb-impl-2.2.10-b140310.1920.jar
    │   │   │   │   ├── jetty-continuation-8.1.15.v20140411.jar
    │   │   │   │   ├── jetty-http-8.1.15.v20140411.jar
    │   │   │   │   ├── jetty-io-8.1.15.v20140411.jar
    │   │   │   │   ├── jetty-security-8.1.15.v20140411.jar
    │   │   │   │   ├── jetty-server-8.1.15.v20140411.jar
    │   │   │   │   ├── jetty-util-8.1.15.v20140411.jar
    │   │   │   │   ├── joda-time-2.2.jar
    │   │   │   │   ├── neethi-3.0.3.jar
    │   │   │   │   ├── opensaml-2.6.1.jar
    │   │   │   │   ├── openws-1.5.1.jar
    │   │   │   │   ├── slf4j-api-1.7.7.jar
    │   │   │   │   ├── spring-aop-3.2.0.RELEASE.jar
    │   │   │   │   ├── spring-beans-3.2.0.RELEASE.jar
    │   │   │   │   ├── spring-context-3.2.0.RELEASE.jar
    │   │   │   │   ├── spring-core-3.2.0.RELEASE.jar
    │   │   │   │   ├── spring-expression-3.2.0.RELEASE.jar
    │   │   │   │   ├── spring-jdbc-3.2.0.RELEASE.jar
    │   │   │   │   ├── spring-orm-3.2.0.RELEASE.jar
    │   │   │   │   ├── spring-tx-3.2.0.RELEASE.jar
    │   │   │   │   ├── spring-web-3.2.0.RELEASE.jar
    │   │   │   │   ├── spring-webmvc-3.2.0.RELEASE.jar
    │   │   │   │   ├── stax2-api-3.1.4.jar
    │   │   │   │   ├── woodstox-core-asl-4.4.1.jar
    │   │   │   │   ├── wsdl4j-1.6.3.jar
    │   │   │   │   ├── wss4j-bindings-2.0.2.jar
    │   │   │   │   ├── wss4j-policy-2.0.2.jar
    │   │   │   │   ├── wss4j-ws-security-common-2.0.2.jar
    │   │   │   │   ├── wss4j-ws-security-dom-2.0.2.jar
    │   │   │   │   ├── wss4j-ws-security-policy-stax-2.0.2.jar
    │   │   │   │   ├── wss4j-ws-security-stax-2.0.2.jar
    │   │   │   │   ├── xml-resolver-1.2.jar
    │   │   │   │   ├── xmlschema-core-2.1.0.jar
    │   │   │   │   ├── xmlsec-2.0.2.jar
    │   │   │   │   └── xmltooling-1.4.1.jar
    │   │   │   ├── web.xml
    │   │   │   └── wsdl
    │   │   │       └── CustomerOrders.wsdl
    │   │   └── index.jsp
    │   └── wsdlfirstws.war
    └── wsdlfirstws.iml

我还基于其他建议的SO答案添加了插件build-helper-maven-plugin(以添加另一个源文件夹),但是在mvn全新安装后,它似乎不起作用(至少IntelliJ无法识别它们)。

    <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>${cxf.version}</version>
        <executions>
            <execution>
                <id>generate-sources</id>
                <phase>generate-sources</phase>
                <configuration>
                    <sourceRoot>${basedir}/src/generated</sourceRoot>
                    <wsdlOptions>
                        <wsdlOption>
                            <wsdl>${basedir}/src/main/webapp/WEB-INF/wsdl/CustomerOrders.wsdl</wsdl>
                        </wsdlOption>
                    </wsdlOptions>
                </configuration>
                <goals>
                    <goal>wsdl2java</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.7</version>
        <executions>
            <execution>
                <id>add-source</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>add-source</goal>
                </goals>
                <configuration>
                    <sources>
                        <source>${basedir}/src/generated</source>
                    </sources>
                </configuration>
            </execution>
        </executions>
    </plugin>

参考方案

由于它是“非标准”路径,因此intellij不会自动将其拾取,但是您可以像下面这样轻松地对其进行修复:

右键单击文件夹(在您的情况下为src\generated),然后选择:

Mark Directory As-> Generated Source Root

您应该看到它变成蓝色,并且下面的所有包(com ...等)应该都被识别为Java代码。

JAVA:字节码和二进制有什么区别? - java

java字节代码(已编译的语言,也称为目标代码)与机器代码(当前计算机的本机代码)之间有什么区别?我读过一些书,他们将字节码称为二进制指令,但我不知道为什么。 参考方案 字节码是独立于平台的,在Windows中运行的编译器编译的字节码仍将在linux / unix / mac中运行。机器代码是特定于平台的,如果在Windows x86中编译,则它将仅在Win…

java:继承 - java

有哪些替代继承的方法? java大神给出的解决方案 有效的Java:偏重于继承而不是继承。 (这实际上也来自“四人帮”)。他提出的理由是,如果扩展类未明确设计为继承,则继承会引起很多不正常的副作用。例如,对super.someMethod()的任何调用都可以引导您通过未知代码的意外路径。取而代之的是,持有对本来应该扩展的类的引用,然后委托给它。这是与Eric…

Java:BigInteger,如何通过OutputStream编写它 - java

我想将BigInteger写入文件。做这个的最好方式是什么。当然,我想从输入流中读取(使用程序,而不是人工)。我必须使用ObjectOutputStream还是有更好的方法?目的是使用尽可能少的字节。谢谢马丁 参考方案 Java序列化(ObjectOutputStream / ObjectInputStream)是将对象序列化为八位字节序列的一种通用方法。但…

Java DefaultSslContextFactory密钥库动态更新 - java

我有一个使用org.restlet.engine.ssl.DefaultSslContextFactory的现有应用程序和一个在服务器启动时加载的密钥库文件。我有另一个应用程序,该应用程序创建必须添加的证书服务器运行时动态地更新到密钥库文件。为此,我在代码中创建了证书和私钥,然后将其写入到目录。该目录由bash脚本监视,该脚本检查是否有新文件,如果出现,它将…

Java-如何将此字符串转换为日期? - java

我从服务器收到此消息,我不明白T和Z的含义,2012-08-24T09:59:59Z将此字符串转换为Date对象的正确SimpleDateFormat模式是什么? java大神给出的解决方案 这是ISO 8601标准。您可以使用SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM…