Solved

how to access a project in Eclipse from outside Eclipse

Posted on 2012-03-26
64
482 Views
Last Modified: 2012-03-29
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
0
Comment
Question by:onyourmark
  • 35
  • 25
  • 4
64 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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;...
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Better way would be to create executable .jar file
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
0
 

Author Comment

by:onyourmark
Comment Utility
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)?
0
 
LVL 3

Expert Comment

by:Peter Haussl
Comment Utility
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.
0
 

Author Comment

by:onyourmark
Comment Utility
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.
0
 
LVL 3

Expert Comment

by:Peter Haussl
Comment Utility
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
 

Author Comment

by:onyourmark
Comment Utility
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)
0
 
LVL 3

Expert Comment

by:Peter Haussl
Comment Utility
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.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 

Author Comment

by:onyourmark
Comment Utility
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.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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.
0
 
LVL 3

Expert Comment

by:Peter Haussl
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 

Author Comment

by:onyourmark
Comment Utility
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.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
>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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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)
0
 

Author Comment

by:onyourmark
Comment Utility
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.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 

Author Comment

by:onyourmark
Comment Utility
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"
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 

Author Comment

by:onyourmark
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 

Author Comment

by:onyourmark
Comment Utility
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.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
 

Author Comment

by:onyourmark
Comment Utility
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.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
>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
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:onyourmark
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
 

Author Comment

by:onyourmark
Comment Utility
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
0
 

Author Comment

by:onyourmark
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 

Author Comment

by:onyourmark
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 

Author Comment

by:onyourmark
Comment Utility
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
0
 

Author Comment

by:onyourmark
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
>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
0
 

Author Comment

by:onyourmark
Comment Utility
No I want to do it manually, not with eclipse.
0
 

Author Comment

by:onyourmark
Comment Utility
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)?
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
and report to me that it is executing as you want from within eclipse
0
 

Author Comment

by:onyourmark
Comment Utility
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.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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 ?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
Comment Utility
OK, assuming that you don't have any pacakge in you JavaWeka...

Copy the bin folder form your eclipse project to a fresh clean space outside of any eclipse area

Copy to that bin_copy the JavaWeka....._update5.class file

Copy to that bin_copy  folder all your jars which you used in elclispe prroject


Open dos command line and go to that bin_copy folder

then start your execution like that:

java -cp .\;xmlParserAPIs-2.2.1.jar;.\gdata-finance-meta-2.0.jar;.\...(name all your jars in the same way here)    JavaWekaJ48TestTrainPredSQL_updated5
0
 

Author Closing Comment

by:onyourmark
Comment Utility
THANK YOU SO MUCH (as always) for your help. I think I should try it another way for now.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
SO you didn't try it this way as in the last posting?
0
 

Author Comment

by:onyourmark
Comment Utility
Ok, I am going to try it now.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Try, I think it should work if it is in general compatible
0
 

Author Comment

by:onyourmark
Comment Utility
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>
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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!
0
 

Author Comment

by:onyourmark
Comment Utility
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)
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
 

Author Comment

by:onyourmark
Comment Utility
Thanks again. It is working it seems except for the credentials. I will try to get that fixed.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
It seems this google piece requiressome authentication - make sure you are providing valid user/password to access those
0
 

Author Comment

by:onyourmark
Comment Utility
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."
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

762 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now