Running .jar error main class not found.

Don’t expect less than 10 MB except if you use this JEP:
http://openjdk.java.net/jeps/148

In that case, you’re just looking for the -source and -target options. See this for more info: http://stackoverflow.com/questions/18162519/set-java-complier-compliance-level

You might also check out JWrapper: http://www.jwrapper.com/

JWrapper gets the JRE down to 7MB, and it also includes an option to only download a JRE if the user doesn’t already have the correct version.

Um, that’s great! Thanks for the links! :slight_smile:

I get a warning:
warning: [options] bootstrap class path not set in conjunction with -source 1.6

Trying to follow another questions answer:

javac -target 1.4 -bootclasspath jdk1.4.2/lib/classes.zip
-extdirs “” OldCode.java

Having trouble finding the zip folder, I downloaded an old JRE, 1.4.

Can I just point to the rt.jar?

JWrapper seems somewhat confusing to use.

Edit: the error says 1.6 because I c/p from the above link.

Oo interesting I compiled for 1.5 and created a jar, ran it, and now I’m getting the exact error my friend is getting(Java Virtual Machine Launcher: Could not find the main class!) . When double clicking on it.
When I run it from the command line, it runs fine?

Looks like the best solution is to just figure out how to get JWrapper to work, and use that

Edit:

Odd now I can’t seem to run jar’s by double clicking at all now. Just get that error message after downloading jre 1.4

Edit:

Exception using JWrapper - probably not doing it right - any help is appreciated

Folder source cannot be part of classpath!

I think I am misunderstanding what the classpath is?

The stacktrace is very long…hard to type all of that out

java.lang.Exception @ jwrapper.JWrapperCompiler.main(JWCompiler.java:112)

Oh and, Merry Christmas everyone.

So this is frustrating. I got the JWrapper compile to work, so I have everything in a “JWrapperBuild” folder, not errors were produced, but when I try to run the application it doesn’t run however java does start as a process. But program doesn’t actually seem to be running ???

Edit: I’ve tried a bunch of different stuff but the same problem. I’m going to try and change the code so the main method isn’t inside a main class that extends JFrame, and hopefully it runs properly. If not I’m out of ideas.

Edit2:

Yeah that didn’t work.

anyone know what I’m doing wrong with this JWrapper business? There are no errors…The application kind of just starts and sits idle…

Edit3:

Tried jwrapping sample project. javax.image.io.IIOException: Can’t read input file!

Also get this error when I try to use the sample xml as a template, as opposed to using the application to generate one.

You haven’t really posted a lot of info about what you’re doing with JWrapper, so it’s really hard to help you.

You might want to post a zip file of your example directory, JWrapper XML file, etc. That way we can try it out.

You also might want to post on the JWrapper forums. They’ve been pretty helpful for me in the past.

Thanks. Their forums are down or something, and for now they’re using stackoverflow. No reply yet.

Trying to find how to attach zip.


import java.awt.*;
import java.awt.Component;
import java.awt.event.*;


public class Game
{
	Draw draw;
	Frame frame;
	Insets insets;
	
	boolean isRunning = true;	
	
	
	private int FPS = 30;
	private double averageFPS;
	
	public static void main(String[] args)
	{
		Game game = new Game();
		game.run();
		System.exit(0);
	}
	
	void run()
	{
		initialize();
		
		long startTime;
		long URDTimeMillis;
		long waitTime;
		long totalTime = 0;
		
		int frameCount = 0;
		int maxFrameCount = 30;
		
		long targetTime = 1000 / FPS;
		
		while(isRunning)
		{
			startTime = System.nanoTime();
			
			update();
			draw();
			
			URDTimeMillis = (System.nanoTime() - startTime) / 1000000;
			
			waitTime = targetTime - URDTimeMillis;
			
			try
			{
				Thread.sleep(waitTime);
			}
			catch(Exception e)
			{
			
			}
			
			totalTime += System.nanoTime() - startTime;
			frameCount++;
			
			if(frameCount == maxFrameCount)
			{
				averageFPS = 1000.0 / ((totalTime / frameCount) / 1000000);
				frameCount = 0;
				totalTime = 0;
			}
		
		}
		
		frame.close();
	}
	
	void initialize()
	{
		
		
		draw = new Draw();
		frame = new Frame();
		
		frame.add(draw);
	}
	
	void update()
	{}
	
	void draw()
	{
		frame.draw();
	}
}

import java.awt.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import java.awt.Component;
import java.awt.event.*;

public class Frame extends JFrame
{
	int windowWidth = 960;
	int windowHeight = 480;
	Insets insets;
	
	public Frame()
	{
		setTitle("Game");
		setSize(windowWidth, windowHeight);
		setResizable(false);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		insets = getInsets();
		setSize(insets.left + windowWidth + insets.right, insets.top + windowHeight + insets.bottom);
		
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
		
		setVisible(true);
	
	}

	
	public void close()
	{
		setVisible(false);
	}
}



import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;

public class Draw extends JPanel
{
	public Draw()
	{
	
	}
	
	@Override
	protected void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
	}
	
	public void draw()
	{
		repaint();
	}
}

Just creates a window. After using jwrapper, the program runs but a window doesn’t appear. I am following the instructions for the sample project and last night I was able to get that working, but translating to this is just doesn’t run.

