Eclipse : Add jar file and not depend on local machine path - java

I'm working on Eclipse with a java project. In this project, I include a jar file. But when I include it, eclipse remembers its path base on local machine. For example : if I'm on Windows, the path will be C:\Document\... and if on Linux, will be /hqt/workspace.. for example.
Although, in project folder, I create a folder lib and copy jar file to here, hard link to this jar doesn't change. So, when I copy this project to another place that jar file doesn't same with my current local machine, jar file will be missed and must re-config again.
So, my question is : How can i include jar file and not depend on local machine path.
Thanks :)

Do not use "Add external JARs...". Put the jar in the "lib" forlder you have created in your project then add it to the classpath using "Add JARs...".

Related

Is there an option for intellij to build directories outside the JAR file?

So what im trying to do is to build a JAR artifact which should include the necessary libraries as well as directories which are outside of the JAR file and can be looked at in the explorer.
I have already tried to add directories to the artifacts but these get put into the JAR file in a folder which i cant access later when converting it to a exe using launch4j.
Is there an option in Intellij to exclude directories from building into a JAR?
Edit: I want the output directory like this
Directory Structure

Run jar that depends on external jars inside JRE folder

Case: all external jar files are in the folder
/usr/lib/jvm/jre-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86_64/lib/ext
I need to run my executable JAR that uses these jar files internally. Do I need to specify them when explicitly starting my jar, or since they are inside the JRE directory, will they be automatically pulled up?
The jar files inside the jre folder will be found automatically because you must have set the path of java to the folder in the system path.

How to build a java app in Maven with resources outside of ".jar"

I made a little java app that modifies an Android Studio project and executes "gradlew.bat" to build the .apk and move it to an "output" folder.
As you might expect this project has to be saved outside of the .jar (AFAIK I can't execute a Gradle build inside of it).
I converted it from a plain Idea project into a Maven project to automate my workflow a bit. But Maven packs my resources in the "res" folder inside the jar. It also builds in the "target" directory and I want it in an isolated folder.
I need Maven to build the .jar file with the source files in an isolated folder and, in the same folder, copy the resources to the file system instead of the .jar.
Edit: For clarification. I want the project to have a more standarized layout so I can push the project to Heroku. Heroku will compile and execute the .jar using its Maven configuration but will not pass the other files to the filesystem to be along the .jar and instead, pack the resources inside the .jar.
The result I want is:
Whenever I execute a Maven build, the "target" directory should have the .jar file and two resources (A folder with files and a .ini file) within the same directory. It is not possible to do that myself as Heroku works automatically.

Creating jar from java project which uses jdbc

I have finished my java application using eclipse, with some sql code. I am using oracle database and jdbc connector.
When I am trying to create a jar file it shows me this message: JAR export finished with warnings.
See details for additional information.
Exported with compile warnings:
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-path entry for 'C:Users/Grlouk/Downloads/ojdbc6.jar'
And when finally I am creating a.exe file from .jar database functions does not work. Any suggestions?
It would appear that the exporter is looking for the JDBC library ojdbc6.jar in your C:\Users\Grlouk\Downloads folder and finding it missing.
There are a couple of ways to fix this.
1) Find where your ojdbc6.jar file is located and put it in C:\Users\Grlouk\Downloads
2) Change the classpath to reflect the actual location of ojdbc6.jar file, e.g. if you are using the Eclipse IDE you can right click on your project and Build Path > Configure Build Path... to open the build path configuration and then under the Libraries tab you can manage the libraries, and under the Order and Export you can explicitly state which libraries will get exported, you might want to select the ojdbc6.jar here if it please you.
Placing jar inside a jar won't work. You have to use it with some third party libraries. Because when you are trying to executing the jar file it tries to search the jar files in the mentioned path. Jar file will not be present in the path so classpath fails. Do it with eclipse by exporting to jar.
Eclipse will load the jar files on the fly and add it to your classpath.

Eclipse: copy the Java Build Path to a different workspace

In Eclipse how do I copy the Java Build Path to a different workspace?
Somebody somewhere wrote that if you copy the project then you have copied the build path also. This doesn't seem to be the case.
I've tried copying the entire workspace to a new directory. Opening Eclipse and pointing it to the new directory has all the projects and source files but the build path for my project is empty. It doesn't even have the basic Java source files to build against (java.lang.Object).
Eclipse 3.3.0 (Europa)
Any ideas?
The build path is stored in a file named .classpath in the project's root directory. I don't know of any different way, and copying the directory should also copy that file, of course. How do you copy the project? What OS?
Be very careful...
The workspace itself is just metadata in eclipse that points to your project folders. If the projects are not actually in the workspace directory, you aren't actually copying them, just references to them.
This can happen if you use "Import existing projects into workspace" that are folders in the file system without the "copy into workspace" checkbox checked, or if you create a project using an existing directory.
If you copy that workspace to a different machine, the projecs won't be there.
If you want to share projects, your best bet would be to use source/version control (subversion, for example) and have everyone hook up to the same repository.
Another note on the build paths -- if you have a java project reference an external jar, the absolute path of that jar is stored in the build path. This can be bad if other people who are sharing that project have the jar in a different location on their machine. If this happens, you should look into using Classpath variables or user libraries in eclipse.
Can you comment more on what you're attempting to do when you do the copy?

Categories

Resources