I want to run a fat client delivered as a Java web start application without Java web start. I launched it via javaws and managed to get all the jar files mentioned in the JNLP file from the cache after they were downloaded.
I tried running the jar file that contains the main class according to the JNLP file, but I get the 'Could not find or load main class' error. Were I just trying to run a class I'd set the classpath accordingly, but since I'm running a jar file with java -jar, as far as I know the classpath settings will be ignored anyway. Now I'm not sure what to do, does anybody know how to tackle this?
I'll answer this myself now, turns out it is stupidly simple: Get all the jar files, unzip them to get the content, merge all the content (best done with rsync), create a new MANIFEST.MF file that contains the main class to be loaded and the merged hashes for all existing files from all MANIFEST.MF files, zip again to create a jar. That's it.
Related
I have an application build in IIB v10 where i am referencing a java routine from esql. I have created the java class as an independent resource, then exported it as a JAR file and placed it in a folder under C://lib. There was an existing configuration service for java class loader which also pick yet another jar file from C://lib. I then amended the existing configuration service for Java Class loader with the new jar name and its path. Also, did a restart of the broker and inspected via mqsireportbroker command and webconsole to confirm the new jar has been updated in the configuration service. Now when i deploy the BAR file to the server, I am getting the below error.
BIP3202E: (com.xxxx.soa.xx.xxx.createMD5Hash, 1.12) : An error occurred when trying to resolve the Java class or method 'com.xxxx.gen.createMD5.createMD5Hash' which is referred to by the routine 'createMD5Hash'.
Further messages are generated that explain the error in more detail.
Correct the syntax of your Java expression in node 'com.xxxx.soa.xx.xxx.createMD5Hash', around line and column '1.12', then redeploy the message flow.
BIP2943E: The Java Method 'com.xxxx.gen.createMD5.createMD5Hash' could not be found as its containing class could not be found in the deployed bar file or in the 'workpath/shared-classes/' directory.
The specified Java Method 'com.xxxx.gen.createMD5.createMD5Hash' belongs to a class that could not be found in the deployed bar file or the 'workpath/shared-classes/' directory. Ensure that the fully qualified name of the method is correct and that its containing class or jar file is in the deployed bar file or in the 'workpath/shared-classes/' directory.
Examine and correct the SQL program.
When I put the jar file under workpath/shared-classes directorey, its working. But I want the jar file to take from the shared class librarry which is C://lib. What am I missing in this case?
All you need to do it to put your jar in the shared-classes folder.
You can find all the information about it in the IBM documentation really easily, but here is an example on Unix :
/var/mqsi/config/MY_BROKER/shared-classes
You can either put the .jar there, and it will be loaded for each execution group (also called integration servers).
If you know you only need this for a specific execution group, then you can copy it there :
/var/mqsi/config/MY_BROKER/MY_EG/shared-classes
And I would highly recommand you to use the second option, otherwise you might have performance issues if you do this with a lot of libraries
There are only a few paths where the .jar files are loaded from.
See for more information: https://www.ibm.com/support/knowledgecenter/en/SSMKHH_9.0.0/com.ibm.etools.mft.doc/bk58210_.htm
JAR files are loaded in the following precedence order:
JAR files placed in the integration server shared-classes directory allow only a single defined integration server to access them. Files placed in here are loaded first.
JAR files placed in the broker shared-classes directory allow only a single defined broker to access them. Files placed in here are loaded after any files placed in the integration server shared-classes directory.
JAR files placed in the top level shared-classes directory are made available to all brokers and all integration servers. Files placed in here are loaded after any files placed in the broker shared-classes directory.
I found it on windows here C:\ProgramData\IBM\MQSI\config*\shared-classes
using this command mqsireportbroker <my_broker_name>
I have a project which uses both RMI and JDBC and I need to make it an executable JAR. Now my instructions are to make one JAR file with all my source code which ive included all my .java files. My second JAR needs to be the RMI server .class files and then the third JAR is to have all my RMI client .class files.
Now the first JAR and the third JAR I can make no problem but the issue lies with that in my second I require the use of JDBC so I need to include the mysql-connector-java-5.1.31-bin.jar file in it.
My folder consists of the following layout, only default packages are used and everything is in the root directory.
1st JAR - Source Code Jar File Contains...
A2Interface.java
A2InterfaceImpl.java
A2RmiClient.java
A2RmiServer.java
InvalidLocationException.java
DuplicatedAddressException.java
I used this command to jar it
jar cvf source.jar *.java
2nd JAR - Contains the classes related to RMI server, I also need the mysql JDBC jar file included along with it
And I used this command to JAR it
jar cvfm RMIserver.jar server.txt A2RmiServer.class A2Interface.class
A2InterfaceImpl.class *Exception.class mysql-connector-java-5.1.31-bin.jar
My server.txt Manifest file contains the following
Main-Class: A2RmiServer
Class-Path: mysql-connector-java-5.1.31-bin.jar
-empty line as per the docs-
3rd JAR - Contains the classes related to the RMI client
jar cvfm RMIclient.jar client.txt A2RmiClient.class
A2RmiClient$EventHandler.class
Any my client.txt manifest file contains
Main-Class: A2RmiClient
-empty line as per the docs-
Now everything jars perfect fine and I extract my first JAR file containing all my .java files with no errors. I then attempt to run my RMIserver.jar file with the following command...
First I start the registry..
start rmiregistry 5566
Then I run the executable jar file..
java -cp mysql-connector-java-5.1.31-bin.jar -jar RMIserver.jar
AND here is where I get an Exception of the following
Trouble: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: A2Interface
I cannot determine why this is doing this at all. If I dont use any jar files my code runs perfectly fine with ZERO exceptions but as soon as I try this I always get exceptions. I have searched many places and some people say that you cant include the mysql JAR file (or any JAR file) like this and even according to the Java doc here http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
They also mention that its designed for use only for JAR's over the network and not in the same directory, however my professor believes this can be done. I have been trying to figure this out for hours and have come to a wall. I don't know how I can make it work with using the necessary mysql JAR file.
OH and please dont mention using any other tools to create a JAR package as I cannot do that for my assignment or even eclipse. I can only do this from using strictly command line tools.
The ClassNotFoundException is happening in the rmiregistry, and it's being returned to your server application wrapped in a ServerException.
In normal usage, the RMI server annotates the classes with their codebase URL so that other Java processes can load the unknown classes. However, the jar file isn't a usable URL for this purpose (I'm not totally sure, but I think it's because it's generally insecure to load from file: URLs received from the network).
The reason it works when you're not using jar files is because the rmiregistry is able to find the missing classes in its own classpath (because you're running it in the same directory that contains A2Interface.class).
You have two choices:
Serve the class files (or a jar containing them) from an http server running on the RMI server's host, and use the java flag -Djava.rmi.server.codebase=http:... to point to the directory/jar where the classes can be found; or
Insert the common classes in every classpath: server, client, and rmiregistry.
For more detail, see http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/codebase.html.
And here is where I get an Exception of the following
The Registry doesn't have that class available on its CLASSPATH. There are three solutions, in increasing order of difficulty:
Run the Registry inside the server JVM, via LocateRegistry.createRegistry(). When you do this, you must store the result of that call in a static variable, to prevent it being garbage-collected. That also makes it possible to unexport the Registry when you want the JVM to exit.
Run the rmiregistry with an appopriate CLASSPATH. There are several ways to do that, including -J-classpath and setting a CLASSPATH environment variable.
Use the RMI codebase feature.
Now my instructions are to make one JAR file with all my source code which ive included all my .java files. My second JAR needs to be the RMI server .class files and then the third JAR is to have all my RMI client .class files.
Your instructions are incorrect. You need to make four JAR files:
Source code (why?)
.class files that are common to both client and server
.class files that are only used on the server
.class files that are only used on the client.
(3) and (4) need manifests, both to name the Main-Class and to name (2) on the Class-path.
The server deployment needs (2) and (3). The client deployment needs (2) and (4).
I have a web application that I developed in Java over Play 2.2 framework.
When I am running the app locally one of my java class which is accessing some files in the project folders run fine.
After I create a jar file and run it, the java code is not able to read those files. The files are in the public folder and I have ensured packaged in the jar.
There are other files which I have referred from HTML and they are accessible but the java classes are not able to access the files.
Please help me solve this issues.
I think you are trying to access a file inside a jar. If I have understood your question. Please correct me if I am wrong
You could use something like this:
InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileFromJarFile);
If test.txt was in the root of your JAR file, you'd use:
InputStream is = this.getClass().getClassLoader().getResourceAsStream("test.txt");
NOTE : The file and the java class needs to be in same jar file.
The code was all fine in my case, the directory structure at the jar side was where I missed the part.
I had to keep the files/folders in the directory as same as that of the jar as #APaul said, I tried that but it did not work because I was using a batch to run the jar. My files should have been in the folder containing the batch file. My bad!
Anyways Thanks #APaul.
Im able to run exe's in runtime via Runtime.getRuntime().exec(filePath), but this only seems to work for external exe's outside of the jar. I want to run an exe that I've packaged inside of the jar. How would I do this? I'd believe theres a jar load function, because I've seen code that loads it the same way using the name of the file in the jar, but that returns an IO error for me.
You can copy it to a temporary location outside the jar file, I think that is possible.
I need to load an .xml file in META-INF, it works when the application isn't sandboxed, but in Java Web Start a different classloader (which is more restricted) seems to be used, so the file found in myproj.jar/META-INF/myfile.xml isn't loaded. It however works if I put the file in the current directory of the loading class (I put it under com/blabla/myproj/whatever/META-INF/myfile.xml).
I couldn't find any classpath settings within the .jnlp file, but perhaps this can be done with a manifest? I don't know how they work, so if that's the solution please supply an example.
Stuff in META-INF should not be readable by code in your jar file, since that code should be agnostic to the fact that it's packaged in a JAR. Instead, since it is meta information (meta-inf) about the Jar itself, only the application that loads the jar file should access it.