how to access a project in Eclipse from outside Eclipse

Hello. I have a project in Eclipse that seems to run. I have attached a screen shot. I also have a class file that I have been running from the command line. The class file is my main program. And since I am comfortable with the command line I want to continue to run it from there. The project in Eclipse (GoogleFinanceAndMail) has some functionality I want to use. I want to instantiate an instance of the what is in GoogleFinanceAndMail and use it. I am wondering how I access this project (GoogleFinanceAndMail)? Do I have to add something to the class path? And what if I want to move the whole thing to another computer, how do I do that? I am attaching the code where I instantiate GoogleFinanceAndMail. It begins on line 60 and goes to line 71.
Also, it requires a set of jar files that I downloaded from Google to access Google's API. Do I need to add each one into the CLASS PATH or is there an easier way? I am attaching a screenshot of the jar files as well.screen-shot-of-google-finance-pr.PNGsampleToAskAboutAccessingEclipse.javalibJar.PNG

I tried the steps for making an executable jar. I had already added in the external jar files using the Java Build Path and adding External Jars.
Does that mean that if I use the executable jar file I don't have to worry about the classpaths for these external jars?

In the file I attached to this question called sampleToAskAboutAccessingEclipse.java
on line 63 it declares an instance of the classes in the executable jar like this:
FinancePortfoliosClient cl = new FinancePortfoliosClient("from-mail.com","to-mail.com", "password");

What do I have to do now to make this executable jar (I called it test.jar) available to my program (sampleToAskAboutAccessingEclipse.java)?

You need to insert related "runtime configuration during creation". And class needed needs to contain related function in order to allow execution.....

public static void main(String[] args) {
}

Find attached some screenshots taken from Eclipse 3.7

Alternativly you can also let the wizard produce external directory containing all dependant classes and api's (Exluding those delivered from the JRE you are using)exporting-Runnable-Jar-file.pdf

0

onyourmarkAuthor Commented: 2012-03-27

Thank you for the screen shots. I used the "package required libraries into generated Jar" option and now when I double click the resulting executable jar it does not give the error about main class but nothing happens. I guess that might be a good sign.

If that is a good sign, how can I arrange things so that I can use this jar to run my code. Specifically, this line:

You need to add youtr third party jar files to your executable jar and add classpath to manifest file.
I'm not sure Eclipse does it automatically when you have third party jars, that's why you need to use the FatJar plugin, which I posed the link above.
It will make it much easier

The Fat Jar Eclipse Plug-In is a Deployment-Tool which deploys an Eclipse java-project into one executable jar.

It adds the Entry "Build Fat-JAR" to the Export-Wizard.
In addition to the eclipse standard jar-exporter referenced classes and jars are included to the "Fat-Jar", so the resulting jar contains all needed classes and can be executed directly with "java -jar", no classpath has to be set, no additional jars have to be deployed.

Jars, External-Jars, User-Libraries, System-Libraries, Classes-Folders and Project-Exports are considered by the plugin.
The Main-Class can be selected and Manifest-files are merged.
The One-JAR option integrates a specialised Class-Loader written by Simon Tuffs ( http://one-jar.sourceforge.net/ ) which handles jar-files inside a jar.
Individual files and folders can be excluded or added to the jar.
Different settings can be stored and re-executed as "Quick Build" via the context-menu.

<added> Just because as i saw your code you sent initially - if you have list containing nothing (list != null) in this case execution would be empty as well and programm executed not as expected but all classes needed are included </added>

at the end of the main method. This should point out if the problem is in the jarfile you produced or in the source before.

Having no exception would show that all dependencies are fullfilled.

Coming back to your inital question ...

If just calling the constructor is sufficiant or not matters basically on the actual content of the class.

You just need to make sure that you specify correct Run Configuration - the same which is running the project for you in eclipse itslef

Then make sure that checkbox "Package required libarayes into jar" is checked

Then specify where to put the executable jar

Then open dos cmd window go to the folder where you have executable jar

and in that folder type on the command line

java -jar Jar_name.jar

It worked for me right now.
Should work for you also.

Just double-clicking on jar may not always work, so test form the command line

0

onyourmarkAuthor Commented: 2012-03-27

Hi. I am really confused. I just want my system to be able to run the code in the file I originally attached (sampleToAskAboutAccessingEclipse.java). Actually I did not write the googlefinance code (the one that I made into an executable jar) and I really just wanted just a class that I could call from my sampleToAskAboutAccessingEclipse.java code but the person who created the googlefinance code used eclipse and so it is not a class but a whole project.

Perhaps if I add all the files in the lib folder to the class path manually (as described near the top of this discussion) this would be easiest.

By the way, in the screenshot, I forgot to say, the name of the project I am using is GoogleFinanceAndMail not Test or GoogleFinance.

You wrote:
"then you need to put on the classpath, and in this way yiou can start your application:

1) what is the -cp option?
2) I am not trying to run finance.google.TestFinananceModule as the main code, I am trying to run
sampleToAskAboutAccessingEclipse.java
so what is the command?

