0

I have a program with multiple packages in my current Java Project.

I have also referenced some jars such as the Java Commons Library.

I am planning on releasing my program as a runnable jar files to the public, however when I was testing today, when I exported it and tried to run it. The files within the packages could not import that Java Commons Library. I know that changing classpath may fix this, but I have A TON of .java files and don't wish to write them 1 by 1. Also I do not know if the classpath changing technique will allow the compiled jar to work on ANYONE'S computer.

Is there a simpler / faster way to do it? Or is using the Change Classpath with console the only way?

(I am using Eclipse)

Thanks for any help!

user2804925
  • 247
  • 3
  • 11

1 Answers1

1

It is answered in another thread here. I've tried to concise the answer for your question below.

The files within the packages could not import that Java Commons Library.

Option 1: You need to ship Java Commons library along with your Jar and mention classpath (relative to your Jar) in your Jar's META-INF/MANIFEST.MF

Option 2: You may also place Java Commons library in lib folder inside your Jar

You might want to prefer option 2 since you deliver single jar (Fat Jar) instead multiple.

I have A TON of .java files and don't wish to write them 1 by 1

Just setting classpath would not require you to change your Java files.

Also I do not know if the classpath changing technique will allow the compiled jar to work on ANYONE'S computer.

I don't know how you want to change classapth. But it certainly works if you choose Option 1 above.

Is there a simpler / faster way to do it? Or is using the Change Classpath with console the only way?

Eclipse has FatJar plugin to do this.

Community
  • 1
  • 1
kotacc
  • 327
  • 2
  • 12