简体   繁体   English

用Eclipse打包我的项目

[英]Packaging my project in Eclipse

I have a Java swing project which i need to test on other computers. 我有一个Java swing项目,需要在其他计算机上进行测试。 I have some classes and a sqlite db which stores login information. 我有一些类和一个sqlite db,用于存储登录信息。 I have some lib jars as well. 我也有一些罐子。 The application takes information from the user and stores it in the sqlite db and then pushes data to the web. 该应用程序从用户那里获取信息,并将其存储在sqlite db中,然后将数据推送到Web。 I want to package my project so that whoever uses my project has to just double click on an executable or jar. 我想打包我的项目,以便使用我项目的人只需双击可执行文件或jar。

I tried to Export to a Runnable Jar file in Eclipse but this does not give desired results. 我试图在Eclipse中导出到Runnable Jar文件,但这没有得到期望的结果。 After the runnable jar is created and i run it for the first time it creates the sqlite db beside it and does not connect to the web link and send information. 创建可运行的jar后,我第一次运行它,它在它旁边创建了sqlite db,并且不连接到Web链接并发送信息。

How can i package my data properly? 如何正确打包数据? This is my folder structure - 这是我的文件夹结构-

root
--src --src
----default package ----默认包
----rest package ----休息包
----images - - 图片
--lib --lib
--file.fcl --file.fcl
--db.sqlite --db.sqlite

Any time you run a program outside eclipse that changes any file within a project folder structure, the file changed is "out of sync". 每当您在eclipse外部运行程序以更改项目文件夹结构中的任何文件时,更改的文件都是“不同步”。 To bring things back in sync, right-click on the project in Package Explorer and choose "Refresh" (you can also select the project in Package Explorer and press F5). 要使内容恢复同步,请在Package Explorer中右键单击该项目,然后选择“刷新”(您也可以在Package Explorer中选择该项目,然后按F5键)。

If your code is creating the database instead of using the one that is there, it suggests to me that your database location is set for your eclipse environment but not for the general case. 如果您的代码是在创建数据库而不是使用那里的数据库,那么对我来说,您的数据库位置是为Eclipse环境设置的,而不是为一般情况设置的。 For a java application, you have to know (or set) the "current directory" or "current folder" -- this is a folder that is the default for file operations, and from which relative file paths are set. 对于Java应用程序,您必须知道(或设置)“当前目录”或“当前文件夹”-这是文件操作的默认文件夹,并从中设置相对文件路径。 If your current directory is "aaa", and you open a file or database at "bbb/ccc/ddd/database.db", then the "bbb" directory must be within "aaa" or the program won't find the file. 如果当前目录为“ aaa”,并且在“ bbb / ccc / ddd / database.db”中打开文件或数据库,则“ bbb”目录必须位于“ aaa”之内,否则程序将找不到该文件。

To run your program without having to set the database location, etc., then you're probably going to want to discover the directory in which your program file is stored and set that as your current directory. 要运行程序而不必设置数据库位置等,那么您可能想要发现存储程序文件的目录并将其设置为当前目录。 This SO answer indicates how you might do that. 这样的答案表明了您可能会如何做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM