0

first of all, i've searched for some related topics, and already tried the solutions pointed in those, but still have some problems, so i'll try to explain it here hoping for a solution.

I'm trying to compile a java program which's already working on eclipse, on command line. The .jar file and the java files are all in same directory, the class i'm trying to compile is NOT in the .jar, but in this class i used some methods belonging to that .jar (paillier.jar)

I first tried this:

javac -cp paillier.jar CoupleGen.java
java -cp paillier.jar CoupleGen

First line gives CoupleGen.class and no problems for the moment, when i type the second line it gives me the error

Error: Could not find or load main class CoupleGen

So, reading some topics in here i tried another way

javac -cp paillier.jar CoupleGen.java
java -cp .;paillier.jar CoupleGen

and the result is a list of "how-to-use" java command with the end of these lines

paillier.jar command not found

So, i clearly make some mistakes, but actually i can't understand. Just in case it's needed, i set up ambient variable.

Any help is really appreciated.

Cheers

Here's the code i'm trying to compile

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Random;

import paillierp.key.KeyGen;
import paillierp.key.PaillierKey;
import paillierp.key.PaillierPrivateKey;


public class CoupleGen {

    public static void main(String[] args) throws IOException{
        //Creo un messaggio m da criptare

        //for (int j=1; j==2; j++){

                int nodeID=5;
                int s=32;
                Random random = new Random();
                long seed = random.nextLong();
                PaillierPrivateKey pr= KeyGen.PaillierKey(s, seed);
                PaillierKey pu= pr.getPublicKey();
                System.out.println("PublicKey:("+pr.getN()+","+pr.getNPlusOne()+")");
                String pubkey ="PublicKey"+nodeID;
                    FileWriter File= new FileWriter(pubkey);
                    PrintWriter out=new PrintWriter(File);
                    out.println("n:" + pu.getN());
                    out.println("n+1:" + pu.getNPlusOne());
                    out.println("n^s:" + pu.getNS());
                    out.println("n^s+1:" + pu.getNSPlusOne());
                //  out.println("rnd:" + pu.getRnd());
                    out.println("k:" + pu.getK());  
                    out.close();
        //} for not working on this pc
    }
}
Elia
  • 25
  • 1
  • 6

3 Answers3

2

>> paillier.jar command not found

This sounds like you're running this on Linux or Mac, and the command line interprets this as two different commands because of the semicolon ;:

java -cp .
paillier.jar CoupleGen

The semicolon is used as path-separator on Windows only, on Linux and Mac one should use the colon :. So try running you're code like that:

java -cp .:paillier.jar CoupleGen
cello
  • 5,356
  • 3
  • 23
  • 28
  • BarrySW19 beat me with a comment, but had the same idea. – cello Dec 23 '14 at 09:39
  • (yep, running on xubuntu) with this colon it gives me the error Error: Could not find or load main class CoupleGen And seeing another answer, i've to point out that my class isn't in paillier.jar – Elia Dec 23 '14 at 10:41
1
javac -cp C:\...\yourjarfile.jar; javafile.java

This works in the Windows command prompt very easily. Do not forget to write -cp, semicolon(;) , .jar, .java extensions and later run it with java C:\...\yourjavafile.java. You can have you directory changed from c to d or e.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
0

when you are executing below line, you are getting the below error right ?

javac -cp paillier.jar CoupleGen.java

Error: Could not find or load main class CoupleGen

That means compiler is looking for the CouplenGen.java in paillier.jar. Actually CoupleGen is outside of the jar file.

Venkat Kondeti
  • 81
  • 1
  • 12
  • Do one thing, make one jar file using your entire project in the eclipse. procedure for making jar file is – Venkat Kondeti Dec 23 '14 at 09:51
  • Do one thing, make one jar file using your entire project in the eclipse. procedure for making jar file is right click on your project->export->java->runnable jar file->click on next. Then select CoupleGen in launch configaration dropdown box -> select required libraries into generated jar ->finish. Now open cmd ->goto the jar file path in cmd-> then give the command -> java -jar jarFileName. thats it, it will execute automatically. – Venkat Kondeti Dec 23 '14 at 09:57
  • Ok, it worked, thank you very very much. The problem now is that i'll have to execute more of this java programs, i'll have to create one .jar file for everyone of em to execute em? Isn't there a way like javac->java? – Elia Dec 23 '14 at 10:50
  • i didn't get your question. what "em" means? And give me some clarity, what is your requirement exactly? – Venkat Kondeti Dec 23 '14 at 10:59
  • em means other java programs. I'll explain myself better, i'm going to run some java program one after another, like, Couplegen.java for generating a couple of keys, Extract.java to extract keys from file. Depending on the situation, i have to create bash scripts (or something similar, still working on it) with those java programs. – Elia Dec 23 '14 at 11:06
  • if each .java file is an individual java project then create a jar file for each java program. Then write a code some thing like this in another java file. public class DriverProgram{ public static void main(String[] args){ Runtime.getRuntime().exec("cmd.exe /c start java -jar Demo.jar"); Runtime.getRuntime().exec("cmd.exe /c start java -jar Demo1.jar"); Runtime.getRuntime().exec("cmd.exe /c start java -jar Demo1.jar"); } } The above program will execute jar files one by one in cmd promt. – Venkat Kondeti Dec 23 '14 at 11:18
  • Ok, you solved all my problems, thanks, thanks very much! Whishing you a merry Christmas :) – Elia Dec 23 '14 at 11:20
  • Thanks Elia and wish you the same. This is my first answers to the question in stackoverflow. Please click on appcet button (right mark). you can find the right mark at left to the first line of my answers. Such that ill get some reputation points. – Venkat Kondeti Dec 23 '14 at 11:37
  • Done, wish you the best :) – Elia Dec 23 '14 at 11:45