How can I use external jar files in my Ewon project? - java

I am working with Ewon hardware project which supports javaetk run time environment.
Now some of the functionality like JsonReader, Logger, etc are not available in javaetk. So I download this jar file externally and include it in my project.
Looks fine at Eclipse level! But at run time it shows error on Ewon error blog that class not found! Any suggestions, that how can I use this??

We could extract external jar files of higher versions of java environment and put it in our project's bin folder. So works fine!

Related

java - Sharing an executable .jar file

I wrote a program in NetBeans, and now want to share it with my coworker. However, when he tries running it on his computer, he gets an error message:
"Could not find the main class: excelcomparator.ExcelComparator. Program will exit."
Here's the confusing part: I wrote this on my laptop which has NetBeans, and to make sure that it worked, copied the dist folder onto a flash drive, and ran it on my computer. It worked fine. When I emailed it to my coworker, he got that error.
Based on what I've seen, some solutions are to run the .jar from the command line. While that might work, I need the file to be double-clickable.
I sent my coworker the file via email in a zipped folder, is it possible that unzipping the entire folder also messed up the .jar file (don't see why it should, but included anything that might help)?
This is the MANIFEST.mf that's within the .jar file. There is a carriage return at the end of the file, it just doesn't copy well into this text box:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.7.0_71-b14 (Oracle Corporation)
Class-Path: lib/poi-3.12-20150511.jar lib/poi-examples-3.12-20150511.j
ar lib/poi-excelant-3.12-20150511.jar lib/poi-ooxml-3.12-20150511.jar
lib/poi-ooxml-schemas-3.12-20150511.jar lib/poi-scratchpad-3.12-2015
0511.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: excelcomparator.ExcelComparator
I sent the dist folder, which includes the lib folder which contains all the additional .jars.
If there's any other relevant information I need to include, let me know. Thanks!
If you want the JAR to be double-clickable then you should bundle all the dependencies into a single JAR file.
You achieve this using the maven assembly plugin: http://maven.apache.org/plugins/maven-assembly-plugin/usage.html
If you don't know how to use Maven, Eclipse has a nice wizard. I'm not sure how it works on NetBeans but the same question has been asked many times, e.g. here Netbeans Export to Jar, include all library files
Just to finish this off, I'll write what ended up working for me:
As per Franz Becker's suggestion based on this question, I bundled the entire program into a single .jar file.
I was still getting the same error on my coworkers computer, so based on other suggestions I saw, I guessed that the problem was based on different versions of Java installed on our computers. What I did was recompile the program to an earlier version of Java, which works with any version from then and onward (other people suggested reinstalling Java on the users computer. That's a bit too unrealistic in most scenarios).
To change the compliance level (in Eclipse): right click on the project in Package Explorer, select properties. Choose Java Compiler in the options on the left. Uncheck 'Use compliance from execution environment [default target JavaSE] on the 'Java Build Path'', and change 'Compiler compliance level' to your level of choice (I picked the lowest option available, 1.3, as I assumed anything higher than that wouldn't be an issue).
I then exported the file (File -> Properties -> Java -> Runnable JAR File), and had a working, clickable .jar.
Thanks to everyone for their help!

JFreeChart Java JAR not running on a different machine

I have created an application using the JFreeChart library for use on another machine.
Previously I have developed applications with JFreeChart (using the same libraries) which has worked fine on other machines. The only difference is this machine is running Vista.
Please see below for the run-time exception I am getting:
The class that cannot be found, however, is located in the highlighted jar in the below image showing my imported libraries for the JAR. I have also established that this JAR is included in the manifest for the application. See below image:
So I very much need this to work and have no idea where to look next - or what is causing this problem!
Development machine Java version:
1.7.0_45
Target machine Java version:
1.7.0_45
Thanks in advance.
Check the Class-Path attribute in your JAR's manifest, which should contain entries like this:
Class-Path: lib/jfreechart-1.0.17.jar lib/jcommon-1.0.21.jar …
Also, examine dist/README.TXT in your NetBeans project folder, which should say something like this regarding libraries required by your project:
To run the project from the command line, go to the dist folder and
type the following:
java -jar "CISOnlineMonitor.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
This has nothing to do with os i belive.You dont have all the necessery libs within your jar.Try to open a jar and see if you have them in.Fact that you are able to run it on your maschine only proves that.Make executable jar with eclipse or whathever you use.And when it ask you for libs check -Extract required libraries into generated Jar.
if you dont know how to get to that point
File>Export>Java>Runnable Jar File> Runnable JAR File Specification.
Also right click on your project and check Your build path.
RightClick project>Properties>Java Build Path>Libraries
Make sure you have everything correct
EDIT-
As i see you use NetBeans im not sure exactly how to find all this there.Bud it will be very similiar.

Importing .war file using cmd

I'm developing an Installer for a project team to reduce the amount of work they have to do installing it manually.
We are using:
Windows 7 x64,
Eclipse Kepler
Right now I'm looking for a way to import a .war file using the commandline.
Is there any way to do this via cmd?
First of all, I would not recommend importing the source code from a file in Eclipse if you have a team of developers, as you would be giving everyone a version that will hardly be actual after some days of work. Using some repository (CVS, SVN, GIT) would be the way to go.
If you have your code in a central repository, then you could make a "Project Set" file in Eclipse wich can be imported easily to setup your whole workspace:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-cvs-project-set.htm
This project set might have instructions on how to construct the Workspace based on checkouts of the repositories you need.
If you happen to work at a company that uses some X or Y old-fashioned Source Control tool (or worse, none at all), and you have no chances of implementing one that is compatible with Eclipse (like the three I stated above), then the time you are saving with automating the import of a war file will become irrelevant compared to the source code control issues you will be facing (or the team is facing already).
A WAR file is a ZIP file. If you need the content of the WAR you can use the tools for ZIP archives.
A workaround in case eclipse does not have any such options would be to
do a Import WAR through eclipse GUI
check what changes are made to workspace by eclipse (eg. folder created with exploded war file content, configuration files created by eclipse in the folder like .classpath for project folders etc)
Identify the steps and replicate the same through a batch file
Add a call to the batch file in eclipse launch short cut
There is no command line API I know to do this task for Eclipse just from command line, but with the right tools you can achieve what you want.
Please try this:
Straightforward approach that works with any GUI application. You can use AutoIt scripts for interaction with any application. The downside is that GUI may change more frequently than command line API.
Try to create Eclipse project with metadata and unpack WAR file in this project. It can be done, for instance, with Maven or Gradle. Those also can download all dependencies for you.

Exporting to Runnable jar with extra native code libraries in eclipse

I am having trouble exporting my java project from eclipse as a jar executable file. My java project uses an external library (its called jri). I have exported the jri.jar file and set the library path for its native library in eclipse, and it works great in development in eclipse. However, when I export it as an executable jar file I get the following error:
Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
I have placed a folder called lib in the same directory as my project's jar; this lib folder contains jri's native library. jri's native library is not in one file but in a folder. This is the same setup I have in eclipse.
The way I am exporting my project in eclipse is
Export...
Java > Runnable JAR file
Copy required libraries into a sub folder next to the generated Jar
Finish
And my folder is organized like this
folder project
project.jar
project_lib
jri.jar
jri native library folder
The MANIFEST.MF of my project.jar is:
Manifest-Version: 1.0
Class-Path: . project_lib/jri.jar
Main-Class: index
What I want to achieve is to give another person a folder including project.jar and anything else needed so she/he can run it without needing to install anything else.
Thanks so much
Add a script containing something like that:
#!/bin/bash
java -Djava.library.path=project_lib/native/ -jar project_lib/jri.jar
I export some java projects that way.
This is relatively hard to implement. The solutions I have seen involve extracting the native libraries in the JAR to an OS temp directory and then loading it. I would go for an integrated solution for that. One Jar and Java Class Loader support it, and on the second page you will find links to similar tools.
You can put the libraries inside your jar:
Export...
Java > Runnable JAR file
Package required libraries into generated Jar
Finish
I always export this way.
I don't know if it will work in your case, but worth a try.
Edit:
See these links:
Instalation, setup and setting environment properly
What to do when getting Cannot find JRI native library!
My guess is that this have something to do with LD_LIBRARY_PATH not correctly been set. Or the file wich it is searching for isn't in the path listed.
You know I had the similar problems
Could not extract native JNI library.
all above proposes can't help me. I couldn't stop and start gradle deamon by using follow command:
gradle --stop
I saw that gradle deamon still not stopped in my processes. That's why I kill it in my process and all will be fine :)

Create java application jar file in eclipse

I have created a java application in eclipse, wich needs comm.jar and jexcel.jar and .property files so i have added to libray. I want to make a jar file out of my java appliction, including the external jar files added to the appliction.
How can I do it? To run serialport programs I have copied win32.dll into java_home/bin and comm.jar into java_home/jre/lib and javax.comm.properties into java_home/jre/lib, but when delivering the product it should run only by needing the jre.
How can I solve this? Please help me.
Thanks in advance,
suma
Although your question is not totally clear I suggest using the Fat Jar Plugin should allow you to achieve what you want.
You can use File > Export > Executable Jar which includes all libraries. There is also a checkbox to generate an ant build file as well as the jar in order to customize it further (I for instance make all the paths relative and remove the main-class flag).
You have two "path" issues. The Java Classpath and the path from which dlls are loaded.
If you were using a Java EE app server or OSGi then controlling these paths is addressed by the respective runtimes. Both Java EE and OSGi are likely to be overkill for small projects.
In which case you are delivering:
Your application JAR
The dependent jars
The DLLs
I suggest that on installing your app you place these artefacts into a suitable directory structure, for example .../myapp/lib for the jars and .../myapp/bin for the dlls. Don't copy them into the infrastructure directories, for example the JRE lib and bin, or into Windows32 - that just leads to version nightmares and mysteries when someone installs a new jre.
Having got that structure, how to control the paths? For the classpath, look at the Manifest.mf file. tutorial
For the DLL path, I know of no good alternative to setting OS level environment variables ** before ** launching the JVM. Hence you need a little batch/shell script to launch your app, setting the PATH appropriately.
You can also check maven.
You can right click on the project and say "Export". Now select "Java" in tree of choices. Under that select "Jar File". It'll guide you through the process and will allow you to export you project as a jar file.
Hope thats what you are looking for.
The recently released Eclipse 3.5 has a Export as runnable Jar which allows to put all dependent jars in a subfolder to the jar file, and get the Manifest right.
It is an adaption of the FatJar plugin. Works nicely!

Categories