Java RMI - jar on NetBeans - java

I have an RMI server that is using a class from another project. I have imported the jar of the other project as library on the RMI and it works fine on netbeans. Although when I run the RMI Server from the .jar generated by netbeans, I am getting classnotfoundexceptionfor the class imported.
Any suggestions why it would be running inside netbeans, but the jar isn't working?
Also I am not sure if it was the right choice but on the RMI I have checked " used dedicated library folder" since the other project is very small.
Also note I am importing the server on the other project too, so that it can use the remote interface.( although I guess this has nothing to do with the problem).

When you launch your rmi server you put in the classpath also the jar with the other class?
Try to launch the jar from command prompt:
java -jar -classpath rmiserver.jar:lib/other.jar rmiserver.jar

If you've built your project with a standard netbeans project (instead of a maven one), you'll see a lib directory underneath the dist directory where the final jar is built. Netbeans will build the manifest in the main jar file such that it will look for the dependent jars in that lib directory which is relative to the location of the built jar. So if you put your built jar in one directory, copy the lib folder to that directory, then launch it like so:
java -jar my.jar
e.g
+ folder
| my.jar
+-+ lib
| other.jar

Related

How to add jar files to java project without gradle or Maven or Eclipse

Can I add a jar file to a Java project I created on my desktop manually without using gradle, Maven or any dependency management tool or any Java IDE? Currently the project is a single folder containing 5 java files and I run it from the terminal. Is it possible to use a jar dependency in this kind of project. If Yes, please show me how.
Look at this answer
Supposing you have in the root directory of your project a Test.jar and a lib directory containing jar files :
Windows
java -cp "Test.jar;lib/*" my.package.MainClass
Unix
java -cp "Test.jar:lib/*" my.package.MainClass
You could use the -cp compiler option.

War file creation with out eclipse

I am linux admin and i want to automate the process of java web application deployment process in my client location. And actually they are using svn tool for version control.
So my question is if they commit the​ code into subversion repository automatically create a war file through bash script and move that war file into tomcat for automated deployment....
This is my thought.. can u guys suggest me about war file creation remain process i can build through bash
Thank u in advance
To create war file, you need to use jar tool of JDK. You need to use -c switch of jar, to create the war file.
Go inside the project directory of your project (outside the WEB-INF), then write the following command:
jar -cvf projectname.war *
Here, -c is used to create file, -v to generate the verbose output and -f to specify the arhive file name.
The * (asterisk) symbol signifies that all the files of this directory (including sub directory).
There are multiple ways to create WAR file
Using ANT/Maven or many times framework also provides command e.g. Play Framework.
You basically need to go to the SVN checkout project folder.
if you have ANT or Maven project than follow the steps :
How to create a WAR file using the commandline?
How to create war files
else for other Java based project :
To create war file, you need to use jar tool of JDK. You need to use -c switch of jar, to create the war file.
Go inside the project directory of your project (outside the WEB-INF), then write the following command:
jar -cvf projectname.war *
https://www.javatpoint.com/war-file
You can then copy the newly created WAR file to Tomcat webapps folder using linux command
SCP or CP.

How to make jar file created by netbeans work from any location in the system

I have a java desktop application in netbeans. I have created an executable jar file for the project using clean and build command provided by the netbeans. By using this command the executable jar file gets created under netbeansProjects//dist/.jar. I am able to execute this jar file from command line using java -jar .jar from within project path. But the problem is that when i move this jar outside of netbeans projects folder, say to desktop and run the jar file, it is giving error of type "Exception in thread "main" java.lang.NoClassDefFoundError". How to solve this problem and make the jar file executable from any location of the system.
Complete instructions may be found in dist/README.TXT:
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Ensure that the manifest inside of the jar file contains the necessary classpaths. If you are unfamiliar with the concept, go here: http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
Netbeans has probably included any external projects/libraries/Jars in the dist/lib folder.
In order to run the application, you must include all the files in the dist folder when you copy the application
Check if in your projects Manifest.mf file has the Attribute
"Main-Class" set to your projects current main Class file.

How to create a jar file for the eclipse plugin project that should be able to download and run without eclipse software?

I m doing an eclipse plugin project to create an IDE. I need to create a jar file for the plugin project in which i have four plugin packages which was created by me. Now I need these to be created as a single jar file and the user should be able to download the jar file and run my plugin project without the eclipse software.
EDIT-
You cannot run Eclipse plugin outside of Eclipse, because you need the Equinox runtime container. you could run a plugin using the eclipse executable, and as an application, see:
http://wiki.eclipse.org/FAQ_How_do_I_create_an_application%3F
You're effectively creating an an org.eclipse.core.runtime.applications extension point.
You could also publish a plugin as part of an Eclipse application and then export it as an executable so that it can be run aside from Eclipse. This still bundles the Equinox runtime and plugin together though.
Also, check out "Running it outside of Eclipse" section here.
-END of EDIT
Generally, all you need to run an executable jar file is the jvm (java) and your code with all the classpath dependencies. You can use "Runnable Jar Export Wizard" available in Eclipse IDE when you right-click your project.
You can put all the dependencies inside your jar (for example you can create a lib directory in your project and put all your dependency jars inside). Also you will need to specify the dependecy location in the MANIFEST file that will be generated for your executable jar (if you use the wizard the MANIFEST file will contain your dependencies).
To run your executable jar you will need to execute:
java -jar jar-file
Good Luck!

I need some help concerning using 2 jar files in Java

Well I have 2 .jar files. The main jar file is the jar file for my whole project and the other .jar file being the MySql JDBC Connector.
Well basically whats happening right now is that when I build the project I have the one main .jar file with everything but the MySql JDBC Connector .jar file is inside the main jar file when it builds in NetBeans.
Now when I am just running the project from within NetBeans the MySql JDBC driver can be found inside the src/com/game/mysql folder that I have it in. But when I build the project the Java application cannot locate the JDBC driver from within the main jar file.
When I open the main jar file with WinRar I can see that the JDBC jar file is still in its /com/game/mysql/ folder. But why cant the Java application access it?
I have heard that nested .jar files are not supported in Java so Im thinking this might be the reason although Im not sure if thats true. Is there a way that I can make it so that the application can find the JDBC .jar file within the main jar file?
Also I have done the thing in NetBeans where you add the .jar file through right clicking project -> properties -> Library -> Add Folder/Jar. Thats what makes it work in the NetBeans run but still not the App build.
I have heard that nested .jar files are not supported in Java
More precise, classes in a JAR file which is packaged as a child JAR inside a main JAR are indeed by default invisible to classes in the main JAR.
You have basically 2 options:
Ship your application with 2 loose JARs: your.jar and mysql.jar and define the relative path to the mysql.jar in the Class-Path entry of the MANIFEST.MF file of your.jar.
Class-Path: mysql.jar
When you put both JARs in the same folder and execute your.jar by java -jar your.jar, then it will work.
Let your IDE repackage all loose classes of mysql.jar inside your.jar or add a special classloader which preloads the classes of any embedded JARs. Since I don't do Netbeans, I can't tell whether it supports it and if so, how to do it. In Eclipse, however, this is definitely possible. See also this answer.

Categories