我在pom.xml
以下插件,它應該產生其他項目的編制要求的java文件:Maven的antrun-插件:生成的protobuf不會生成Java文件來源
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<archive>
<manifestFile>META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="src-gen" />
<exec executable="protoc">
<arg value="--java_out=src-gen" />
<arg value="proto/ros/RosTime.proto" />
<arg value="proto/ros/RosHeader.proto" />
<arg value="proto/ros/RosPoint.proto" />
<arg value="proto/ros/RosPose.proto" />
<arg value="proto/ros/RosPoseStamped.proto" />
<arg value="proto/ros/RosQuaternion.proto" />
<arg value="proto/U.proto" />
<arg value="proto/S.proto" />
<arg value="proto/Z.proto" />
<arg value="proto/algorithm/A.proto" />
<arg value="proto/algorithm/B.proto" />
<arg value="proto/algorithm/C.proto" />
<arg value="proto/algorithm/D.proto" />
<arg value="proto/algorithm/E.proto" />
<arg value="proto/algorithm/F.proto" />
<arg value="proto/env/G.proto" />
<arg value="proto/env/H.proto" />
<arg value="proto/env/J.proto" />
<arg value="proto/env/K.proto" />
<arg value="proto/env/L.proto" />
</exec>
</tasks>
<sourceRoot>src-gen</sourceRoot>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
然而,這根本不會在src-gen文件夾下產生任何東西。然後我不斷收到錯誤,如:
cannot find symbol
[ERROR] symbol: class AMsg
[ERROR] location: class project.messages.AFormatter
和
package project.messages.ros.RosHeader does not exist
package project.messages.ros.RosPoint does not exist
package project.messages.ros.RosPose does not exist
package project.messages.ros.RosPoseStamped does not
基本上無法找到所需文件,自然,並給出錯誤。我已經安裝了2.5.0版本,並且依賴性被正確定義:
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
我已經用完了想法。什麼使這不起作用?
編輯:下了我的注意的mvn install -X
調試輸出:
Execute:Java13CommandLauncher: Executing 'protoc' with arguments:
'--java_out=src-gen'
'proto/ros/RosTime.proto'
'proto/ros/RosHeader.proto'
'proto/ros/RosPoint.proto'
'proto/ros/RosPose.proto'
'proto/ros/RosPoseStamped.proto'
'proto/ros/RosQuaternion.proto'
.
.
.
.
The ' characters around the executable and arguments are
not part of the command.
[exec] ros/RosTime.proto: File not found.
[exec] proto/ros/RosHeader.proto: Import "ros/RosTime.proto" was not found or had errors.
[exec] proto/ros/RosHeader.proto:6:14: "project.messages.ros.RosTimeMsg" seems to be defined in "proto/ros/RosTime.proto", which is not imported by "proto/ros/RosHeader.proto". To use it here, please add the necessary import.
.
.
.
[INFO] --- maven-antrun-plugin:1.3:run (generate-sources) @ X.messages ---
[DEBUG] org.apache.maven.plugins:maven-antrun-plugin:jar:1.3:
[DEBUG] org.apache.maven:maven-plugin-api:jar:2.0.4:compile
[DEBUG] org.apache.maven:maven-project:jar:2.0.4:compile
[DEBUG] org.apache.maven:maven-settings:jar:2.0.4:compile
[DEBUG] org.apache.maven:maven-profile:jar:2.0.4:compile
[DEBUG] org.apache.maven:maven-model:jar:2.0.4:compile
[DEBUG] org.apache.maven:maven-artifact-manager:jar:2.0.4:compile
[DEBUG] org.apache.maven:maven-repository-metadata:jar:2.0.4:compile
[DEBUG] org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9:compile
[DEBUG] junit:junit:jar:3.8.1:compile
[DEBUG] classworlds:classworlds:jar:1.1-alpha-2:compile
[DEBUG] org.apache.maven:maven-artifact:jar:2.0.4:compile
[DEBUG] org.codehaus.plexus:plexus-utils:jar:1.5.6:compile
[DEBUG] org.apache.ant:ant-launcher:jar:1.7.1:runtime
[DEBUG] org.apache.ant:ant:jar:1.7.1:compile
[DEBUG] Created new class realm plugin>org.apache.maven.plugins:maven-antrun-plugin:1.3
[DEBUG] Importing foreign packages into class realm plugin>org.apache.maven.plugins:maven-antrun-plugin:1.3
[DEBUG] Imported: < project>runtime_shared:art.util.robot:1.0.0
[DEBUG] Populating class realm plugin>org.apache.maven.plugins:maven-antrun-plugin:1.3
[DEBUG] Included: org.apache.maven.plugins:maven-antrun-plugin:jar:1.3
[DEBUG] Included: junit:junit:jar:3.8.1
[DEBUG] Included: org.codehaus.plexus:plexus-utils:jar:1.5.6
[DEBUG] Included: org.apache.ant:ant-launcher:jar:1.7.1
[DEBUG] Included: org.apache.ant:ant:jar:1.7.1
[DEBUG] Excluded: org.apache.maven:maven-plugin-api:jar:2.0.4
[DEBUG] Excluded: org.apache.maven:maven-project:jar:2.0.4
[DEBUG] Excluded: org.apache.maven:maven-settings:jar:2.0.4
[DEBUG] Excluded: org.apache.maven:maven-profile:jar:2.0.4
[DEBUG] Excluded: org.apache.maven:maven-model:jar:2.0.4
[DEBUG] Excluded: org.apache.maven:maven-artifact-manager:jar:2.0.4
[DEBUG] Excluded: org.apache.maven:maven-repository-metadata:jar:2.0.4
[DEBUG] Excluded: org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9
[DEBUG] Excluded: classworlds:classworlds:jar:1.1-alpha-2
[DEBUG] Excluded: org.apache.maven:maven-artifact:jar:2.0.4
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-antrun-plugin:1.3:run from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-antrun-plugin:1.3, parent: [email protected]]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-antrun-plugin:1.3:run' with override configurator -->
[DEBUG] (f) pluginArtifacts = [org.apache.maven.plugins:maven-antrun-plugin:maven-plugin:1.3:, junit:junit:jar:3.8.1:compile, org.codehaus.plexus:plexus-utils:jar:1.5.6:compile, org.apache.ant:ant-launcher:jar:1.7.1:runtime, org.apache.ant:ant:jar:1.7.1:compile]
[DEBUG] (f) project = MavenProject: runtime_X:X.messages:1.0.0 @ /home/usr/workspace_runtime_X/X.messages/pom.xml
[DEBUG] (f) sourceRoot = /home/usr/workspace_runtime_X/X.messages/src-gen
[DEBUG] (f) tasks =
[DEBUG] -- end configuration --
你是說'maven-antrun-plugin'根本不被調用?或者它被調用,但'protoc'沒有被調用或者沒有生成文件?你能用'-X'運行時發佈與'maven-antrun-plugin'相關的日誌嗎? – Tunaki
它被調用,我可以看到'[exec]在調試輸出中用參數:[exec]'--java_out = src-gen''和這些行執行'protoc'。讓我分享這個問題下的相關內容。編輯:只需添加調試輸出。 –
你可以用'--java_out = $ {basedir}/src-gen'來嘗試(即指定一個絕對路徑)嗎? – Tunaki