Link to home
Start Free TrialLog in
Avatar of onyourmark
onyourmark

asked on

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.PNG
sampleToAskAboutAccessingEclipse.java
libJar.PNG
Avatar of for_yan
for_yan
Flag of United States of America image

Yes, you can move your project as a whole folder to another place say to folder C:\folder

let's assume thet your jars are in the folder lib of your project

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

java -cp C:\foolder\bin;c:\folder\lib\myjar1.jar;c:\folder\lib\myjar3.jar...  finance.google.TestFinanceModule
Yes, you'll have to enumerate all your jar files in your classpath

classpath can be soecified either on command line as I showed or beforehand

set CLASSPATH=C:\folder\bin;c:\folder\lib\my.jar;...
Id your main class is within package you'll have to use fully qualified name of your starting class with all packages  finance.google.TestFinanceModule
Better way would be to create executable .jar file
Avatar of onyourmark
onyourmark

ASKER

Hello. Thank you!

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)?
Yes .... The export function from Eclipse is taking care on adding all needed classes into the executeable file ...

You just need to tick the tick on to include needed classes on the Project Export dialog.
Thanks. I am getting an Jar file “cannot find main class” error message when clicking on the jar file. But I did select the java file with the main in it when creating the jar.
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
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:

FinancePortfoliosClient cl = new FinancePortfoliosClient("from-mail.com","to-mail.com", "password");

 in my code requires the classes compressed in the executable jar (I called it test3.jar)
Well seems your program

At least it is better ... code is that one you atteched in your initial posting? or you changed meanwhile your main methode of your entry - class?

public static void main(String[] args) {
   FinancePortfoliosClient cl = new FinancePortfoliosClient("from-mail.com","to-mail.com", "password");  
}

After you can add something like cl.dothis(); cl.dothat(); whatever needs to be done in order to follow your required functionality. All within main method.
You can use fatjar eclipse plugin

http://fjep.sourceforge.net/

or OneJar application to do it:

http://one-jar.sourceforge.net/

Or you can expand all your jars into your bin folder and it will repcakage them together
Sorry, I meant, after I have created the executable, how do I let my program (the code I attached initially) know where this jar is and that it should use it and will this
 
FinancePortfoliosClient cl = new FinancePortfoliosClient("from-mail.com","to-mail.com", "password");

be enough to reference it?

Thanks again.
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

http://fjep.sourceforge.net/


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.
hi,

can you add some debug code like

System.out.println("*** Program finished ***");

<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.

br
Pet.
Changed 16:44 with some addtional explainations
I just followed the steps given here

http://askeralim.blogspot.com/2011/03/create-executable-jar-file-using.html

 with one of my projects in Eclipse and it works fine

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
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:

java -cp C:\foolder\bin;c:\folder\lib\myjar1.jar;c:\folder\lib\myjar3.jar...  finance.google.TestFinanceModule"

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.
>1) what is the  -cp  option?

so you can specify classpath in two ways.
One way is to set CLASSPATH env variable
and then start exceutio:

java fully_qualified_main_class_name

another way is to provbvide the classpath on the command line
In the latter cae you provide classpath after switch -cp after java command:

java -cp (at least one space)  (classpath here)  (at least one space here)  fully_qualified_main_class_name
You don't need to do both.
If you proveide classpath in env variable, then you don't need to have it on the command line
If your  "main" class is in the package, like

finance.google.TestFinance

(then its fierst statement (in Java code) must be

package finance.google;
\then you start it with fully qualified  name

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)
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.

Here are my results.


C:\Users\Bill\Desktop\chatvestor\test>javac JavaWekaJ48TestTrainPredSQL_updated5.java
Note: JavaWekaJ48TestTrainPredSQL_updated5.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

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

C:\Users\Bill\Desktop\chatvestor\test>

any ideas on this? Thanks.
the package is finace.google

project is GoogleFinanceAndMail

project is more or less synonymic to application

and project can have many packages

project or application name have nothing to do with referencing classes

the reason for the exception most probably is that  in classpath you are lacking jar which contains class
com.google.gdata.util.AuthenticationException

which is necessary for execution of your application
did you have all jars which we see in the snapshot in the classpath ?
i guess some of those google jars should contain this lacking class
I thought I created the executable jar after adding in those google jars as external jars. Maybe I need the fatjar?

P.S. This was helpful too "and project can have many packages"
well it should work

but I don't know how you finally did it

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
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
I am not sure I understand what is this picture about.

