Executable jar closes immediately after launching (Slick2D) - java

So I made an executable file with Eclipse but when I double-click it nothing happens. It IS NOT because I've got wrong association for running .jar files (I'm running okey my another jar program just by double-clicking it).
I also tried with command prompt and the console doesn't print anything at all and get back to be "normal".
I think it's something with main class so the thread doesn't last but closes after running (however it looks like the code isn't run because console would print lot of Slick stuff).
So here is the main method:
public static void main(String[] args) {
Shiftjumper shiftjumper = new Shiftjumper("Shiftjumper - behavior prototype");
try {
AppGameContainer gc = new AppGameContainer(shiftjumper);
gc.setDisplayMode(TILE_SIZE*RIGHT_LEFT_TILES, TILE_SIZE*UP_DOWN_TILES, false);
//gc.setTargetFrameRate(60);
gc.start();
} catch (SlickException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
And here the manifest:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ lwjgl.jar slick.jar
Class-Path: .
Rsrc-Main-Class: engine.Shiftjumper
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

You need to download a tool known as JarSplice. JarSplice is a very simple GUI based application which packages all libraries and native code into the form of either a .JAR, a .EXE, a.SH or a .APP. Here is a link to the site: http://ninjacave.com/jarsplice
Hope this helps :)

Try running the jar in your terminal or command prompt, if there are any exceptions it will print to the console and you can debug

Related

Connecting to Quality Center v11 using COM4J

I am trying to connect to HP Quality Center V11 using Java code and com4j but i keep getting following error. Can someone please take a look at the error?
When I use the URL in my browser and log-in with same credentials, I was able to login. I double checked all the spelling of my domain, url, Id and password..
Error I get:
com4j.ComException: 800403ea (Unknown error) : Failed to Login : .\invoke.cpp:517
at com4j.Wrapper.invoke(Wrapper.java:166)
at $Proxy5.connectProjectEx(Unknown Source)
at com.testpack.TestClass.main(TestClass.java:23)
Caused by: com4j.ComException: 800403ea (Unknown error) : Failed to Login : .\invoke.cpp:517
at com4j.Native.invoke(Native Method)
at com4j.StandardComMethod.invoke(StandardComMethod.java:35)
at com4j.Wrapper$InvocationThunk.call(Wrapper.java:340)
at com4j.Task.invoke(Task.java:51)
at com4j.ComThread.run0(ComThread.java:153)
at com4j.ComThread.run(ComThread.java:134)
Code I use to connect
public static void main(String[] args) {
String url="http://XXXX/qcbin/";
String domain="ACTIVE";
String project="QC_2013_Projects";
String username="XXXX";
String password="XXXXX";
try{
ITDConnection itd=ClassFactory.createTDConnection();
itd.initConnectionEx(url);
System.out.println("Test1:"+ itd.connected());
itd.connectProjectEx(domain,project,username,password);
//System.out.println(itd.connected());
}catch(Exception e){
e.printStackTrace();
}
}
I followed these steps for getting connected to HP QC 11 from Java code using com4j on windows 7 32 bit machine
Download Com4j artefacts com4j-20120426-2.zip from https://github.com/downloads/kohsuke/com4j/com4j-20120426-2.zip
Unzip it. Open a command prompt and navigate to the unzipped folder. Then run following command to create Wrapper classes in a location CCCC with package structure as DDDD.
java -jar tlbimp.jar -o "C:\CCCC" -p "DDDD" "C:\Users\MYACC\AppData\Local\HP\ALM-Client\10\OTAClient.dll"
Now copy the OTAClient.dll and WebClient.dll from C:\Users\MYACC\AppData\Local\HP\ALM-Client\10 and save it in Windows/System32 folder.
After following the step 2, you must have a com4j-x86.dll in the location where tlbimp.jar is present. Now copy that dll to Windows/System32 folder.
Now with Admin rights, register all 3 dll files using the commands 1 by 1 as follows.
regsvr32 com4j-x86.dll
regsvr32 OTAClient.dll
regsvr32 WebClient.dll
Now create a Java Project in eclipse. In the src folder copy the DDDD folder created during the step 2. Add com4j.jar in class build path. Then have the following code in a java file to test the HP QC connection. Run the java file to check the result.
ITDConnection itd=ClassFactory.createTDConnection();
itd.initConnectionEx("http://10.10.10.10:8080/qcbin");
System.out.println(itd.connected());
itd.connectProjectEx("DOMAIN_NAME", "PROJECT_NAME", "HPQC_USERID", "HPQC_CREDENTIAL");
System.out.println(itd.projectConnected());
Hope this helps. :)
I was finally able to solve this issue. I had install HP ALM QC Client. It would install in the following path- > Your Program files->HP->HP ALM Client.
After I installed this, I was able to connect to QC.
Hope this might be useful to someone else. Thanks!
I added all the 3 .dll files in c:\Windows\SysWOW64 and executed the same code.
// This is a fairly important section for x64 bit machines,
// as a note this took me forever to figure out. Basically,
// if the DLL is not registered in the SysWOW64 dir then we
// are unable to use this as it was created when 32-bit
// computers were still all the rage. This is a quick little
// hack that registers it if it is needed to be registered.
// If it's already registered, this does nothing.
try {
Runtime.getRuntime()
.exec("C:\\windows\\SysWOW64\\regsvr32 /s lib\\OTAClient.dll")
.waitFor();
Runtime.getRuntime()
.exec("C:\\windows\\SysWOW64\\regsvr32 /s lib\\com4j-amd64.dll")
.waitFor();
Runtime.getRuntime()
.exec("C:\\windows\\SysWOW64\\regsvr32 /s lib\\com4j-x86.dll")
.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Utilities
.showError(
new JFrame(),
"OTAClient.dll, com4j-amd64.dll or com4j-x86.dll could not "
+ "be registered, program may or may not work on a 64-bit machine "
+ "without these files. You can attempt to manually register them, "
+ "but this rarely works.");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run this before anything else in your code, it's what I used to force any machine to register them.

Run JAR file in PHP and write a file

I have the following problem in php when excecuting a jar file. I use the following command:
exec("java -jar JavaProject4.jar";
The JavaProject4.jar creates a txt file in a path given in the java code.
When i run the project in NetBeans the txt file is created. However, when i excecute the jar in php i don't get any errors but i can't get the file.
Here the java code I use to write the file:
public static void main(String[] args) throws InterruptedException, FileNotFoundException, IOException {
Main a = new Main();
List<Double> l1 = new ArrayList<Double>();
l1 = a.compute_features();
//System.out.println(l1);
FileWriter fstream1 = new FileWriter("C:/wamp/www/test/out.txt");
BufferedWriter out1 = new BufferedWriter(fstream1);
out1.write(l1.toString());
out1.newLine();
out1.close();
}
Im using a wamp server with php 5.2.4 and the latest java version.
Thanks a lot!
EDIT:
Problem solved, I moved the main java file in NetBeans to the default package and also fixed a wrong path and now everything is working as expected.
Thanks everyone
When you run it with PHP, how are you doing so? Are you using the PHP CLI (Command Line Interface), or are you running it through an Apache Module (CGI or otherwise)? The reason I ask, is because the problem you are having could have something to do with the user who the script is executing as. If you are using the CLI, you are running as your Windows User, however, if you are running it through Apache, then it is running as whatever user Apache is running as. Therefore, you might need to give the relevant permissions to the Apache user for that directory you are writing to.
Regards,
Ralfe
I think that you need to specify the full path for :
- the java executable
- your jar
Example :
exec("/usr/bin/java -jar /my/java/project/path/JavaProject4.jar");

JSmooth generated exe does not show Splash Screen

I wrap my Java Swing application as an exe using Jsmooth but I can see no way to take advantage of Java 6 splash screen option. I have the following manifest file:
Manifest-Version: 1.0
SplashScreen-Image: resources/LOADLOGO.png
Main-Class: se.bookingapp.UI.MainFrame
The splash screen appears if I simply click on the jar file of the application. However, the JSmooth generated exe form of the jar file does not show the splash screen somehow. Does anyone know why?
Yesterday I've finished to develop my java application and I had the same issue. If I double click the .jar file or I execute in a command line splash screen works perfectly, but when I execute the wrapped file it doesn't. Seems just JSmooth doesn't support this feature.
However I made a little trick to have a wrapped .exe and splash screen working at the same time. I made a little application called ApplicationLoader.jar that consists in a single main class that execute java -jar "Application.jar" in a command line. Here is the complete code:
public class ApplicationLoader {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
/* First I check if the first parameter is not null and it's not an empty string */
if(args[0] != null && !args[0].trim().isEmpty()){
/* Then I use java.util.regex package to validate the parameter is a .jar file */
Pattern pattern = Pattern.compile(".*jar");
Matcher matcher = pattern.matcher(args[0]);
if(matcher.matches()){
/* Finally I define the command line like: java -jar "Application.jar" */
String command = "java -jar \"" + args[0] + "\"";
try {
Runtime r = Runtime.getRuntime();
ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", command);
Process p = pb.start();
p.waitFor();
} catch (IOException | InterruptedException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error executing: "+command, JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null, "The argument is not a .jar file!!");
}
} else {
JOptionPane.showMessageDialog(null, "There's not a valid argument!");
}
}
}
I have this folder structure for my application:
MyApp
+-- bin
| +-- MyApp.jar
| +-- ApplicationLoader.jar
+-- MyApp.exe
So in JSmoot I changed the classpath to ApplicationLoader.jar and add the relative location to my application in Application Arguments section like this:
And that's it. I know this is not the best option but is a workaround.
However there's a little problem:
Since ApplicationLoader.jar calls a cmd.exe then the wrapped .exe and your application will execute in two different processes.
This implies that if you have to kill .exe process for some reason (unexpected crash or something), your java application still working as a java.exe process. So in that case you must kill MyApp.exe and java.exe processes. Actually if you just kill java.exe process then MyApp.exe process will finish execution by itself.
If you keep this in mind and you can live with that I think this option is quite simple and useful.
I hope this be helpful to anybody looking for a workaround to this issue.
Does it work when you execute the jar file? Open it with WinRar for example, and check if the manifest is into META-INF folder, and LOADLOGO.png is in the right folder too.
After doing that, it should work. It works for me. Nothing wrong in your manifest.

Running java code on VMWare with references to external jar files

I am trying to run simple java code on VMWare Workstation. I have the following simple test Main file:
import cern.jet.random.engine.RandomSeedGenerator;;
public class TestDataService {
//private static Logger logger = Logger.getLogger(TestDataService.class);
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World DAI!");
// Input some data.
RandomSeedGenerator re = new RandomSeedGenerator();
return;
}
}
RandomSeedGenerator is a class in colt.jar library, and I have the jar file under my lib folder.
I am building the project with ant, and I have the following manifest file where I set the classpath:
Manifest-Version: 1.0
Main-Class: edu.umass.TestDataService
Name: edu/umass/TestDataService/Version.class
Class-Path: lib/colt.jar
When I run the code from the VMWare shell which runs Red Hat Linux, I get this Exception:
[root#localhost] java -jar app.jar
Hello World DAI!
Exception in thread "main" java.lang.NoClassDefFoundError: cern/jet/random/engine/RandomSeedGenerator
at edu.umass.TestDataService.main (Unknown Source)
Caused by: java.long.ClassNotFoundException: cern.jet.random.engine.RandomSeedGenerator
Just as a final note, everything seems to work fine on windows with eclipse, but nothing seems to work on the virtual machine. Any ideas?
Did you install the jar files required by your application on the VMs?
Did you configured CLASS_PATH correctly?
I doubt there is an issue with the jvm or the vm. The problem is going to be in how you run the class. Specifically how your setting the classpath. Try this:
Navigate to where you've placed colt.jar. Get the present working directory by typing in pwd. Use this to construct the run command using the absolute path to colt.jar.
So eventually you should be running (from the directory containing your jar) something like this:
java -cp /the/full/path/to/lib/colt.jar -jar app.jar
Once you've got that work you can then try and figure out what the correct relative path is. and then you'll be able to do
java -cp a/relativel/path/to/lib/colt.jar -jar app.jar

how to launch java file program with processbuilder?

here i'm trying to launch a java program inside another java program.
after some search in the forum i found some clues but my code launches only .exe file and not .java file why?
import java.io.*;
public class Mana
{
public static void main(String args[])
throws IOException, InterruptedException
{
try
{
Process p=Runtime.getRuntime().exec(" D:\\NetBeansProjects\\GetIPAddress\\dist\\GetIPAddress.jar");
}
catch(IOException e1) {System.out.println(e1);}
}
}
for java file you must run javaw.exe(not java, because java.exe shows new console window) from jre:
Process p=Runtime.getRuntime().exec("javaw -jar D:\\NetBeansProjects\\GetIPAddress\\dist\\GetIPAddress.jar");
If you are ok to use 3rd party library, you can use:
http://code.google.com/p/jlibs/wiki/JavaProcessBuilder
Okay, looks like you have several problems.
First, to call a java program as a jar file, you need to have the jar file. Your question first looked like you already had one (producted by Netbeans). So try this:
java -jar D:\NetBeansProjects\GetIPAddress\dist\GetIPAddress.jar
in a console window (cmd.exe on Windows). If this works, then your call as given by Sergey should work too. If it does not work, then you have to look at how to create this jar file.

Categories

Resources