0

我正在制作一个 Java 应用程序,它使用Restlet创建一个宁静的 API。从 Eclipse 运行它时它工作得很好,但是每当我生成一个 .exe 文件(使用exe4j)并从那里运行它时,restful API 停止工作并显示Not found错误(10.4.5 404 Not Found)

为什么会这样?

据我所知,我在创建 .exe 时包含了所有需要的库。这是我.xml在 exe4j 中使用的文件:

    <pathelement location="${lib}/com.mysql.jdbc_5.1.5.jar" />
    <pathelement location="${lib}/jacob.jar" />
    <pathelement location="${lib}/joda-time-2.3.jar" />
    <pathelement location="${lib}/json-simple-1.1.1.jar" />
    <pathelement location="${lib}/junit-4.11.jar" />
    <pathelement location="${lib}/log4j-api-2.0.1.jar" />
    <pathelement location="${lib}/log4j-core-2.0.1.jar" />
    <pathelement location="${lib}/mail.jar" />
    <pathelement location="${lib}/ojdbc6.jar" />
    <pathelement location="${lib}/org.restlet.jar" />
    <pathelement location="${lib}/pdfbox-app-1.8.0.jar" />
    <pathelement location="${lib}/sigar.jar" />
    <pathelement location="${lib}/sqlite-jdbc-3.7.2.jar" />
    <pathelement location="${lib}/guava-17.0.jar" />
    <pathelement location="${lib}/zeromq.jar" />

如果这完全相关,这是我创建路线的方式:

   /* Creates a root Restlet that will receive all incoming calls.*/
   @Override
   public Restlet createInboundRoot() {
       // Create a router Restlet that routes each call to  the relevant instance
       Router router = new Router(getContext());

       // Defines routes
       router.attach("/users", UsersController.class);
       router.attach("/departments", DepartmentsController.class);
       router.attach("/absences", AbsencesController.class);

       router.attachDefault(RestDefault.class);

       return router;
   }
4

1 回答 1

1

很难说,我不知道exe4j。

我看到的是,你使用exe4jc.exejars from${lib}但你没有引用${dist}/${ant.project.name}.jar. 因此,您构建的代码似乎不会进入可执行文件。这就是服务器找不到它的原因(404)。

    <!-- Put everything in ${build} into the <Project>.jar file -->
    <jar jarfile="${dist}/${ant.project.name}.jar" basedir="${build}"/>

    <!-- Copy MY program into lib to get packed by exe4jc -->
    <copy file="${dist}/${ant.project.name}.jar" todir="${lib}"/>

    <!-- Create an exe -->
    <apply executable="c:\Program Files\exe4j\bin\exe4jc.exe" failonerror="true">
      <fileset dir="${lib}">
        <patternset>
          <include name="${ant.project.name}.exe4j"/>
        </patternset>
      </fileset>
    </apply>
于 2014-11-26T13:02:59.487 回答