How to reference external .jar files in TextMate - java

I'm working on a java project that requires constantly running the code, to see if it builds properly.
So I'm trying to reference external jar files, without having to launch the project from the command line (I'm running in TextMate).
Any advice?

Related

Gradle creates broken start scripts. How to fix?

I am trying to learn how to build applications using Gradle; to do this I use the 'Application' plug in. This plug in builds executable scripts that runs my jar file. However the batch file that is generated is showing an error. This is for every project I build with Gradle.
I can execute the jar file fine using 'java -jar app.jar' but the app.bat file only shows the error.
The error shows is;
Error: Could not find or load main class com.test.Main
I have exhausted my ability to search stackoverflow and google for a solution. It seems possible that there is an error with the %CLASSPATH%?
Note: I had the batch file for an early project working perfectly fine. When revisiting the project later in the day (no code changed) the batch file fails to run. This makes me thing there is a setting/ environment issue more than a programmatic one?
I needed to use the assembleDist task to create a zip folder. This zip folder contained the sh and batch files with the correct classpaths and worked perfectly.
Note: The sh and batch files located in /scripts are used by Gradle to run the application during development. When trying to execute them from the terminal or command prompt they could not find the main class or the libraries used. As far as I can tell this was due to the %CLASSPATH% not being tailored for use outside of gradle.
Running the distribution task creates an archive of the project containing all of the required files and working execution scripts. These were the files I should have been testing, not those found in the gradle project.

Java3d - Jar file contains error java.lang.NoClassDefFoundError javax/media/j3d/Canvas3D

I am currently having a problem running a jar file created by eclipse.
Within eclipse I can run my project using the run function and the project runs exactly as expected.
The same applies to compiling and running the code from command line using javac Menu.java to compile and java Menu to run.
Both of these run correctly and do not return the error I receive when running the jar file.
The jar file was created in eclipse by exporting the project. But when i run the jar file the application refuses to response when opening any JFrames containing Java3d. Upon debugging the jar file i receive the error
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/media/j3d/Canvas3D
This normally would lead me to believe that my CLASSPATH is incorrect but since the project runs from command line this doesn't seem likely.
Any help or pointers would be very helpful.
Thanks.
Found a solution which works.
Instead of simply creating a jar file, you can created a runnable Jar file.
When asked under library handling in the export process, selecting 'package required libraries into generated JAR' solves this issue and allows it to run on all computers, even ones without Java3D installed.

Error in preparing standalone Java application with external libraries

I have made a Java serial Interface using RxTx libraries in Netbeans 7.2.1 which works fine.
Tested it with NULL modem and it works fine. Now I need to create an exe which I can distribute.
So,Now I am trying to make a jar file for my project. What I did-
and then clean and build to get jar at location
"D:\Glaswegian\Java\Slides\RxTx\SerialCommInterface\SerialCommInterface\dist"
with below structure
with lib having RxTx.jar
Now when I try to run from command prompt:
I get below error
Can anyone please let me know how to resolve this?
Have refered
Run jar file in command prompt
How can I include external jar on my Netbeans project
But not able to resolve it.
The system cannot find some native libraries (which probably are needed by RxTx).
Assuming that the native libraries (*.dll) are in the lib folder - try to run the app like this:
java -Djava.library.path=lib -jar SerialCommunicator.jar

Builds fine in Eclipse, Runs fine from CLI, Running from Eclipse generates NoClassDefFoundError

I have a project, which generates 2 jar files {Main.jar, Sub.jar}, and relies on two other jar file libraries {extJar1.jar extJar2.jar}.
In eclipse, building Main.jar and Sub.jar works fine, so eclipse can see everything that is needed.
At the CLI running the Main.jar works fine and the program compeltes successfully.
Running the project from within eclipse however, generates a NoClassDefFoundError from within extJar1.jar
My system classpath is blank, so naturally everything must be contained within the 4 jar files.
Given that eclipse can build the project, so can obviously see all necessary classes, why does running in eclipse generate this issue?

Application compiles and builds on Netbeans but not as an independent jar file?

Is it possible that your application compiles and builds flawlessly in Netbeans but when you build it and run it outside of Netbeans you get heaps of Exceptions??! (keeping in mind that the all the libraries and dependencies are ported along with the actual jar file).
I run the followng command
ant -f run
and my program runs flawlessly as it's supposed to, however, where I run the following command to actually build a jar file,
ant -f jar
and when I run the jar file, my application runs but does not perform the tasks it does when it is launched using the first command.
Any ideas why this is happening??! I'm totally lost with this behaviour and can't find why!
If the exceptions are ClassNotFound, then it means that you're missing JARs in the CLASSPATH. NetBeans is sorting it out for you, but when you run outside of it you have to manage it yourself.
keeping in mind that the all the libraries and dependencies are ported
along with the actual jar file
I'm not sure what the word "ported" ends up looking like for you, and without any real information I'm guessing, but your app isn't packaged correctly.
How are you attempting to build your project outside of NetBeans?
Inside NetBeans, if you created the project from within NetBeans, I believe that most of the time NetBeans will create all of its (by default) Ant targets in a file called nbbuild.xml.
Thus, if you're attempting to compile your project outside NetBeans from the command-line (however it exists on your system), you would then need to use the -f nbbuild.xml argument to the ant program to use the NetBeans-generated Ant file. So your command-line might look like this:
ant -f nbbuild.xml compile
Substitute, of course, the target you desire to run for compile in the example above.

Categories

Resources