Here is the situation: I have a JavaFX8 application, made with Netbeans 8.1. The application runs/debugs within Netbeans without a problem. When I package the application as .EXE (or .MSI, same error), I get the .exe install file without errors. The installer installs the application with the expected folder structure:
+-- RCWStats
\+-- app
\+--lib (contains all needed jars)
\---RCWStats.jar
\---RCWStats.cfg
\+--runtime
\+--bin
\+--lib
\---RCWStats.exe
When I try to run the application by executing the RCWStats.exe file, I get these :
However, when I execute the RCWStats.jar in /app, it starts without errors, which I find puzzling.
I have found a similar question in SO, namely this one, but the solutions and comments in there didn´t help me:
I have executed the .exe from the command line, redirecting output, but the output file is always empty. I have triple-checked the main-class-setting in Netbeans, it´s correct. Also, my external libraries are generated correctly, so I don´t have to tweak my build.xml.
EDIT: additional info
I opened the JAR, the main class is where it is supposed to be. The manifest is also correct. Pic attached. To be honest, since the JAR is working fine, I suspect the problem is in the .exe, it somehow doesn´t find or execute the JAR correctly. Since the packaging process is more or less a blackbox, I´m kinda stuck.
Manifest-Version: 1.0
Implementation-Title: RCWStats
Implementation-Version: 1.0
Permissions: sandbox
Codebase: *
JavaFX-Version: 8.0
Class-Path: lib/eclipselink.jar lib/iText-4.2.0-com.itextpdf.jar lib/j
avax.persistence_2.1.0.v201304241213.jar lib/mysql-connector-java-5.1
.6-bin.jar lib/org.eclipse.persistence.jpa.jpql_2.5.2.v20140319-9ad6a
bd.jar
Created-By: JavaFX Packager
Implementation-Vendor: jalexakis
Main-Class: main.java.RCWStats
EDIT 2: RCWStats.cfg
[Application]
app.name=RCWStats
app.mainjar=RCWStats.jar
app.version=1.0
app.preferences.id=main/java
app.mainclass=main/java/RCWStats
app.classpath=lib/eclipselink.jar;lib/iText-4.2.0-com.itextpdf.jar;lib/javax.persistence_2.1.0.v201304241213.jar;lib/mysql-connector-java-5.1.6-bin.jar;lib/org.eclipse.persistence.jpa.jpql_2.5.2.v20140319-9ad6abd.jar
app.runtime=$APPDIR\runtime
app.identifier=main.java
[JVMOptions]
[JVMUserOptions]
[ArgOptions]
I would check the classes contained in the jar first and foremost and ensure that the RCWStats class is located in the right place. Check the manifest also to see what the main class is defined as and that it matches what you expect from NetBeans itself. And ensure that your runtime classpath is defined. Without seeing the contents of the jar, knowing your classpath settings, etc, it's difficult to suggest more. If you could embellish on these, perhaps it may become clearer and easier to answer? Thanks.
Related
I'm producing an app using Eclipse on a Mac, and am using File Export to produce a Runnable Jar. The Runnable Jar files that I produce run happily on my Mac and on another Mac. But on two different Windows machines, they don't. I've looked around for answers, and have tried the following:
1) When I double click on the jar icon nothing happens.
2) When I type
java -jar Luscinia.jar
at the Command Prompt, I get:
"Could not find or load main class lusc.net.github.Luscinia"
3) When I type
java -cp Luscinia.jar lusc.net.github.Luscinia
I get the same error message.
The JRE on one of the Windows machine (at least) is up to date
(1.8.0_40). So is the JRE on the Mac.
The file structure inside my jar does indeed have
Luscinia.class nested inside github, net and lusc directories.
The manifest contains the lines:
Class-Path: .
Main-Class: lusc.net.github.Luscinia
(& it contains two blank lines at the bottom)
Other jar's are working well on the two Windows machines.
And to emphasise again, it works perfectly well on two Mac machines.
Any ideas?
I checked whether the EOL character had an effect. Changing it to Windows \r\n didn't have any effect. (Thanks to RealSkeptic for the idea).
Are you sure your class doesn't attempt to load a Mac specific class that is not available in the windows JRE (vendor private classes ? like com.sun classes on windows) or it's not missing dependencies in the classpath necessary to the main class ?
If one of your dependant class fails to load when the main class is being class loaded (in static blocks for example), it makes it fail to load the importing class as well and you can have that problem.
In any case, having the source of the main class could help figure out the problem.
The answer provided by DarkRift was correct:
Hidden in one file was a reference to a com.apple... class that was superfluous and, critically, platform specific.
In this case, when I got the error message:
Could not find or load main class lusc.net.github.Luscinia
It meant "Could not load" rather than "Could not find". Thanks for all your suggestions.
I'm new to using jar files on my applications so here is my problem.
I wrote my code on net beans and added into the library the jar file I need, which is:
poi-3.10-FINAL. The program runs perfectly from net-beans, however when i try to run it from the command line seems like it doesn't find some of the files inside the jar. Reason for this I would like to make it an executable after i get this solved.
In the command line I'm compiling my code as follows:
C:\Users\chuser10\Desktop\Excel\src\excel>javac *.java -cp C:\Users\chuser10\Des
ktop\Excel\src\excel\lib\poi-3.10-FINAL.jar
It compiles perfectly, which lead me to think everything is good to go, however this is not so. I tried then running my main as ...>java GUI and i got this:
C:\Users\chuser10\Desktop\Excel\src\excel>java GUI
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apach
e/poi/poifs/filesystem/POIFSFileSystem
I checked inside the jar and the file is there. Any clue why this might be?
You need to specify the classpath when you run the program too. Compiling doesn't link the library into your code as happens in C and many other languages; in Java linking happens at runtime.
Probably -cp .;C:\Users\chuser10\Desktop\Excel\src\excel\lib\poi-3.10-FINAL.jar will be what you need. The '.' at the beginning means the current directory, which is where the class files that constitute your program are rooted. The ';' is just a separator.
Got it working. You are both correct, we have to specify the class-path at runtime as well.
I went ahead and went for the executable jar file creation and put it on my manifest:
..>jar cfm < *.class>
On my manifest:
Class-Path: poi-3.10-FINAL.jar
Main-class: GUI
Cheers!
Ok, I'm stumped here. I'm using Matlab version 2013b with a Java RTE of 1.7.0_11 and I'm trying to run a simple piece of code to see if Matlab is able to read the .jar file and nothing seems to be working.
Here is the Java code, which is compiled to a .jar named JavaOCT.jar, which is placed in the Matlab working directory:
package VTK;
public class vtkVolumeView{
public int Test(){
return 10;
}
}
That is it, no other dependencies, nothing fancy. In Matlab, I try:
javaaddpath('\JavaOCT.jar'); %<-Directory and name are 100% correct
import VTK.*; %<-Package name from above
methodsview VTK.vtkVolumeView; %<-Can't find the class, argh!
Matlab kicks back that it can't find the class.
Things I've done to try and solve the problem:
Reverted to the exact same JDK as the Matlab RTE
Tried an older 1.6 JDK
Done lots of stack overflow research to try and solve it 1 2 3 4
Tried used javaclasspath and pointing to the compiled class instead
Read the Matlab documentation 5
Using clear -java after the javaaddpath
Any help would be appreciated, it is driving me nuts!
Update: Daniel R suggested just javaaddpath('JavaOCT.jar') which doesn't work either.
Final update: It finally works! I wasn't building the .jar properly. In IntelliJ, click on the project and hit F4. This brings up the Project Structure, then go to Artifacts and click the green + button and add DirectoryContent and then point to the out\production. Once this is done, as mentioned by others, it should show up in Matlab as an expandable .jar.
I don't know which operating system you are using, but the ./ seems invalid.
Try javaaddpath('JavaOCT.jar'); or javaaddpath(fullfile(pwd,'JavaOCT.jar'));.
What does exist(fullfile(pwd,'JavaOCT.jar')) return?
Some things to try:
Add the class file. When using a package, you need to add the class file in at the host of the package. For example, if your code is here:
\\full\path\to\code\VTK\vtkVolumeView.class
Then use:
javaaddpath('\\full\path\to\code')
I'm still suspicious of your *.jar path. You should usually use absolute paths when adding jar files. Try adding the results of which('JavaOCT.jar')
How did you make your jar file? Does it contain the appropriate directory structure implied by your package declaration?
I am reading packaging java applications with jar tool. I noticed a manifest file is created under META-INF directory. For a simple application, it felt like, it's serves no purpose. I searched on stackoverflow to understand the usages of Manifest file. I came across UsesOfManifestFile. While reading the answer, i got confused on point 2 and 3 which are :-
What are download extensions? I am not able to understand the concept in the answer.
What does it mean to seal the jar? It has given an example below like this
Name: myCompany/MyPackage/ Sealed: true
What is the use of putting such information? Can someone elaborate on these points.
Thanks.
The manifest file is like the guidance instructions for the java program to run the jar. When the manifest is created it will hold crucial information, for example a reference to the main program. When the java program runs your jar it doesn't know where to start, so it look sin the manifest for a line telling it where the class with the main method is so it has a start point for the program. Another use is a classpath line, which will tell the program where to find any 3rd party library's in the jar are, otherwise again, the java program won't find them.
There is a range of data that can be stored in the manifest file, I would recommend checking out the Oracle information on them and seeing if that clears it up a bit more.
EDIT: From the Oracle site regarding your example:
Packages within JAR files can be optionally sealed, which means that all classes defined in that package must be archived in the same JAR file. You might want to seal a package, for example, to ensure version consistency among the classes in your software.
You seal a package in a JAR file by adding the Sealed header in the manifest, which has the general form:
Name: myCompany/myPackage/
Sealed: true
The value myCompany/myPackage/ is the name of the package to seal.
Note that the package name must end with a "/".
What this appears to mean is that any and all classes that you use in your program must be within the same jar file.
EDIT 2 (For comment response)
A manifest may contain the following line:
Main-Class: com.mkyong.awt.AwtExample
When the javaw.exe (I think) runs your runnable jar, it has no idea where to start from, all java programs run via a main method, but if you have say 50 class files in your jar, it has no idea which one has the main method to start from. It will look at the manifest file, reads your above line and thinks right, the main method is in the package com.mkyong.awt and the class is AwtExample, it then finds this class and runs the program from that main method. It's most basic function within the jar is to tell the java program running the jar where to find the stuff it needs to run your jar.
Note: that example manifest entry came from a little tutorial which shows how to create a simple runnable jar.
Good Luck!
I'd like to make "double-click" cli application but still don't get how.
I know I should propably somehow edit manifest but that is all. I googled ofc. but no success.
Thanks for any tips.
Here is the output from build, run, and manifest:
compile:
Created dir: /home/nick/NetBeansProjects/SemestralWork/dist
Building jar: /home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar
Not copying the libraries.
To run this application from the command line without Ant, try:
java -jar "/home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar"
jar:
BUILD SUCCESSFUL (total time: 1 second)
java -jar /home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar
Exception in thread "main" java.lang.NoClassDefFoundError: semestralwork/Main
Caused by: java.lang.ClassNotFoundException: semestralwork.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
Could not find the main class: semestralwork.Main. Program will exit.
MY MANIFEST created with build:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 14.0-b08 (Sun Microsystems Inc.)
Main-Class: semestralwork.Main
Class-Path:
X-COMMENT: Main-Class will be added automatically by build
These two lines tell you all you need to know:
Exception in thread "main" java.lang.NoClassDefFoundError: semestralwork/Main
Caused by: java.lang.ClassNotFoundException: semestralwork.Main
And a further clue is dropped by the manifest output:
Main-Class: semestralwork.Main
This means that the JAR file is looking for a package named semestralwork and a class named Main inside it. It fails at this point because it cannot find either the semestralwork package or the Main class.
As you pointed out in your question, the problem is indeed in the manifest file. You can edit this directly in your JAR file if you like, but a better idea would be to do this from Netbeans:
Click on `File --> Project Properties (semestralwork)'
In the dialog that opens, on the tree on the left select Run
Then, on the right, under the field labeled Main class:, enter the fully qualified class name of the class that you want executed when run from the command line.
In your case, as I see from your comment on #Aaron's answer, if your main class is in a file called encryption.java, and it is in the default package (no package), just enter encryption.
Once this is done, do a clean and build, then try running it from the command line again.
HTH
Since I encountered the same problem, I can clarify the solution a little bit.
You must create main Java class outside your method (for example-default_package folder), and then invoke your method(folder), e.g import your_folder.connected_class; in that main class.
Hopefully I could help someone with the same problem.
It's easier to make a .exe from a .jar without netbeans.
Here are my suggestions:
1. Use a special application for this(ex: JSmooth, JEXECreator etc)
2. Make a C++ program that starts a JVM (see this tutorial)
The default class search path may be the issue. You should try changing directory to the location the jar is and launching with java -jar Semestral.jar. Also you may have misnamed the main class. Please also include your package structure.
Open the JAR file with a ZIP tool (or try less ... if you're on Linux or jar tvf ...). Make sure there is a directory semestralwork in there which contains a file Main.class.
It's Easy. Download a copy of netbeans. Make a new project in netbeans. Goto your main class in the Projects Explorer. This should be folder "YourProject" As the class YOURPROJECT.JAVA . It is this yourproject.java file that you want to start with. Just write your code into the public static void main area. You can run the program with the green play button in the top toolbar.