I actually strictly folloewed this instruction
http://askeralim.blogspot.com/2011/03/create-executable-jar-file-using.html

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
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).

But I did have the executable jar test3.jar in the classpath.

Is this incorrect?
Thank you.
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?
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:

C:\Users\Bill\Desktop\chatvestor\test>javac JavaWekaJ48TestTrainPredSQL_updated5.java
Note: JavaWekaJ48TestTrainPredSQL_updated5.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

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.
>C:\Users\Bill\Desktop\chatvestor\test>javac JavaWekaJ48TestTrainPredSQL_updated5.java
Note: JavaWekaJ48TestTrainPredSQL_updated5.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

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
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:\Program Files\Weka-3-7\weka.jar;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\Program Files\Weka-3-7\mysql-connector-java-5.1.18\mysql-connector-java-5.1.18-bin.jar;C:\Users\Bill\Desktop\chatvestor\test\test3.jar

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

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
don't understad what you are writing.

where are your clasess like com/google/gdata/util/...
are they in test3.jar ?
If so - put test3.jar in the calsspath

wherea are your clasess like
weka/classifiers/Classifier

in weka.jar  ?

make sure that weka.jar is in the classpath

make sure taht all classes which you need are on the classpath and then run

if you use CLASSAPTH as env varaible, then put everything in the env variable

otherwise put everything after -cp on the command line

Don't copmbine the two ways.
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
Hello. I have both weka.jar and test3.jar in my system classpath variable:

.;C:\Program Files\Weka-3-7\weka.jar;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\Program Files\Weka-3-7\mysql-connector-java-5.1.18\mysql-connector-java-5.1.18-bin.jar;C:\Users\Bill\Desktop\chatvestor\test\test3.jar

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
Hello. I have both weka.jar and test3.jar in my system classpath variable:

.;C:\Program Files\Weka-3-7\weka.jar;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\Program Files\Weka-3-7\mysql-connector-java-5.1.18\mysql-connector-java-5.1.18-bin.jar;C:\Users\Bill\Desktop\chatvestor\test\test3.jar

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
I think it means that you don't have

com/google/gdata/util/AuthenticationException.class

in your test3.jar

and understand that if you have some jar embedded in test3.jar which has that class inside that embedded jar then it is not enouough- you need to have this class in test3.jar in the folder structure

com/google/gdata/util/AuthenticationException.class

otherwise it would not work
How do I check if this is in my test.jar com/google/gdata/util/AuthenticationException.class ?

Here is a screen shot of the external jars I added to the project in eclipse.
lib-jar-files.PNG
copy test3.jar to test3.zip and open it with winzip

But if you have jars zipped-in into test3.jar and your class is in one of those
emvbeded jars - tthen it will not work this way
you need to put all those jars in the same folder explicitly (not inside any jars)
and add them one by one to your CLASSPATH
Here is my manifest

Manifest-Version: 1.0
Rsrc-Class-Path: ./ xmlParserAPIs-2.2.1.jar gdata-finance-meta-2.0.jar
  gdata-maps-2.0.jar gdata-core-1.0.jar gdata-client-1.0.jar servlet-a
 pi.jar google-collect-1.0-rc1.jar gdata-maps-meta-2.0.jar mail.jar ac
 tivation.jar gdata-client-meta-1.0.jar gdata-finance-2.0.jar
Class-Path: .
Rsrc-Main-Class: finance.google.TestFinanceModule
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
test3.jar has inside it the jar files in the attached screen shot. But how do I know if com/google/gdata/util/AuthenticationException.class  is in here?

Here is my manifest

Manifest-Version: 1.0
Rsrc-Class-Path: ./ xmlParserAPIs-2.2.1.jar gdata-finance-meta-2.0.jar
  gdata-maps-2.0.jar gdata-core-1.0.jar gdata-client-1.0.jar servlet-a
 pi.jar google-collect-1.0-rc1.jar gdata-maps-meta-2.0.jar mail.jar ac
 tivation.jar gdata-client-meta-1.0.jar gdata-finance-2.0.jar
Class-Path: .
Rsrc-Main-Class: finance.google.TestFinanceModule
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
tstjar.PNG
Once again, do you want to do it through eclipse - do it exactly as here

http://askeralim.blogspot.com/2011/03/create-executable-jar-file-using.html

and don't drop on top of it still one more java file - evrything should be there, should be Run Configuration ansd agaian everything as I was talking before

with another RunConfiguratein - create another new full jar file

I was thinkning that we are now doing it manually without eclipse.
with eclipsee follow the instruuctions
>But how do I know if com/google/gdata/util/AuthenticationException.class  is in here?

But I just told you - copy it to test3.zip and open with winzip -and look at the files there
No I want to do it manually, not with eclipse.
I did look at the files but I only see the 13 jar files in the screen shot I attached. Should I do the same with each of them (change to zip and look for it in each of them)?
Ok, forget about all of that
and follow my instaructions step by sterp exactly:

Go to your Eclipse project - excute in eclipse exactly as you want to execute it outside arrting with the same main class - and report to me that it is executing as you want
and report to me that it is executing as you want from within eclipse
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.
Ok, then it probably will not work as it never worked this way and was not dbugged properly, etc.

OK, does your JavaWekaJ48TestTrainPredSQL_updated5.java has any package statement at the very top of your code ?
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THANK YOU SO MUCH (as always) for your help. I think I should try it another way for now.
SO you didn't try it this way as in the last posting?
Ok, I am going to try it now.
Try, I think it should work if it is in general compatible
Hello. I put the weka.jar file in the folder as well. (Note also: From the Eclipse project there were several class files. )

Here is what I ran:

C:\Users\Bill\Desktop\test bed\bin\finance\google>java -cp .\;xmlParserAPIs-2.2.1.jar;.\acti
vation.jar;.\gdata-client-1.0.jar;.\gdata-client-meta-1.0.jar;.\gdata-core-1.0.jar;.\gdata-f
inance-2.0.jar;.\gdata-finance-meta-2.0.jar;.\gdata-maps-2.0.jar;.\gdata-maps-meta-2.0.jar;.
\google-collect-1.0-rc1.jar;.\mail.jar;.\servlet-api.jar;.\weka.jar JavaWekaJ48TestTrainPred
SQL_updated5
Exception in thread "main" java.lang.NoClassDefFoundError: finance/google/FinancePortfoliosC
lient
        at JavaWekaJ48TestTrainPredSQL_updated5.main(JavaWekaJ48TestTrainPredSQL_updated5.ja
va:63)
Caused by: java.lang.ClassNotFoundException: finance.google.FinancePortfoliosClient
        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

C:\Users\Bill\Desktop\test bed\bin\finance\google>
to what folder did you copy the whole bin folder form eclipse?

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!
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.

C:\Users\Bill\Desktop\test bed\bin>java -cp .\;xmlParserAPIs-2.2.1.jar;.\activation.jar;.\gd
ata-client-1.0.jar;.\gdata-client-meta-1.0.jar;.\gdata-core-1.0.jar;.\gdata-finance-2.0.jar;
.\gdata-finance-meta-2.0.jar;.\gdata-maps-2.0.jar;.\gdata-maps-meta-2.0.jar;.\google-collect
-1.0-rc1.jar;.\mail.jar;.\servlet-api.jar;.\weka.jar JavaWekaJ48TestTrainPredSQL_updated5
Invalid Credentials!
com.google.gdata.client.GoogleService$CaptchaRequiredException: Captcha required
        at com.google.gdata.client.GoogleAuthTokenFactory.getAuthException(GoogleAuthTokenFa
ctory.java:623)
        at com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(GoogleAuthTokenFactor
y.java:500)
        at com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(GoogleAuthToken
Factory.java:346)
        at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:362)
        at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:317)
        at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:301)
        at finance.google.FinancePortfoliosClient.loginUser(FinancePortfoliosClient.java:224
)
        at finance.google.FinancePortfoliosClient.<init>(FinancePortfoliosClient.java:83)
        at JavaWekaJ48TestTrainPredSQL_updated5.main(JavaWekaJ48TestTrainPredSQL_updated5.ja
va:63)
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.
Thanks again. It is working it seems except for the credentials. I will try to get that fixed.
It seems this google piece requiressome authentication - make sure you are providing valid user/password to access those
Yes. I have looked up the error. Seems that sometimes it happens. I saw this and tried it but still got the error.

Your application can direct the user to the Google hosted page:
https://www.google.com/a/yourdomain.com/UnlockCaptcha
Note: Please replace yourdomain.com with your domain name.

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."
well, that is way beyond your original question

I don't know how google.finance is organizes - I know usually with google you need to have an account ansd they send you some token which you need to  them for authentication.
perhpas read this:
https://developers.google.com/finance/docs/2.0/developers_guide_java#Authenticating