JAR File Import Problem [message #1827759] |
Fri, 22 May 2020 11:04  |
Eclipse User |
|
|
|
Hi guys, I followed the instruction of this video on how to export and import JAR file. It doesn't seem to work.
Look up "What is Jar file? | How to make a Jar in Eclipse?" by Telusko on Youtube.
So I exported Simple_Program folder, which contains CalDemo.java, the code is:
package Cal;
public class CalDemo {
public int add(int i, int j) {
return i + j;
}
}
Then, I exported the project folder Simple_Program as Calculator.jar (JAR file). Then I created Simple_Program2, inside project folder, I cretead class CalDemo2.java.
package Cal2;
import Cal.CalDemo;
public class CalDemo2 {
public static void main(String[] args) {
CalDemo c = new CalDemo();
System.out.println(c.add(4, 8));
}
}
Then, I imported Calculator.jar via "Add External JAR Files" into Simple_Program's Referenced Library. CalDemo.class appears in the .jar file branch instead of CalDemo.jar. Then, when I click on CalDemo.class, it says Source Not Found. So, when I run CalDemo2.java, I am getting an error. Error message attached in image below.
Also, I tried to assigned path to CalDemo.class and it's not working either. Now, I cannot re-assign path to that file.
Attachment: z.bmp
(Size: 5.15MB, Downloaded 76 times)
|
|
|
Re: JAR File Import Problem [message #1827765 is a reply to message #1827759] |
Fri, 22 May 2020 15:35  |
Eclipse User |
|
|
|
Quote:... when I click on CalDemo.class, it says Source Not Found
That shouldn't surprise. Normally, jars don't contain sources. You could either explicitly include sources in the jar, or provide a source attachment, but neither is required for running.
Concerning the runtime error I suggest to open the Run configuration and visit the Dependencies tab. Does it show your jar file on the classpath? You may also click "Show Command Line" to see exactly how the application is run.
|
|
|
Powered by
FUDForum. Page generated in 0.03816 seconds