首页 \ 问答 \ JNLP - NoSuchMethodException(JNLP - NoSuchMethodException)

JNLP - NoSuchMethodException(JNLP - NoSuchMethodException)

一段时间以来一直在努力解决这个问题。 我有一个类,有一个主要的方法,当从Eclipse运行时,这个方法非常好。 无论如何,当我使用我的JNLP文件运行它(使用maven-jar-plugin)时,我无法管理它来开始工作。

我得到的错误如下:

java.lang.NoSuchMethodException: my.package.ishere.MainClass.main([Ljava.lang.String;)
    at java.lang.Class.getMethod(Unknown Source)
    at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
    at com.sun.javaws.Launcher.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

我的主要方法是在正确的包中,主要方法是public,static,返回类型是void,并且有一个字符串数组作为参数。

为了生成jar文件,在pom中我包含以下内容:

<plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <configuration>             
            <source>1.6</source>
            <target>1.6</target>
            <encoding>UTF-8</encoding> 
                <archive>
                        <manifestFile>${manifestFile}</manifestFile>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                            <mainClass>my.package.ishere.Mainclass</mainClass>
                        </manifest>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                </configuration>
</plugin>

最后,在我的JNLP中,我正确地包含了代码库,正确地包含了所有必需的资源,以及具有main =“true”属性的jar文件。

此外,我甚至在jar上检查了清单文件,它清楚地说明了Main-Class:my.package.ishere.MainClass 。 任何人都可以给我一个关于接下来要检查的提示吗? 我疯了!

(显然包名和类名不是真正的名称)。

提前致谢!!

编辑:MainClass代码请求。

package my.package.ishere;

//HELLA long import list not going to add.

public class MainClass extends Frame implements WindowListener {

static String xmlParams;

public static void main(String[] args) {
    try {
            xmlParams = new String(base64Decoder.decodeBuffer(args[0]));
            MainClass mc = new MainClass();
            mc.setLayout(new FlowLayout());
            System.out.println(mc.getParameter("id"));
            mc.init();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

这是一个我转换成独立应用程序的旧applet。

更新:

设法使它运行主jar; 将maven的类路径添加到清单中,并从命令提示符处运行java -jar name-of-the-jar.jar param1和yay,它工作正常。 无论如何,没有设法从JNLP直接运行 - 仍然得到“NoSuchMethodException”。


Been struggling with this issue for a while already. I have a class, with a main method, which works perfectly fine when ran from Eclipse. No matter what, when i jar it (with maven-jar-plugin) to run it with my JNLP file i can't manage it to get to work.

The error im getting is as follows:

java.lang.NoSuchMethodException: my.package.ishere.MainClass.main([Ljava.lang.String;)
    at java.lang.Class.getMethod(Unknown Source)
    at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
    at com.sun.javaws.Launcher.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

My main method is in the right package, and the main method is public, static, returning type is void and has an array of strings as the parameter.

In order to generate the jar file, in the pom I include the following:

<plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <configuration>             
            <source>1.6</source>
            <target>1.6</target>
            <encoding>UTF-8</encoding> 
                <archive>
                        <manifestFile>${manifestFile}</manifestFile>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                            <mainClass>my.package.ishere.Mainclass</mainClass>
                        </manifest>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                </configuration>
</plugin>

Finally, in my JNLP, I'm including the codebase correctly, all the required resources correctly, and the jar file with the main="true" attribute.

Furthermore, I even checked the manifest file on the jar and it says clearly Main-Class: my.package.ishere.MainClass. Could anyone give me a hint on what to check next? I'm going nuts!

(Obviously the package name and the class name ain't the real ones).

Thanks in advance!!

EDIT: MainClass code on request.

package my.package.ishere;

//HELLA long import list not going to add.

public class MainClass extends Frame implements WindowListener {

static String xmlParams;

public static void main(String[] args) {
    try {
            xmlParams = new String(base64Decoder.decodeBuffer(args[0]));
            MainClass mc = new MainClass();
            mc.setLayout(new FlowLayout());
            System.out.println(mc.getParameter("id"));
            mc.init();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

It is an old applet I converted into a stand-alone application.

UPDATE:

Managed to make it work running the main jar; added the classpath from maven to the manifest and from the command prompt i ran java -jar name-of-the-jar.jar param1 and yay, it worked. No matter what, haven't managed to run it straight from the JNLP - still getting the "NoSuchMethodException".


原文:https://stackoverflow.com/questions/33147530
更新时间:2022-06-18 13:06

最满意答案

在运行时没有区别。

只有Java编译器(和类型检查器)才有区别。 在第一种情况下,即使运行时类型更具体,您声明关于c的最有用的信息是它是Parent类。

这有两个主要影响:

  • c可以在需要Parent时使用,但在需要Child时不能使用
  • 如果你想将c的类型更改为另一种类型(让我们假设class Nephew extends Parent ),唯一必要的是更改实例化(例如, new Child()成为new Nephew()

第二个影响的结果是,如果代码编译并且c被声明为Parent ,这意味着您没有使用任何尚未在Parent声明的特性,因此从Parent扩展的每个其他类都是有效的替代品


At runtime there is no difference.

There is a difference only for the Java compiler (and type checker). In the first case you are declaring that the most informative thing that you know about the c is that it is a Parent, even if the runtime type is more specific.

This has two main effects:

  • c can be used when a Parent is needed but not when a Child is needed
  • if you want to change the type of c to another type (let's suppose class Nephew extends Parent) the only necessary thing is to change the instantiation (eg. new Child() becomes new Nephew()

The second effect is a consequence of the fact that, if the code compiles and c is declared as a Parent, this implies that you are not using any feature which is not already declared in Parent, so every other class which extends from Parent is a valid substitute.

相关问答

更多
  • 父母程序可能已经退出并且不再存在。 你可以在父母中尝试一些延迟。 It is likely the parent process has already exited and no longer exists. You could try some delay in the parent.
  • 父母和孩子是更抽象的关系。 它们用于描述层次结构,因此可用于各种树木(或有时是DAG)。 类继承树就是这样一棵树,所以叫他们父母和孩子是没有错的。 这个术语通常与其他种类的树一起使用,例如嵌套的GUI控件,目录结构...... 基础和派生仅用于继承,因此更精确。 这个术语是首选,因为它不太模糊。 parent and child are more abstract relations. They are used to describe hierarchy, and thus can be used in ...
  • 如果你没有将管道文件描述符设置为非阻塞,那么应该没有问题。 管道上的任何读数都会阻塞,直到孩子产生输出; 如果您需要响应多个文件描述符(例如,来自用户的标准输入和来自子进程的管道),请使用select()或poll() 。 我假设fgets()返回NULL。 这表示文件结尾(意味着孩子已经关闭了管道的末尾)或错误。 你可以使用feof()或ferror()来检查其中哪一个是真的。 在错误情况下使用perror()来查看错误实际是什么。 If your haven't set your pipe file d ...
  • 你需要为此使用递归CTE 。 ;WITH r as ( SELECT ID FROM DevicesTable WHERE ParentID = @someID UNION ALL SELECT d.ID FROM DevicesTable d INNER JOIN r ON d.ParentID = r.ID ) SELECT ID FROM r You need to use a recursiv ...
  • 处理你正在做的事情的另一种方法是B提升事件和A处理事件。 这样你就不必将A传递给B.我不知道你的真实结构是什么,但是我们可以说B的线程函数做了更复杂的事情而A实现了IDisposable 。 如果在B到达它正在调用A上的方法之前处理A会发生什么。对我来说,处理这种情况的更简洁的方法是让B引发事件和A寄存器。 public class A { B _b; public A() { _b = new B(); _b.DidSomething += Han ...
  • 谢谢大家,我想出了自己! get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); $i = 0; if ( $child_pages ) : foreach ( $child_pages as $pageChilds ) : $gchild_page ...
  • 是的,绝对有可能让孩子活着。 其他响应者也是正确的; 这就是“守护进程”或后台进程在Linux环境中的运行方式。 有人称这是“分手和死亡”的方法。 以下是描述如何执行此操作的链接: http : //wiki.linuxquestions.org/wiki/Fork_off_and_die 请注意,不仅仅是fork() - 已经完成。 文件描述符被关闭以防止后台进程占用系统资源等。 Yes, it is definitely possible to keep the child alive. The oth ...
  • 在运行时没有区别。 只有Java编译器(和类型检查器)才有区别。 在第一种情况下,即使运行时类型更具体,您声明关于c的最有用的信息是它是Parent类。 这有两个主要影响: c可以在需要Parent时使用,但在需要Child时不能使用 如果你想将c的类型更改为另一种类型(让我们假设class Nephew extends Parent ),唯一必要的是更改实例化(例如, new Child()成为new Nephew() 第二个影响的结果是,如果代码编译并且c被声明为Parent ,这意味着您没有使用任何尚 ...
  • 销毁订单定义为(强调我的): 对于用户定义或隐式定义的析构函数, 在执行析构函数体之后,编译器按照声明的相反顺序调用类的所有非静态非变体成员的析构函数,然后调用析构函数所有直接的非虚基类按构造的相反顺序(反过来调用它们的成员及其基类的析构函数等),然后,如果这个对象是派生最多的类,它调用所有虚拟的析构函数基地。 一个很好的理由是, Parent的析构函数可能需要访问其成员以释放资源,而不是每个对象都是自包含的。 The destruction order is defined as (emphasis mi ...
  • 它不是关于Person如何“看到” Student ,而是关于继承的访问控制意味着什么。 当你说class Student: public Person ,这意味着你宣布Student是每个Person的人,这意味着main()知道Student*可以由Person*引用。 所以一切都很好。 当你说class Student: private Person ,它意味着Student继承了Person功能,但这只是一个实现细节。 这不会让任何人知道Student是一个Person所以它不能被视为一个人。 因此 ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)