无法使用蚂蚁启动的main()从罐子 [英] Unable to start main() from jar using ant

查看:107
本文介绍了无法使用蚂蚁启动的main()从罐子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,说 A ,并包括在其构建路径罐子,说 A 。罐子包含一个主要方法和它的类名是在清单文件中提供的。

I have a project, say A and a jar included in its build path, say a. The jar contains a main method and its classname is provided in the Manifest file.

A 的build.xml文件我使用code如下调用jar文件:

From A's build.xml I am calling the jar file using code as below :

<java jar="lib/a.jar" fork="true">
      <arg value="test param" />
</java>

清单文件指向: myframework.Startup

当我尝试运行Ant文件获得:

When I try to run the ant file I get :

 [java] java.lang.NoClassDefFoundError: org/apache/log4j/Logger
 [java]     at myframework.Startup.<clinit>(Startup.java:40)
 [java] Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
 [java]     at java.net.URLClassLoader$1.run(Unknown Source)
 [java]     at java.security.AccessController.doPrivileged(Native Method)
 [java]     at java.net.URLClassLoader.findClass(Unknown Source)
 [java]     at java.lang.ClassLoader.loadClass(Unknown Source)
 [java]     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 [java]     at java.lang.ClassLoader.loadClass(Unknown Source)
 [java]     at java.lang.ClassLoader.loadClassInternal(Unknown Source)
 [java]     ... 1 more
 [java] Could not find the main class: myframework.Startup. Program will exit.
 [java] Exception in thread "main" 
 [java] Java Result: 1


但是,当我从我的编辑,Eclipse的,即直接运行jar文件的右键点击a.jar->运行方式 - > Java应用程序的运行良好

请帮忙。

推荐答案



我试图访问的父项目(A)儿童罐内容(一)。根据Oracle的规格这里和Ant单证< A HREF =htt​​p://ant.apache.org/manual/Tasks/java.html相对=nofollow>这里,在的classpath 的条目,而使用的jar属性忽略在java任务。


I was trying to access a Parent Project(A) contents from the Child Jar(a). As per oracle's specifications here and Ant documentations here, the classpath entries are ignored while using jar attribute in java task.

<java jar="jarFile.jar">
     <classpath>
          ... ... ...
     </classpath>
</java>

类路径将被忽略。

The classpath is ignored.

当我试图调用在jar文件一个main()present( ),我在指定清单文件中的类名。在main()需要使用的类从Project( A ),但遗憾的是这些类不作为按照Oracle的标准。

As I was trying to call a main() present in the jarFile (a), I specified the classname in the manifest file. The main() needed to use the classes from the Project (A) but unfortunately these classes are not available as per the oracle's standards.

然后我试图用一种新的策略:

Then I tried to use a new strategy :

<unzip the jar file to project bin directory />
<java classpath="jar file's main Class Name">
    ... ... ...
</java>

通过解压缩的jar文件内容到项目bin /目录下的jar文件( )的类主要项目是可利用的( A ),然后我问题得到解决。

By unzipping the jar file contents to the project bin/ directory the jar file (a)'s classes were available in the main project (A) and then my problem was solved.

这篇关于无法使用蚂蚁启动的main()从罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