Java cxf将源文件放入目标中,但编译器可以';你没看见他们吗?

Java cxf将源文件放入目标中,但编译器可以';你没看见他们吗?,java,maven,cxf,Java,Maven,Cxf,我刚开始使用cxf,所以这可能是一个新手的错误 我正在阅读《soa治理在行动》一书,并下载了示例项目 当我使用cxf从wsdl构建源代码时,它将源代码放在eclipse的“target”目录中。但这些是它创建的java文件,编译器似乎看不到它们,因此构建需要这些文件的应用程序失败,并出现编译器错误 我应该将“target”中生成的sources目录添加到构建路径还是什么 非常感谢 编辑:完全糊涂了。这是pom <build> <pluginManagement>

我刚开始使用cxf,所以这可能是一个新手的错误

我正在阅读《soa治理在行动》一书,并下载了示例项目

当我使用cxf从wsdl构建源代码时,它将源代码放在eclipse的“target”目录中。但这些是它创建的java文件,编译器似乎看不到它们,因此构建需要这些文件的应用程序失败,并出现编译器错误

我应该将“target”中生成的sources目录添加到构建路径还是什么

非常感谢

编辑:完全糊涂了。这是pom

<build>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings 
                only. It has no influence on the Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>
                                        build-helper-maven-plugin
                                </artifactId>
                                    <versionRange>[1.7,)</versionRange>
                                    <goals>
                                        <goal>add-source</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute></execute>
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.cxf</groupId>
                                    <artifactId>
                                        cxf-codegen-plugin
                                </artifactId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>wsdl2java</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute></execute>
                                </action>
                            </pluginExecution>

                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </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>target/generated/cxf</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <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>${project.build.directory}/generated/cxf</sourceRoot>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>${basedir}/src/main/resources/contract/accountService.wsdl</wsdl>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxrs</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.manning.ossoagov.chapter2</groupId>
        <artifactId>traffic-service-general</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
</dependencies>

编辑:试图缩小范围。我有一个“Maven问题”,即“执行生成目标源org.apache.cxf:cxf codegen插件:2.3.2:wsdl2java失败。(org.apache.cxf:cxf codegen插件:2.3.2:wsdl2java:generate sources:generate sources)”

但是如果我转到命令行并执行 mvn org.apache.cxf:cxf-codegen插件:wsdl2java

然后我就成功了

eclipse的自动构建是否可能没有以相同的方式运行?这可能是警告吗

[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.manning.ossoagov.chapter2:traffic-service-remoting-WS:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.apache.cxf:cxf-rt-frontend-jaxws:jar -> duplicate declaration of version ${cxf.version} @ line 134, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]                                                                     
[INFO] ------------------------------------------------------------------------
[INFO] Building Traffic Service WS Remoting 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- cxf-codegen-plugin:2.3.2:wsdl2java (default-cli) @ traffic-service-remoting-WS ---
[INFO] Nothing to generate
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.868s
[INFO] Finished at: Tue Apr 16 09:37:40 BST 2013
[INFO] Final Memory: 6M/81M
[INFO] ------------------------------------------------------------------------

您应该将此文件夹添加到类路径中,使用maven可以执行以下操作:

      <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <id>add-wsdl-source</id>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/path/to/generated/sources</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

org.codehaus.mojo
构建助手maven插件
1.4
添加wsdl源
过程源
添加源
${project.build.directory}/path/to/generated/sources

我遇到了一个类似的问题,我右键单击了保存生成源的文件夹,然后选择


生成路径->“用作源文件夹”

现在eclipse将知道它在哪里。然后所有的错误都消失了

在选择文件夹时要小心,因为在错误的文件夹上选择会导致错误的包名。
.

您使用的是EclipseJavaEE版本吗?我想是的。为什么会有不同?谢谢。谢谢-我想我的pom中有这个(请参见上文)。更改“阶段”使其从generate-sources处理源代码。这似乎没有什么区别?我将阶段更改为ProcessSources并运行了一个maven构建,目标是ProcessSources,它只是像以前一样在target中创建了源文件,但没有编译它们..这些是完整的日志吗?我没有看到编译器插件得到执行。更新了日志。第一次我只是运行目标进程源代码。这次我运行了maven安装。我仍然在eclipse中看到错误,即使构建成功,编译器也无法看到生成的源代码?困惑的谢谢你的帮助!
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.manning.ossoagov.chapter2:traffic-service-remoting-WS:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.apache.cxf:cxf-rt-frontend-jaxws:jar -> duplicate declaration of version ${cxf.version} @ line 134, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]                                                                     
[INFO] ------------------------------------------------------------------------
[INFO] Building Traffic Service WS Remoting 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- cxf-codegen-plugin:2.3.2:wsdl2java (default-cli) @ traffic-service-remoting-WS ---
[INFO] Nothing to generate
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.868s
[INFO] Finished at: Tue Apr 16 09:37:40 BST 2013
[INFO] Final Memory: 6M/81M
[INFO] ------------------------------------------------------------------------
      <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <id>add-wsdl-source</id>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/path/to/generated/sources</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Build Path -> "Use as source Folder "