当前位置: 动力学知识库 > 问答 > 编程问答 >

In java, how do you import one project into another without having them in the same (Eclipse) workspace?

问题描述:

I've been a c++ programmer for 10 years, i'm used to just creating libraries and then linking to them from my existing project. However in java, i have 2 projects, one is my game engine, the other is the test environment that i would like to use, here is how it is structured:

com.logic.engine

com.logic.testapp

yet in my test app, i cannot do

import com.logic.engine.*;

it simply cannot find the reference.

How can I do this without having to copy and paste my engine into every program i write with it?

网友答案:

Package your engine as a jar, and add the jar to the classpath of the projects that use it.

网友答案:

In eclipse you can also declare that your test prgram depends on your game engine. The classes will then be available. Check in the build paths dialog available from the context menu in the project view.

网友答案:

In eclipse, right click on your test project in the Project Explorer and select Properties. In the "Java Build Path" section, go to the Projects tab and add your engine project.

网友答案:

You need to change the classpath to include the folder containing your engine.

java -cp /path/to/engine testapp

网友答案:

I just fired up Eclipse to check this out.

You should see a red wavy underline on import com.logic.engine.*; - mouse over this and it'll tell you that the import could not be resolved and offer you a number of so-called quick fixes. One of those should be Fix Project Setup - that will offer to fix things for you, in this case to add one project to the other's build path.

分享给朋友:
您可能感兴趣的文章:
随机阅读: