Java DB Derby and Netbeans 7.1 Build Problems - java

My application accesses a Derby Database and I have added the Derby.jar to the libraries in the project. It runs fine when compiled and runs perfectly inside the Netbeans environment but once I Build the project, only my application.jar file is in the dist folder. The program will still run but once I try doing anything with the database it hangs.
I tried adding the lib folder containing Derby.jar to the home directory of the application.jar but I still get the same problem.
I'm new to Derby and I'm confused by this, any suggestions?

The answer 1 above does not address the fact the you need to first connect to the database in the service tab of the IDE before you can run your application and that is not possible when you run your application outside the IDE.

This is because you don't also add the project external jar dependencies (such as Derby's jar) to the classpath of your project's executable jar. Basicly, try following their tutorial here:
http://netbeans.org/kb/articles/javase-deploy.html#Exercise_1
the chapter entitled "Running the Application Outside of the IDE" and the one after that.
I haven't used Netbeans in a long while so I don't know if they added this functionality to it now, but with Eclipse you can also make a "fat" executable jar, where all the external jars are packed inside that executable jar, and Eclipse adds a special classloader which makes all this work. It's the option called "Package required libraries into generated jar". Maybe Netbeans lets you do that now too, via some export function or something similar.

Related

windows authentication issue in runnable jar

I have created a project in eclipse. I am accessing a database using windows authentication from JDBC. I have sqljdbc_auth.dll in classPath. When I am running program from eclipse it is working fine but when I am creating runnable jar,most of the time JDBC is throwing exception that driver is not configured for windows authentication and a few times it connects. Anyone have any idea why is it happening?
With the high level details that you've provided, what I can think of right now are the following:
Check the run-time CLASSPATH of eclipse, then try to create a CLASSPATH" variable and add the same path.
Do not set a systemwide classpath. Either use a launcher script that correctly calls java -cp <the classpath> <everything else>, or in an executable file, use a MANIFEST.MF file with a Class-Path: header, or bundle all the needed classes into the JAR using the Maven shade plugin
Make sure your executable jar has the dependency in MANIFEST.MF for all the necessary jars (along with MainClass)
Hope that these details are helpful in an attempt to your problem.

Exporting an app with Sikuli

