如何让我的程序在 eclipse 之外运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15667973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:16:27  来源:igfitidea点击:

How to get my program to run outside of eclipse

javaeclipseexportprocessing

提问by AJMansfield

I have a project in eclipse. It does everything I want it to do when I click on the green circle play button in the IDE - opens the window, plays the stuff, everything. But, try as I might, I cannot figure out how to get it to do that outside of eclipse.

我在 Eclipse 中有一个项目。当我点击 IDE 中的绿色圆圈播放按钮时,它会完成我想要它做的一切 - 打开窗口,播放内容,一切。但是,尽我所能,我无法弄清楚如何让它在日食之外做到这一点。

My project uses the processing.core library to do some of its stuff, but I am unable to get the project to function in the Processing IDE, because of some stupid stuff about one of my classes not being a valid substitute for the type parameter for Collections.sort(List<T>). If anyone knows how I can get it to export from the Processing IDE, that would be excellent.

我的项目使用 processing.core 库来做一些事情,但我无法让项目在 Processing IDE 中运行,因为我的一个类的一些愚蠢的东西不是类型参数的有效替代品Collections.sort(List<T>). 如果有人知道我如何让它从 Processing IDE 导出,那就太好了。

I need to be able to email/upload to the internet/otherwise transmit some kind of file/folder/webpage that allows the recipient to, without much technical knowledge or work on their part, view a window or something that allows them to view and interact with the program in the same way I am able to interact with the window that Eclipse launches when I press the play button at the top.

我需要能够通过电子邮件/上传到互联网/以其他方式传输某种文件/文件夹/网页,允许收件人在没有太多技术知识或工作的情况下查看窗口或允许他们查看和与程序交互的方式与当我按下顶部的播放按钮时我能够与 Eclipse 启动的窗口交互的方式相同。

I have tried several different ways of accomplishing this, but none of them have worked. I tried exporting a runnable .jar, but it wouldn't let me include the referenced libraries. I tried a regular .jar, but I don't know how to package that up with whatever is needed to be able to view it. I've even tried using the fat jar eclipse plugin for it, too, but I ran afoul of something about being unable to find the main PAppletclass for the project.

我尝试了几种不同的方法来实现这一点,但都没有奏效。我尝试导出一个 runnable .jar,但它不允许我包含引用的库。我尝试了一个常规.jar,但我不知道如何将它与能够查看它所需的任何内容打包在一起。我什至也尝试过使用 fat jar eclipse 插件,但是我遇到了无法找到PApplet项目主类的问题。

If anybody knows how to get what I want to happen, or knows of a good tutorial on how to do what I want, I would greatly appreciate any sort of assistance or guidance or anything.

如果有人知道如何获得我想要发生的事情,或者知道如何做我想做的事情的好教程,我将不胜感激任何形式的帮助或指导或任何事情。

Google has been unhelpful in turning up solutions to this problem, because most of the results I have found were just other people asking the same or a similar question, and then either no answer, or something I had already tried, with no indication of exactly what sort of options or settings I needed to give it in order to accomplish the task.

谷歌一直没有帮助找到这个问题的解决方案,因为我发现的大多数结果只是其他人在问相同或类似的问题,然后要么没有答案,要么我已经尝试过,没有确切的迹象为了完成任务,我需要提供什么样的选项或设置。

I am using the processing.core.jarfrom version 2.0b7, but I don't think that would make a difference, although I plan to try it with different versions if I can't figure out anything else.

我使用的processing.core.jar是 2.0b7 版,但我认为这不会有什么不同,尽管如果我无法弄清楚其他任何东西,我计划尝试使用不同的版本。

A copy of my project folder can be found at https://www.dropbox.com/sh/1n4curhxbgi8fye/A5F6_l7xQu

可以在https://www.dropbox.com/sh/1n4curhxbgi8fye/A5F6_l7xQu找到我的项目文件夹的副本

All the data I have is stuff I've concatenated together from successive versions of the file at http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M1.txt

我拥有的所有数据都是我从http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M1.txt文件的连续版本连接在一起的东西

回答by George Profenza

I've done a quick test on OSX and had to tweak your eclipse project a bit:

我在 OSX 上做了一个快速测试,不得不稍微调整一下你的 eclipse 项目:

  1. You are linking to .jar libraries using absolute path. I recommend using keeping libraries relative to the project
  2. I ran into some memory issues and had to add a couple of compiler flags
  3. Added a main method in Earthquaker.java to initialize as an application.
  1. 您正在使用绝对路径链接到 .jar 库。我建议使用保持库相对于项目
  2. 我遇到了一些内存问题,不得不添加几个编译器标志
  3. 在 Earthquaker.java 中添加了一个 main 方法来初始化为一个应用程序。

main looks like this:

主要看起来像这样:

public static void main(String[] args) {
        PApplet.main(Earthquaker.class.getSimpleName());
    }

In eclipse you can export a runnable jar via File > Export > Java > Runnable JAR file. Here are a couple of screenshots:

在 Eclipse 中,您可以通过File > Export > Java > Runnable JAR file 导出可运行的 jar 。下面是几个截图:

eclipse jar export 1

eclipse jar 导出 1

eclipse jar export 2

eclipse jar 导出 2

Personally I prefer using the "Copy required libraries into a sub-folder..."option in case I need to update some dependent .jar independent of the main application .jar.

我个人更喜欢使用“将所需的库复制到子文件夹...”选项,以防我需要更新一些独立于主应用程序 .jar 的依赖 .jar。

For reference I've uploaded the modified eclipse project here(Java SDK will need to be changed). The exported runnable jar with a bash script is available here.

作为参考,我在这里上传了修改后的 eclipse 项目(需要更改 Java SDK)。带有 bash 脚本的导出的可运行 jar 可在此处获得

And here is the bash script itself which should run on Linux as well:

这是 bash 脚本本身,它也应该在 Linux 上运行:

java -Xms128M -Xmx1024M -jar Processing-DataVisualization.jar

Pretty cool project btw.

顺便说一句,很酷的项目。

回答by pravat

Create a simple jar. Create a batch file and specify the class path. Save the batch file. Runnin the batch file will run the app

创建一个简单的罐子。创建批处理文件并指定类路径。保存批处理文件。运行批处理文件将运行应用程序

@ECHO OFF
set CLASSPATH=%CLASSPATH%;myjar1.jar;myjar2.jar;

java mypackage.MyClass