简体   繁体   English

如何将OEM Java库和源导入Netbeans?

[英]How to import OEM Java lib and source into Netbeans?

I have done a reasonable amount of programming in various languages but I am a Java / Netbeans newbie. 我已经用各种语言进行了大量的编程工作,但是我是Java / Netbeans新手。 I have successfully created and run "Hello World" so my Netbeans installation is OK. 我已经成功创建并运行“ Hello World”,因此我的Netbeans安装正常。

I want to write code to control an LED display controller card. 我想编写代码来控制LED显示控制器卡。 I have sample demo code zipped up by the OEM. 我有OEM压缩的示例演示代码。 I am trying to import, run and edit that code. 我正在尝试导入,运行和编辑该代码。 If I can get this running, this will be the starting point of my own code. 如果我可以运行它,那将是我自己的代码的起点。

The zip files only include library and source files in a directory structure that does not match Netbeans. 压缩文件仅在与Netbeans不匹配的目录结构中包括库文件和源文件。 All of my attempts to import the source and lib files have given fatal errors in Netbeans. 我所有尝试导入源文件和lib文件的尝试都在Netbeans中给出了致命错误。

The directory tree has a lib and src branch at the root. 目录树在根目录下有一个lib和src分支。 The src branch cascades 4 levels to get to the source files. src分支级联4个级别以获取源文件。

I figure if I use a different tree structure, I will need to change the import statements in the source file. 我认为如果使用其他树结构,则需要更改源文件中的import语句。 I'd rather not touch the code until I have it running. 我宁愿不触摸代码,直到我运行它。 I have tried to unzip the project tree directly into the Netbeans directory but that didn't work. 我试图将项目树直接解压缩到Netbeans目录中,但这没有用。

For Netbeans to be able to open a project, the folder has to contain some files that Netbeans itself generates when a project is created. 为了使Netbeans能够打开项目,该文件夹必须包含一些在创建项目时Netbeans本身生成的文件。

Since you only have src and lib folders available, I think the easiest solution would be to create a new project from Netbeans, so that the creation of those files is automatically managed, and then copying the content of the folders you have in the folders Netbeans will create. 由于您只有srclib文件夹可用,我认为最简单的解决方案是从Netbeans创建一个新项目,以便自动管理这些文件的创建,然后复制NetBeans文件夹中的文件夹内容将创建。

You will also have to tell Netbeans to use those library, and you can do that from you new project's preferences. 您还必须告诉Netbeans使用这些库,并且可以从新项目的首选项中进行操作。

Edit 编辑

A few more things you can try: 您可以尝试以下几件事:

  1. in NB, right click the folder containing the JARs you imported and select "remove", then import them back but selecting the jar files instead of the whole folder; 在NB中,右键单击包含导入的JAR的文件夹,然后选择“删除”,然后将其重新导入,但选择jar文件而不是整个文件夹;

  2. if you're not already doing so, use the "Clean and build project" button instead of "Build project"; 如果您尚未这样做,请使用“清理并生成项目”按钮,而不是“生成项目”;

If none of the above solve the issue, try starting from scratch again following these steps: 如果上述方法均不能解决问题,请尝试按照以下步骤从头开始重新进行操作:

  1. unzip your OEM files somewhere in your disk; 将您的OEM文件解压缩到磁盘中的某个位置;

  2. create a new empty project in NB 在NB中创建一个新的空项目

  3. copy the files from the src OEM subfolder to src NB project subfolder 将文件从src OEM子文件夹复制到src NB项目子文件夹

  4. in NB, right click Libraries, then add JAR/Folder and select the jar files from the lib OEM subfolder 在NB中,右键单击“库”,然后添加JAR / Folder并从lib OEM子文件夹中选择jar文件。

If this doesn't work either, tell me where I can find the OEM stuff and I'll try it myself :) 如果这还是行不通的,请告诉我在哪里可以找到OEM的东西,然后我自己尝试:)

How to import a JAR (Java Archive, the "library" in your case) in Netbeans: 如何 在Netbeans中 导入JAR (Java归档,您的情况下为“库”)

  1. Right click on your project name, in the 'Projects' pane usually located on the left 在通常位于左侧的“项目”窗格中,右键单击您的项目名称
  2. Click the 'Properties' link from the pop-up menu 点击弹出菜单中的“属性”链接
  3. Click the 'Libraries' link in the Categories list 单击类别列表中的“库”链接
  4. Choose 'Add JAR/Folder', browse to your JAR and click OK 选择“添加JAR /文件夹”,浏览到您的JAR,然后单击“确定”。

If you want Netbeans to create the JAR for the sources you have, do like Stefano says. 如果您希望Netbeans为您拥有的源创建JAR,请像Stefano所说的那样做。

You should package the src folder as src.zip with a zip utility and the structure under lib with the java archiver as a jar file. 您应该使用zip实用程序将src文件夹打包为src.zip,将带有Java归档程序的lib下的结构打包为jar文件。

Now you can define a library in NetBeans and add these files to it (Tools => Libraries => New Library). 现在,您可以在NetBeans中定义一个库并将这些文件添加到其中(工具=>库=>新库)。

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

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