Gradle creates broken start scripts. How to fix? - java

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.

Related

Using the HornetQ standalone server

I downloaded the 2.5.0 source, and built it by cd'ing to the hornetq-master directory and running mvn clean install (I've also tried mvn clean package). The build reported a success.
According to the 2.4.0 manual, which is the newest I found,
"In the distribution you will find a directory called bin.
cd into that directory and you will find a Unix/Linux script called
run.sh and a windows batch file called run.bat"
If I go to hornetq-master/distribution/hornetq/src/main/resources/bin, I see those files. I don't see any kind of target directory, which I would have expected after a build.
If I execute run.bat, I get an error "Could not find or load main class org.hornetq.cli.HornetQ".
If I look at the hornetq.cmd file, it appears to be trying to use a classpath of %HORNETQ_HOME%\lib, which in my case would be hornetq-master/distribution/hornetq/src/main/resources/lib, which doesn't exist.
So, I assume I'm building this incorrectly. Can somebody tell me how it should be built?
Looks like "distribution" in the manual here is referring to the official distributed .zip file, not something built from source.

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.

Eclipse Classpath with Play Framework

I'm trying to run a small Play application (well, the tests really) in Eclipse and I've come up against a frustrating problem. When I run the command from the command line all the tests are successful, but from Eclipse I've found that it is unable to load some of our required properties files. Looking at the target directory I see two compiled class folders, classes and classes_managed. The properties files are in the classes directory, as I'd expect, but when I look to the class that's attempting to load the properties file the classpath appears to only have the classes_managed directory, which doesn't contain the properties files that are required.
For reference I am running these as JUnit tests so that I can debug them. I've run play eclipse on the command line and imported the project to Eclipse as suggested in the documentation. I'm using Eclipse Kepler and Play 2.2.3.
Any help would be appreciated.
If those files are not getting added to the classpath properly, you can ensure they're accessible by specifically telling sbt that they need to be on the classpath with:
unmanagedClasspath in Test <+= baseDirectory map { bd => Attributed.blank(bd / "conf") }
put this line somewhere in your build.sbt file

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.

How to reference external .jar files in TextMate

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?

Categories

Resources