您将遇到的问题是Eclipse中的项目不一定存储在工作空间目录中;他们可能在文件系统的任何地方。这意味着只需知道工作区的位置并不一定能帮助您找到批处理文件。
例如:我的工作区是$HOME/workspace
,但我所有的项目(工作副本)都在$HOME/code/project
。能够确定工作区并不是非常有用。项目可以存在于工作区之外,并且仍然在Eclipse中使用文件 - >导入。
最好的办法是使用build-helper-maven-plugin的attach-artifact目标将批处理文件“附加”到构建版本。有一个如何做到这一点的例子here。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>script.bat</file>
<type>bat</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
然后,你的其他项目可以使用Maven的依赖,插件的copy goal解决脚本到它自己的目录,并从那里运行它。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<type>bat</type>
<overWrite>true</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/scripts</outputDirectory>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
也许没有什么帮助,但我的建议:博恩奈特该批处理文件。坚持Maven/Ant。 – artbristol
@artbristol burninate? – badgerduke
对不起。我的意思是删除,摆脱。如果你使用Maven/Ant,你可以保持跨平台和声明性质。批处理文件很笨重。 – artbristol