Solved

Packaging in Eclipse

Posted on 2008-06-11
6
367 Views
Last Modified: 2013-12-15
This should be incredibly easy, and I guarantee it's something simple that I "should know," and just remain ignorant of.

First off, I'm not a java developer. My company does not develop in java. However, they recently thought that it would be a smart idea to purchase a program that does something that we want to do, and it was written in java. The guy came, set up eclipse on my machine, gave me the files, set everything up so I click "run dialog", and throw in a couple command line arguments into there, and everything runs just fine, then he left. I guess he assumed I knew what to do.

After researching / reading around, I have concluded that I have zero idea what I'm doing.

So, I have code that runs fine in eclipse. I'm not in Kansas, or my cozy little VS anymore, and there is no effin "compile" button that spits out a wonderful .exe.

I have tried "Exporting" the project by using file->export, and then use the command of Java -jar jarname.jar, but when it does that, it says that it can't find a class in one of the jars that is referenced in the project.

It works. I've seen it work. I can use it if I go into eclipse and run it. I just need to be able to hit it as a command line execution. What am I missing / not doing?

Thanks
--Xen
0
Comment
Question by:darkxenn
  • 2
  • 2
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
mbodewes earned 250 total points
ID: 21764851
Basically you need to set up the classpath to point to the referenced libraries as well as the generated .jar file. But you might be better off packaging it all again into a .exe, which you seem to be more familiar with. Use jsmooth (open source0 or another packager to do that. You will have multiple options to included the referenced libraries.

Another way is to use java -cp "<full path to all .jar files separated by ;>" <the class containing the main excluding .class including package names separated by dots>. Most of the time I find -jar more difficult than this option, where the jar containing the main class is just part of the general classpath.

So something like java -cp "lib/main.jar;lib/log4j.jar" com.somecompany.main.Main


0
 
LVL 92

Expert Comment

by:objects
ID: 21764956
when your exporting your project as a jar there is an option to specify the main class. Specify the class name there and you should be right

0
 
LVL 9

Expert Comment

by:mbodewes
ID: 21765174
"I have tried "Exporting" the project by using file->export, and then use the command of Java -jar jarname.jar, but when it does that, it says that it can't find a class in /one of the jars/ that is referenced in the project."

Objects, if that was the main class, I suppose you would be right, but I wonder if this is the case. After reading the question I figured out it probably isn't, but maybe the author can explain further.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 1

Author Comment

by:darkxenn
ID: 21769436
"when your exporting your project as a jar there is an option to specify the main class. Specify the class name there and you should be right"

I already did that. The problem that I'm having is the jars included in the project. I'm gonna try out jsmooth here, and see how that goes.
0
 
LVL 1

Author Closing Comment

by:darkxenn
ID: 31466386
Thanks so much. Jsmooth was easy to deal with, and I got everything settled in no time.
0
 
LVL 92

Expert Comment

by:objects
ID: 21774293
Thats more likely to be a problem with where the jars are placed. Executable jars can access external jars just fine.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question