My project is called ‘gametest’. Inside gametest there are two folders ‘JRE-1.7’ from extracting the jre pack. ‘gameapp’, contains game.jar (runs fine), jwrapper.xml, the sample logo/splash, two more folders, src and bin, bin class files, src source files.

XML:


<JWrapper>
	
	<!-- The name of the app bundle -->
	<BundleName>GameApp</BundleName>
	
	<!-- The specification for one app within the bundle -->
	<App>
	  <Name>Game</Name>
	  <LogoPNG>gameapp/logo.png</LogoPNG>
	  <MainClass>Game</MainClass>
	  <Param>one</Param>
	  <Param>two</Param>
	</App>
	
	<SupportedLanguages>en</SupportedLanguages>
	
	<!-- App is a per-user app, it won't elevate and install for all users and the shared config folder will be per-user -->
	<InstallType>CurrentUser</InstallType>
	
	<!-- Splash and Logo -->
	<SplashPNG>gameapp/splash.png</SplashPNG>
	<BundleLogoPNG>gameapp/logo.png</BundleLogoPNG>
	
	<!-- JVM options (e.g. extra memory) -->
	<JvmOptions>
	 <JvmOption>-Xmx256m</JvmOption>
	</JvmOptions>
	
	<!-- The JREs JWrapper should use for Windows, Linux32, Linux64... -->
	<Windows32JRE>JRE-1.7/win32/jre1.7.0_05</Windows32JRE>
	<Windows64JRE>JRE-1.7/win32/jre1.7.0_05</Windows64JRE>
	<Linux32JRE>JRE-1.7/linux/jre1.7.0_13</Linux32JRE>
	<Linux64JRE>JRE-1.7/linuxx64/jre1.7.0_13</Linux64JRE>
	<Mac64JRE>JRE-1.7/macos64/jre1.7.0_45.jre</Mac64JRE> 

	<!-- The files that the app wants to bundle, here we have just one which is a JAR file and we specify that it should be on the launch classpath -->
	<File classpath='yes'>gameapp/game.jar</File>
	
</JWrapper>

Edit: My manifest.txt for the jar file is just “Main-Class: Game”

  1. We first create a text file named Manifest.txt with the following contents:

Main-Class: MyPackage.MyClass

Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.

========================
2. How your classpath is defined?

  1. If I did that incorrectly, would the .jar not run? Because it does. Is the manifest important part of Jwrapped application?

  2. I don’t understand what you mean.

  1. this warning is from oracle docs. Manifest is the part of jar.
    I can’t say anything about JWrapper.
  2. What you specified in classpath?

Specify when? When I make the jar? I haven’t ever specified classpath.
I don’t know how, or when to do so.

Unless you are talking about for jwrapper, if so you can see how in my xml file above

Bump

Hi Dreamtime,

I’m still asking about classpath…

As it’s said in Jwrapper’s docs:

In your xml specified:

I think it means that you’re declaring ‘gameapp’ as package that’s missing in your Game class (you’re using default package).
If you use default package you should specify '." (current directory) in your classpath (at least if you specify -cp or -classpath in java’s cmd line).

Btw, as it’s also said in Jwrapper docs:

if I get it right it’s your case.

So, please tell how your app’s cmd line is looked.

Also, I recommend you to add explicit package to your class. It may make your life much easier :wink: .

PS
Nevertheless, could you please check if the ‘Manifest.txt’ is ended with \n or \r.

Hope it all will help and I wasted Internet traffic usefully :-).

Hey stranger,

There was a newline in manifest. I thought I was suppose to have it there.

Looking into rest of post but I’m not quite sure I understand the classpath stuff. (Edit: Appears jar wont even run without a newline in the manifest. As I’ve said before the jar on its own runs fine)

I haven’t used -cp or -classpath in the cmd

also I’m not sure how I should set up my package???

Exactly how would you modify my code/packages/xml, in order to make it work?

Thanks for the help

This is how I use the command line:

Creating jar:

jar -cvmf manifest.txt game.jar *.class

Wrapping jar:

java.exe -Xmx512m -jar jwrapper-00031607960.jar gameapp\jwrapper.xml

Sorry if I am giving you information that you aren’t looking for, I am having trouble understanding.

Changed main class attribute in xml from “Game” to “.Game”, will let you know if it helped

It did not help

Does anyone know what I’m doing wrong?

Of course, you’ve ran ‘gameapp-java-online.jar’ or
‘gameapp-windows32-offline.exe’ (or something like this) in jwrapper’s ‘build’ folder?

As I get it, you will have such a file after app’s building finished:

Yes sir! Among others such as “GameApp-windows32-offline”

But running these does nothing. This is the problem, nothing happens

The only thing I can suggest by now - add normal package to your classes.
Then specify the fully qualified main-class name in manifest , xml

I did this - same issue. I’ll provide details of what I did after I try a couple of things.

However I am having a unrelated (maybe?) issue. After creating the jar file, I can’t run it by double clicking on it. I get a “main class not found” error. When I run from the command line it works fine.

What could be causing this issue?

So there is no stacktrace, the error pops up in a window when I try to run the jar by double clicking.

Edit: Okay fixed that, file association issue. I will now see if the application runs correctly after a rebuild

Edit: Still not working…not really sure what to do now…

http://www.4shared.com/zip/W_trDPGice/game.html

Here is a link to the zipped jar for you to try