我試圖讓mvn exec:exec
(或mvn exec:java
)在類路徑中使用本地jar運行我的程序。但是罐子加載失敗:如何爲mvn exec:exec設置classpath?
Exception in thread "main" java.lang.Error: Unable to load voice directory. java.lang.ClassNotFoundException: com.sun.speech.freetts.en.us.cmu_us_slt_arctic.ArcticVoiceDirectory
at com.sun.speech.freetts.VoiceManager.getVoiceDirectories(VoiceManager.java:211)
at com.sun.speech.freetts.VoiceManager.getVoices(VoiceManager.java:111)
at com.sun.speech.freetts.VoiceManager.getVoice(VoiceManager.java:521)
at xpress.audio.TTS.<init>(TTS.java:66)
at xpress.audio.TTS.<init>(TTS.java:62)
at xpress.audio.AudioProducer.main(AudioProducer.java:18)
從CLI使用java
作品直接運行程序:
C:\XpressAudio\target\classes>java -cp "C:\XpressAudio\target\XpressAudio-1.0-SN
APSHOT-jar-with-dependencies.jar;C:\XpressAudio\cmu_us_slt_arctic.jar;C:\XpressA
udio\en_us.jar;C:\XpressAudio\*" xpress.audio.AudioProducer
這裏是我的pom.xml
的<build>
部分:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<mainClass>xpress.audio.AudioProducer</mainClass>
</configuration>
<dependencies>
<dependency>
<groupId>cmu_us</groupId>
<artifactId>slt_arctic</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/cmu_us_slt_arctic.jar</systemPath>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
有人能告訴我應該如何編輯pom.xml
以使mvn exec:exec
的工作方式與java
com相似上面的任務?
com.sun.speech.freetts.en.us.cmu_us_slt_arctic.ArcticVoiceDirectory
是cmu_us_slt_arctic.jar
[Maven exec插件 - 如何包含「系統」類路徑?](http://stackoverflow.com/questions/5286279/maven-exec-plugin-how-to-include-system-classpath) – Joe
您可能應該使用java mojo而不是exec mojo,並查看其中列出的選項:http://mojo.codehaus.org/exec-maven-plugin/java-mojo.html。特別是可執行的依賴項,包括我猜測包括插件依賴和includeProjectDependencies。 – Tome