简体   繁体   中英

jar file getting executed

I am working with a jar file. What I need to do is to add one of its component to a panel in my tabbed pane. Now the thing is, when I added its component to my Jpanel, the whole jar file gets executed (Yes, It's an executable jar file). Can someone help me on it? Here are 4 LOC's

JComponent panel_exp = new JPanel();
MyClass exp = new MyClass();
panel_exp.add(exp);
tabbedPane.addTab("Experiment", panel_exp);

But when it compiles, MyClass jar file gets executed and not my project that I'm importing this jar file in. I'm using Eclipse IDE.

First of all, it looks like you don't fully understand what does "executable jar" mean, so I'll try to explain.

The notion of executable jar has nothing to do with importing the jar as a dependency into your project.

"Executable jar" is just a regular jar, the only difference is that it can be run standalone, with the help of

java -jar your_jar.jar

So, the jar has a special entry in its MANIFEST.MF file, so that java would figure out what main class should be run in this case. That's it.

Now when you're importing the jar into your IDE you have nothing to do with the "executability" of this jar, you just don't take it into consideration.

So, the issue is probably in the configuration of your ide, you should take a look on what class gets executed and how when you hit "play" button :)

To get a deeper answer you should elaborate on what means "the whole jar gets executed"

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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