And do I follow these steps?
First do I have to set the class path with something like
set CLASSPATH=C:\folder\bin;c:\folder\lib\my.jar;...

And also, I should change any reference to the class to a fully qualified one
You wrote, "If your main class is within package you'll have to use fully qualified name of your starting class with all packages finance.google.TestFinanceModule". I think there is a main class in finance.google.GoogleFinanceAndMail but there is also a main class in sampleToAskAboutAccessingEclipse.java and I suppose that is the "true" main class for the whole of the code.

well, one thing - in most applciations bigger than Hello World, there are many classes and in one class you can create and use intances of another class, and then use third-party classes, so in fact you are not running "only one java file" - you are alwys running java application.
and java application is a collection of classes within the drirectory strictire (corresponding to packages) - and some of these classes you or your team created and so you have their sources and their classes are usually sitinng in the directory strauctire as class files. And also your application in most cases will use some classes from third party developwers and you'll not have source codes of those and you'll normally have those classes packaged in the .jar files. But inside your code - you'll use them basically in the same way as you use your own classes - isntaitaing instances of those classes and invoking methods on those instances.
So all these classes make up application - any you normally run the whole application - not one class.

Howeever within your application there may be one or serveral classes which have
public static void main(String args) method.
Those classes whch have this method can be used to start your application and
using different such "main" classes - you'll be starting your application from different "ends". Most probably you'll still use majority of all cvlasses prsent but because the main methdo is different you'll use them in different order and in this way you can achieve different functionality.
So starting with different main classwes you'll manipulate in different ways with the same collection of objects.
So if you do not meat to execute the main method in finance.google.GoogleFinanceAndMail
but rather the main method in
sampleToAskAboutAccessingEclipse class - thatis perfectly fine - you still normally will need
to have all of your classes compiled and present but you'll use them in different order
and thus may achive different resulst.

if there is no package statemnt in the begonning of the file - then it is called "default" pacakge;
then you jsut start

java sampleToAskAboutAccessingEclipse

(assume that there is no package statement on top of the latter java file)

0

onyourmarkAuthor Commented: 2012-03-27

Thank you. This was very helpful "Those classes whch have this method can be used to start your application and using different such "main" classes - you'll be starting your application from different "ends". " and in fact that entire comment was very helpful.
So, I will be using the file called sampleToAskAboutAccessingEclipse, which is one of the files that has a main method in it, to start the program.

Now is the package called GoogleFinanceAndMail or is it called finance.google? I guess from what you have said above that the package is finance.google and the project name is GoogleFinanceAndMail and that this project name has nothing to do with referencing the classes.

I created the executable jar. The latest version is called test3.jar. I have put in in the CLASSPATH variable as well.

did you create executable jar with eclipse after all or you just specified classpath enumerating all jars manually?

if the latter is true, then check if you by chance omitted some jar

0

onyourmarkAuthor Commented: 2012-03-28

I am attaching the steps I used to make the executable jar. You can see how at the beginning I added the jars in the libs folder. I selected all of them at once in the dialog box called JAR Selection that is a file chooser.steps-to-make-executable-jar.pdf

this morning
with one of my simple projects and I got vereything packaged into jar and was able to execute this jar
with command j

java -jar jar_name.jar

Didn't you try it this way?

Ecexecutable jar relies on the particluar run configuration,
so for raunning form one "main" class and running for another "main"
class you'll need to create two different executable jars.

Other than that I would still try to do it this way.
You should be sure first that you have appropruiate run configuration and
and check that this run configuration is executing without mistakes from eclipse enviroenemnet
in the normal eclipse way

also make sure to chack that the checkbox
package in depenedent jars (or soemthing like that)
is checked

and in this way you'll avoid choseing and selecting jars manually

0

onyourmarkAuthor Commented: 2012-03-28

Hi. I did not do

java -jar jar_name.jar

because the file I want to run (and the main method I want to run) is in the file

sampleToAskAboutAccessingEclipse.java
(in the error message I showed above I called this same file "JavaWekaJ48TestTrainPredSQL_updated5" and so I ran it like
java JavaWekaJ48TestTrainPredSQL_updated5).

I don't know if it is incorrect, but it is not undersatdnable to me
How cna you call the same file
this way
sampleToAskAboutAccessingEclipse.java
and this way
JavaWekaJ48TestTrainPredSQL_updated5

all this is not quite understandble

So my fisrt question is - can you run your applictaion in Eclipse
in noraml way as people noramlly run it in IDE ?

If you can - you must have run configuration which works for you
(Run Configuration is the place where you indeicate which is the "main" class)

If you have all that, why would not you just follow
the way they do it in the lionk I posted above?

0

onyourmarkAuthor Commented: 2012-03-28

Hi. Very sorry for the confusion.

I have two names for the same code.

sampleToAskAboutAccessingEclipse.java
and
JavaWekaJ48TestTrainPredSQL_updated5.java

