Deploying netbeans applications - jar file error (could not find main class) - netbeans

I have a small GUI application developed with netbeans.
I used the 'clean and build' option to build an executable jar file. .jar file works in my pc. But when i sent the application to my friend he says that it throws 'cannot find the main class' error.
what could be the reason?
Thanks in advance...

Open project property, select run and set Main-Class (textfield) attribute.
EDIT:
Execute the main class in .jar application,
java -jar Application.jar

If you have used any library, try giving the library jar files along with the jar file. For example if your libraries are present in suppose lib folder then give the complete lib folder along with the jar file.

Related

Google debug: How to debug a library in executable jar - Error : File was not found in the executable

Details: Java app on GKE : Kubernetes
I am able to debug all the java files of my executable jar but not the inner jars/libraries. My executable jar's main code is in implementaion jars/libraries, I have source code of those libraries. How can I debug them?
I have used gcr.io/google-appengine/openjdk and added following entry points:
ENTRYPOINT ["java","-agentpath:/opt/cdbg/cdbg_java_agent.so", "-Djava.security.egd=file:/dev/./urandom" ,"-Dcom.google.cdbg.module=watchlist", "-Dcom.google.cdbg.version=develop","-jar","/watchlist.jar"]
I think I need a way to put all the class files of required library jars in my main executable jar's web-inf/classes folder. How can I do that?
TIA
I recommend using an IDE.
In my experience, when you got the implementation from your java file to the class file (CTRL + click normally does the trick for classes or Right click and go to implementation for implementation), you reach the class file of the jar.
There you can go to the top of the class file and click on the package. This will open the jar from target of your project explorer.
You will be able to find your desired class there, or in a different package.
I hope this approach works for you.
PS: I use Intellij

deploy jar Java Desktop Application in jdeveloper12c

I have always developed my java NetBeans projects. When I finish my project, and automatically build "dist" folder where the main jar and a "lib" folder containing all the external jar was created. This is done automatically with the NetBeans IDE
Now I'm trying to do a project with jdeveloper 12c Java Desktop Application and try to deploy my project but I have problems with java.lang.NoClassDefFoundError. I meet several questions:
Can you add the same structure as I said before? That is, a file jar and inside a folder "lib" place the jars using How to do it?
I've seen examples that by New File Group adds refencias, but it really adds to the main jar file (as I see in the size of the file) but not saved in a separate folder.
I do not know if you can help me do this in jdeveloper 12c: Generate a jar file and folder lib with references.
Thank you for your help.
Go into the deployment profile for your project and add all the libraries and files that you need to be included to the JAR you are generating.

Trying to create a runnable jar / app out of my Java Project in Eclipse (Mac)

So I know that I can make a .jar file by exporting my project with eclipse... but that doesn't work. I've tried it.
My project contains 10 different classes, and a folder that contains images and fonts used in the app. I thought I should just be able to make a jar file and run it. Keeps telling me "Could not create java virtual machine" when I run it through terminal.
I just need to be able to run it without using an IDE
You can try fat Jar eclipse plugin for exporting Java projects to runnable jar.
More info see here.

How can my project access its "resources" directory both when run in Eclipse and from a Maven-packaged jar file?

I'm working with Maven project in Eclipse (with help of m2e plugin). When I pack my project into jar-file (mvn install), all files from "resources" are located in the root of jar.
Therefore, in my program I should use only bare file names:
File file = new File("foo.txt");
But when I build and run my project by Eclipse, I would have to use the relative path to the file:
File file = new File("src/main/resources/foo.txt");
What should I do to solve this problem?
To access your program's resources, don't use File, FileInputStream and similar classes.
They will not work for anything inside a jar file.
Instead, use Foo.class.getResource(...) or .getResourceAsStream() to access your resources. (Read the documentation before doing so.)
I'm not sure if a program started from eclipse can access these - please try and report back!
Your package configuration in Eclipse is wrong, cause it sees src/main/resources as a package instead of a source folder.
The configuration in Eclipse must look like this:

how to put .properties file in classpath of an Eclipse plug-in

I have an application which is making use of a .jar file and a .properties file which must reside in the same directory as where the .jar file lies. On a normal java application, this works fine, however I'm building an Eclipse plug-in. I've tried attaching the .properties everywhere, in the classpath, build path, putting them in the same folder and calling the jar file from there (this gives an obsure error) and I've even tried putting the .properties file inside the .jar file even.... but no luck. Any ideas how this could be done please?
Thanks and regards,
Krt_Malta
Perhaps the FileLocator class will help you. The FileLocator provides a find method where you can specify the Bundle and a resource to look for.
Ingo