1.找到项目对应build.xml文件
如图所示
2.打开build.xml文件
往文件里面 复制 以下代码
<target name="package-for-store" depends="jar">
<!-- Change the value of this property to be the name of your JAR,
minus the .jar extension. It should not have spaces.
<property name="store.jar.name" value="MyJarName"/>
-->
<property name="store.jar.name" value="sccManager"/>
<!-- don't edit below this line -->
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<mkdir dir="${store.dir}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>
如图所示
3.第三部操作如图
4.以上配置完成之后,找到第一部的build.xml的文件 右击 运行目标 选择 其他目标 然后 选择package-for-store
5.找到项目下的dist文件 就会出现一个jar名称.jar的文件
运行命令 java -jar 包名称.jar 就能运行了。
这种方法 在项目构建的时候找不到主类或者是无法构建的时候都可以用。