I'm having a problem with the java library sikuli.
First I downloaded the sikuli setup jar and executed it. It created sikuli-java.jar and a libs folder (under c:/documents/sikuli). After that I created a project in eclipse, added the jar to the build path and wrote the code. The code worked when I ran it in eclipse. After that I created a runnable jar from it. I ran the runnable jar. It closed when it hit the sikuli code.
I want to export the app as a runnable jar and deploy it, without the users need to install sikuli. Is this even possible?
Also: https://github.com/RaiMan/SikuliX-2014/wiki/Usage-in-Java-programming
take care, that sikulixapi.jar is in the Java classpath of your project
I don't even have a file called sikulixapi.jar.
=======================================
Maybe a quick note, I've created the sikuli-java.jar with option 4 and 6.
edit:
Anyone? The application works fine in eclipse but when I export it as runnable jar and run it, as soon as it hits the sikuli stuff it closes. No catch block triggered, although I've surrounded the code with catch(Exception ex). I've configured eclipse like this: https://stackoverflow.com/a/10354759/2815780
This is RaiMan from SikuliX (http://sikulix.com)
-- 1. You currently are using 1.0.1. I recommend to switch to version1 1.1.0, since this installs smoother especially on Windows (no path entry or anything else needed anymore).
Since you want to deploy your app to systems not having SikuliX installed, this would make it easier.
-- 2. If you want to run your app on systems not having SikuliX installed, you have to pack a sikulixapi.jar (created with setup for the target system) into your application jar (make a so called fat jar or uber jar) or allow people to download a ready made sikulixapi.jar from somewhere and take care in your application, that sikulixapi.jar is on class path, when your app runs. What makes sense in your case, depends on how you want to publish your app.
-- 3. you say: The application works fine in eclipse but when I export it as runnable jar…
Inside Eclipse it takes car, that dependent stuff is on class path. The jar produced in the workspace though is "naked" and need a class path at run time.
There is an option, to copy the dependent jar to a lib folder in the workspace. If you do that, your jar will work (though I do not recommend this: sikulix jars should not be moved around but only referenced somehow)
-- 4. you say: No catch block triggered, although I've surrounded the code with catch(Exception ex).
If you run your jar from command line saying:
java -jar myapp.jar
it should crash with some unmatched exception (most probably "class not found")
As you already did, you might contact me directly with reference to this post here.

Distributable java files only work in dev machine

I created a Java application in NetBeans. That Java application contains a GUI and some external Jars.
In the dist folder I can see a Jar file and a folder called lib where are the jars I use in the project. If I execute the Jar file the application works as expected. If I change the name of the lib folder the application does not work (meaning that the Jar is using the correct files). But when I copy the dist folder to a different machine (with the same Java version) the application does not work as expected. The user interface is shown but the functionalities does not work (the functionalities are in the external Jars i mentioned in the beginning). Can anyone help?
EDIT:
I checked the class-path in the MANIFEST file and everything is ok.

How to customize java options of a independent netbeans application?

i'm developing an application using Netbeans RCP. I have added an option to add a jar to my class path in the project.properties file of my platform:
run.args.extra=-cp:a ./appclient/glassfish/lib/gf-client.jar
The problem i encounter is that is does work when i run it from the Netbeans IDE but not when i try to create a independent application (build for Mac OSX for instance). I hear that the project.properties is no longer taken in account when you run an independent application and of course my appclient directory containing the jars does not exist anymore in the application package (so my jar is not added to class path).
How can i make this -cp option works for my independent Mac OSX application?
EDIT: i was able to create a custom conf file for my independent platform but i can't find a way to add my jar to the class path, i don't know what options to use.
EDIT: i found that i need to you endorsed mechanism to achieve it. So i have added the following command to my app.conf file:
J-Djava.endorsed.dirs=/Users/altanis/appclient/glassfish/lib/gf-client.jar
But when i run the .app (mac application), i get this error:
-J-Djava.endorsed.dirs=/Users/altanis/appclient/glassfish/lib/gf-client.jar: No such file or directory
The path is correct. Do i need to make something special to make the JVM aware of this? I followed this tutorial and somewhere in the comments the author says:
Right, but the package-appclient copies everything for you and you
should be able to put it on the classpath using the endorsed
mechanism. Unpack the jar created by that and add everything you need
from there (the jars) to your application installer. Then you can use
the endorsed (-J-Djava.endorsed.dirs=${GFCLIENT_PATH}) mechanism in
your app.conf to put it on the application classpath. This way you
should be able to deploy it together with your client.
I think, that create a new library is the better way.
Create module type library with required jars
In your module add dependency to created module (type wrapped library)
You must add entry Class-path to you application's MANIFEST.MF
For example
Class-Path: apache-commons-2.1.jar ejb-api-3.0.jar
all this jars should be in the root directory of your application
Your appliction should have next structure
MyApplication.jar
/META-INF
/META-INF/MANIFEST.MF
/apache-commons-2.1.jar
/ejb-api-3.0.jar
/com/package/classes
or you can use jar tool of JDK to create a jar
read more here Oracle doc

How to run a netbeans project without having installed the netbeans? :-)

I need to make an answering questions game and I chose to make it using netbeans. I wonder if I can create an executable so that somebody could "play" the game even if he does not have installed netbeans!
Any ideas please?
In NetBeans set your application as the active project and press F11, which builds the project. This means that your application will be packaged into an executable jar file that you friend can click to run your application.
Once you have clicked F11 you can locate the executable jar file at e.g. ../Documents/NetBeansProjects/ProjectName/Dist
There is a misconception: Netbeans is not a runtime platform. Netbeans is just a tool to build Java applications. You can perfectly create the same Java application with just notepad.exe and the JDK, you only need to have a bit more knowledge and experience to do it rapidly enough.
To run a Java application, all the enduser needs to have installed is a JRE. To create a runnable Java application, all you need to do is to export the Netbeans project as an executable JAR file.
Developed program has nothing to do with IDE. It doesn't need IDE to be executed...
When you build it, a JAR (Java archive) will be created (look in your dist/ directory or your project properties). If you've set up your project correctly, launching that JAR will start your application. See http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html

Categories

Resources