I also have the executable jar which I created from the GoogleFinanceAndMail Eclipse project. This executable is called

test3.jar.

This test3.jar executable jar contains code that allows me to access the Google Finance API. But the code in JavaWekaJ48TestTrainPredSQL_updated5.java is my main code and does a lot more than access Google Finance. But within JavaWekaJ48TestTrainPredSQL_updated5.java I need to access the Google Finance API and that is why I need to have access to test3.jar.

So I did not think I want to run this command:

java -jar test3.jar

because that is not the main code. The main code is in JavaWekaJ48TestTrainPredSQL_updated5.java but within there I need to access Google Finance and so I also need test.jar.

However, when I tried to run JavaWekaJ48TestTrainPredSQL_updated5.java, I get the following:

this is fine, don't pay attention to the warnings
if your googglefinace which you need to access are in test.jar, then you need to have it in the same dfolder and run it like that:

java -cp .\;.\test.jar JavaWekaJ48TestTrainPredSQL_updated5

0

onyourmarkAuthor Commented: 2012-03-28

Thanks. I moved it to the same folder and ran as java -cp .\;.\test.jar JavaWekaJ48TestTrainPredSQL_updated5 but I got an error. Then I ran as
java JavaWekaJ48TestTrainPredSQL_updated5 and got a different error (see below). My classpath is here:

C:\Users\Bill\Desktop\chatvestor\test>java -cp .\;.\test.jar JavaWekaJ48TestTrainPredSQL_upd
ated5
Exception in thread "main" java.lang.NoClassDefFoundError: weka/classifiers/Classifier
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getMethod0(Class.java:2685)
at java.lang.Class.getMethod(Class.java:1620)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:484)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:476)
Caused by: java.lang.ClassNotFoundException: weka.classifiers.Classifier
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more

If you need test.jar then add it to CLASSPATH variable, if everything elase in CLASSPATH variable -cp switch will override your CLASPATH and you'll lose what is on the CLASSPATH
so don't combine two methods - use consistently one of the two methods

0

onyourmarkAuthor Commented: 2012-03-28

Hello. I have both weka.jar and test3.jar in my system classpath variable:

In that case shouldn't I run
java JavaWekaJ48TestTrainPredSQL_updated5

But I get the error:
C:\Users\Bill\Desktop\chatvestor\test>java JavaWekaJ48TestTrainPredSQL_updated5
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gdata/util/Authenticat
ionException
at JavaWekaJ48TestTrainPredSQL_updated5.main(JavaWekaJ48TestTrainPredSQL_updated5.ja
va:63)
Caused by: java.lang.ClassNotFoundException: com.google.gdata.util.AuthenticationException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1 more

0

onyourmarkAuthor Commented: 2012-03-28

Hello. I have both weka.jar and test3.jar in my system classpath variable:

In that case shouldn't I run
java JavaWekaJ48TestTrainPredSQL_updated5

But I get the error:
C:\Users\Bill\Desktop\chatvestor\test>java JavaWekaJ48TestTrainPredSQL_updated5
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gdata/util/Authenticat
ionException
at JavaWekaJ48TestTrainPredSQL_updated5.main(JavaWekaJ48TestTrainPredSQL_updated5.ja
va:63)
Caused by: java.lang.ClassNotFoundException: com.google.gdata.util.AuthenticationException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1 more

Thanks. I cannot really use eclipse. That is why I wanted to use the command line. My main code is just in one class file and I have been running it without problem
(as java JavaWekaJ48TestTrainPredSQL_updated5)
but now I have this extra google.finance and it was done in eclipse but that is only the small functionality of accessing google finance. My main code is just in one class file that I run through the command line. I don't know how to use eclipse well.

It is suspicious why you run it form
this folder
C:\Users\Bill\Desktop\test bed\bin\finance\google>

and not from this folder:

C:\Users\Bill\Desktop\test bed\bin>

Youshould copy the bbin folder andf do everything in that copy folder and run from there - read attetively wbhhat I wrote - it is all important!

0

onyourmarkAuthor Commented: 2012-03-29

Hi. OK, now it is looking better. I did it in the bin folder. I am now getting an error about Invalid Credentials. It says Captcha required. When I ran just the Eclipse code in Eclipse (in other words not the JavaWekaJ48TestTrainPredSQL_updated5 file) it said there were some errors "Errors exist in required project" "Proceed to launch?" but it did run and get the results from Google but here it does not and says captcha required.

Well this is absolutely another story - invalid credentials - perhaps to login somehwere - this inside your aplication. - it is insignificant that it was running in eclipse - it was saying that there are some errors in differnet part of the project not exactly within your execution path. In this case your execution path is different and you need to know where youi have wrong credentials. Think what credentials you are providing and try to understand.

0

onyourmarkAuthor Commented: 2012-03-29

Thanks again. It is working it seems except for the credentials. I will try to get that fixed.

Once the user has successfully responded to the challenge, the Google
server will trust the computer in use. The application can then resend
the original login request to obtain the authentication token."

Featured Post

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.