2013-11-10 29 views
0

我试图用ant来构建我的jar及其所有依赖项,但当我尝试运行带有java -jar ircbot.jar命令的jar时,仍然收到Error: Could not find or load main class main.SteamduckBot未能加载或找到主类

这是我的build.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<project name="ircbot" default="jar"> 

    <!-- Name of the output .jar file --> 
    <property name="jar.name" value="ircbot.jar" /> 

    <!-- Base directory for distribution target --> 
    <property name="deploy.home" value="." /> 

    <!-- Base directory for compilation targets --> 
    <property name="build.home" value="." /> 

    <!-- Main class --> 
    <property name="main.class" value="main.SteamduckBot" /> 

    <!-- The base directory for all libraries (jar) files --> 
    <property name="lib.home" value="lib" /> 

    <target name="jar" description="Create jar and MANIFEST.MF"> 

     <pathconvert property="libs.project" pathsep=" "> 
      <mapper> 
       <chainedmapper> 
        <!-- remove absolute path --> 
        <flattenmapper /> 

        <!-- add lib/ prefix --> 
        <globmapper from="*" to="lib/*" /> 
       </chainedmapper> 
      </mapper> 
      <path> 
       <!-- lib.home contains all jar files, 
               in several subdirectories --> 
       <fileset dir="${lib.home}"> 
        <include name="**/*.jar" /> 
       </fileset> 
      </path> 

     </pathconvert> 

     <!-- create the jar --> 
     <jar jarfile="${deploy.home}/${jar.name}" basedir="${build.home}"> 

      <manifest> 
       <attribute name="Built-By" value="${user.name}" /> 
       <attribute name="Main-Class" value="${main.class}" /> 

       <!-- Finally, use the generated libs path --> 
       <attribute name="Class-Path" value="${libs.project}" /> 
      </manifest> 

     </jar> 
    </target> 

</project> 

的Ant构建得很好,但很明显,我必须做一些错误的 - 哪里是我的错误?

这是我的项目的结构: enter image description here

这里是导致罐的内容:这是JAR的内容:http://pastebin.com/iYQGsutE

回答

0

我没有在生成文件中看到在那里你将Java文件编译为.class文件,并在jar中包含这些.class文件。看起来好像你将源文件存储在jar文件中,而不是类文件。

检查罐子的内容。

+0

这是罐子的内容:http://pastebin.com/iYQGsutE – CodePrimate

+0

所以你证实了我的想法。你用源文件创建了一个jar,而不是编译的类文件。您的构建文件必须先编译源文件,然后创建一个包含已编译的类文件的jar。没有.java文件应该在jar中。 –

+0

有什么机会可以告诉我如何做到这一点? – CodePrimate