How run a jar in project simple? - Advanced Installer Community
albrtgc
Posts: 2
Joined: Tue Oct 11, 2016 11:33 am

How run a jar in project simple?

I have a .jar file thatI need to execute using project simple.
I add this file in "FIles and Folders" in the correc folder, and the I create a shortcut in Desktop (Double click -> New Shortcut to -> Installed file-> Select my jar).
Then I build, and run. This create a shortcut in my desktop, but when I click it the following message appears "Error: Could not find or load main class ...

What is that I do wrong? Which is the solution?
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: How run a jar in project simple?

Hello and welcome to our forums!

I'm not sure why the shortcut to the JAR file does not work in your tests. Are you able to run the JAR file by double-clicking it outside Advanced Installer on your machine? If you manually create a shortcut to that file outside Advanced Installer, can you run the JAR file using that shortcut? Do you try to send some arguments to the file through the shortcut?

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
albrtgc
Posts: 2
Joined: Tue Oct 11, 2016 11:33 am

Re: How run a jar in project simple?

I don't open de JAR with double click, becouse the JAR only can execute in the console. Which is the best proccess to this?
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: How run a jar in project simple?

Hi,

The best way to work with JAR files it to use the "Java Products" support as explained in the "Creating a Java Product Installation" tutorial. However, I'm afraid that this feature is only available in a "Java" or higher edition of Advanced Installer.

Nevertheless, if you can launch your JAR file outside Advanced Installer through a shortcut with arguments, you can, then, create that shortcut in an Advanced Installer project and it should work, too.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
AndreG
Posts: 57
Joined: Tue Jun 10, 2014 11:41 am

Re: How run a jar in project simple?

albrtgc: Just to add to what Eusebiu has explained, it might help if you understand how a JAR file is actually launched.. Just to confirm though, when you say it "can only execute in the console", I assume you mean using the command "java -jar <yourfile>.jar"?

That uses the command line (console) to launch "Java.exe", passing your JAR file as a parameter. The configuration in AI's "Java Products" page creates an executable wrapper that essentially does the same thing. Similarly, if your operating system is set to associate JAR files with the "Java.exe" executable, then simply double clicking on the JAR file in an Explorer window will, again, do much the same as the console command. At the end of the day, all these methods do is launch a new JVM (Java Virtual Machine) using your default Java version and tell it which JAR file you want it to execute.

Looking at the error message that you posted first, it looks like the JVM that's trying to run your JAR file doesn't know which class in your project has the "public static void main()" method it needs to execute. If you open your JAR with an archive manager (7zip, Winzip, Winrar, etc..) and extract the "manifest.mf", does it contain an entry called "Main-Class"? If not, then you'll either need to alter your Java project build configuration, or manually set the "Main Class" in the entry you create in AI's "Java Products" page.
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: How run a jar in project simple?

Thank you for the information you provided AndreG. I'm sure it will help other users in the same situation.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”