user2977259
user2977259

Reputation: 65

Maven add generated folder(using maven plugin) as source folder , IntelliJ not recognizing

In my maven Web project ,cxf-codegen-plugin generates JAVA classes and puts them in the folder

 ${basedir}/src/generated

I am using these generated classes , in my Java classes in

src/main/java

I am using IntelliJ IDE and IntelliJ does not seem to recognize the

${basedir}/src/generated

as a source folder (and rightly so).

My question is how can I get both Maven and IntelliJ to recongize the generated folders as source folder.

My project structure is

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

I also added the plugin build-helper-maven-plugin(to add another source folder) , based on other suggested SO answers , but it does not seem to work(at least IntelliJ does not recognize them) after a mvn clean install.

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

Upvotes: 4

Views: 3266

Answers (1)

vikingsteve
vikingsteve

Reputation: 40388

Since it is a "non standard" path, intellij won't pick it up automatically, but you can fix it easily like this:

Right click on the folder, in your case src\generated and select:

Mark Directory As -> Generated Source Root

You should see it become blue and all the packages underneath (com... etc) should be recognised as java code.

Upvotes: 2

Related Questions