Jump to content

JAVA code to JAR

Lenidar
Go to solution Solved by wasab,

Try this.

 

java -jar myjarfile.jar

 

This is the command I always used for jar files.

Hello, Im kinda transitioning from C# and Python (maybe you could consider COBOL) to JAVA, so far everything has been the same except for sharing the code.

Im starting with console programs to familiarize myself with how things are coded. When I tried the export > runnable java file (On eclipse using the settings below) then double click the thing nothing happens, so I thought of running it in console because unline EXE files it might not run the console natively.

 

image.png.9be97227d2370a54172593ac36fec8e5.png

image.png.158979a14b4a108ec7afeeb85c39b1b8.png

Getting these warnings, these are just my other programs...

 

image.png.39bb72d2f58559856051230337b28d98.png

Here's what I get when I run it on console, same as when I compile the class files using JAVAC...

 

If you can help me, or direct me to the answer, I would be very grateful :)

 

Processor : i7-6700k (stock speed)

Cooler : Hyper 212X

Motherboard: MSI Krait Gaming Z170

RAM : 4x4gb LPX Memory

Boot Device : Samsung 860 EVO

GPU : ZOTAC 1070 Extreme

PSU :Antec HCG-620M

Link to comment
Share on other sites

Link to post
Share on other sites

I tried to get all the details in, but if it would help, this code is not yet in OOP, so its just the main class that does all the work and yes it runs in eclipse.

Processor : i7-6700k (stock speed)

Cooler : Hyper 212X

Motherboard: MSI Krait Gaming Z170

RAM : 4x4gb LPX Memory

Boot Device : Samsung 860 EVO

GPU : ZOTAC 1070 Extreme

PSU :Antec HCG-620M

Link to comment
Share on other sites

Link to post
Share on other sites

I haven't done any Java in a while but I don't think that you should be getting those warnings. If you are exporting your project into a jar, only the current project should be taken into consideration and not the other ones. This and the fact that it can't find the main function make me think that there's a configuration issue with the export part.

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, IAmAndre said:

I haven't done any Java in a while but I don't think that you should be getting those warnings. If you are exporting your project into a jar, only the current project should be taken into consideration and not the other ones. This and the fact that it can't find the main function make me think that there's a configuration issue with the export part.

is there any fix to it? ive tried it on 2 of my machines and im getting the same errors...

Processor : i7-6700k (stock speed)

Cooler : Hyper 212X

Motherboard: MSI Krait Gaming Z170

RAM : 4x4gb LPX Memory

Boot Device : Samsung 860 EVO

GPU : ZOTAC 1070 Extreme

PSU :Antec HCG-620M

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Lenidar said:

is there any fix to it? ive tried it on 2 of my machines and im getting the same errors...

Can you try deleting all the other projects and retry?

Link to comment
Share on other sites

Link to post
Share on other sites

Try javac from the command line. 

cd into your project folder 

 

Then javac *.java

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, IAmAndre said:

Can you try deleting all the other projects and retry?

I have, same error... not really an error, it just cant find the main class

Processor : i7-6700k (stock speed)

Cooler : Hyper 212X

Motherboard: MSI Krait Gaming Z170

RAM : 4x4gb LPX Memory

Boot Device : Samsung 860 EVO

GPU : ZOTAC 1070 Extreme

PSU :Antec HCG-620M

Link to comment
Share on other sites

Link to post
Share on other sites

15 minutes ago, IAmAndre said:

Can you try deleting all the other projects and retry?

even tried making a whole new project just for this.

 

22 minutes ago, wasab said:

Try javac from the command line. 

cd into your project folder 

 

Then javac *.java

Tried this, getting this error
image.png.f3cd6af21aaabef7071122308221f3a2.png

Processor : i7-6700k (stock speed)

Cooler : Hyper 212X

Motherboard: MSI Krait Gaming Z170

RAM : 4x4gb LPX Memory

Boot Device : Samsung 860 EVO

GPU : ZOTAC 1070 Extreme

PSU :Antec HCG-620M

Link to comment
Share on other sites

Link to post
Share on other sites

Hm.... What version of java you have? 

 

Can you post a snippet of your code? 

 

From the looks of it, the code compiles fine. Its when running the jar, it throws you an error.

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, wasab said:

Hm.... What version of java you have? 

 

Can you post a snippet of your code? 

 

From the looks of it, the code compiles fine. Its when running the jar, it throws you an error.

Sure thing, this is the version of my java...

image.png.a41ca3ee0ef1c00f886c9b5da1403d76.png

 

Here is my code:

package testingJAR;

import java.util.HashMap;
import java.util.Scanner;

public class JARTest {public static void main(String[] args) 
{
	// TODO Auto-generated method stub
	HashMap<String, Integer> wordCount = new HashMap<String, Integer>();
	Scanner in = new Scanner(System.in);
	String input = "";
	String[] words = {};
	int maxWords = 0;
	int wordTotal = 0;
	
	System.out.println("Input paragraph:");
	input = in.nextLine().toUpperCase();
	words = input.split(" ");
	maxWords = words.length;
	
	for(String word: words)
	{
		if(wordCount.containsKey(word))
		{
			wordCount.put(word, wordCount.get(word) + 1);
		}
		else
		{
			wordCount.put(word, 1);
		}
	}
	
	for(String k: wordCount.keySet())
	{
		System.out.println("Word : " + k + "\t Number of Instances : " + wordCount.get(k));
		wordTotal += wordCount.get(k);
	}
	
	System.out.println("\n\nNumber of Unique Words: " + wordCount.size() + "\nWord Count: " + maxWords + "\nTotal Instances:" + wordTotal);
	
	
	
}

}

 

Processor : i7-6700k (stock speed)

Cooler : Hyper 212X

Motherboard: MSI Krait Gaming Z170

RAM : 4x4gb LPX Memory

Boot Device : Samsung 860 EVO

GPU : ZOTAC 1070 Extreme

PSU :Antec HCG-620M

Link to comment
Share on other sites

Link to post
Share on other sites

Try this.

 

java -jar myjarfile.jar

 

This is the command I always used for jar files.

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, wasab said:

Try this.

 

java -jar myjarfile.jar

 

This is the command I always used for jar files.

WELL HOT DAMN! IT WORKED! THANKS A BUNCH!
 

Quote

From the looks of it, the code compiles fine. Its when running the jar, it throws you an error.

Do want to know why this is though...

Processor : i7-6700k (stock speed)

Cooler : Hyper 212X

Motherboard: MSI Krait Gaming Z170

RAM : 4x4gb LPX Memory

Boot Device : Samsung 860 EVO

GPU : ZOTAC 1070 Extreme

PSU :Antec HCG-620M

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Lenidar said:

WELL HOT DAMN! IT WORKED! THANKS A BUNCH!
 

Do want to know why this is though...

Java wasn't able to locate the main class. Eclipse usually do the com.project.src path thingy so command needs to be java com.project.src.mainclass.

 

Using -jar will have java look for the jar's manifest file (created by eclipse) which specify the main class so you don't need to do that. 

 

 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×