Edit:
How can I included packages in the .classpath that are downloaded at compile-time by gradlew and use them in Eclipse before compile-time such that my .classpath doesnt include local file paths from my personal computer?
I would like to use the org.apache.commons.cli package, but do so without altering the .classpath file. I'm using the gradlew to build my project, and in the build.gradle file is:
dependencies {
compile 'commons-cli:commons-cli:20040117.000000'
compile 'com.google.code.gson:gson:2.8.2'
testCompile "junit:junit:4.11"
}
So at compile-time, the necessary libraries are managed. However, without them added to Eclipse, using them seems to be impossible as they cannot be resolved.
Question:
If using build.gradle to manage project dependencies, is there a way to use them in Eclipse without going to the project's build path and adding external jar's? If not, what is the general practice for situations like this, where a library is needed to be use, but I dont want my local file path stored in the .classpath, where a user may not have the same jar in the same file path?
You should install and use Eclipse BuildShip to properly work with gradle projects.
Related
Gradle 5.6.4. I have source code of the library I want to add as a dependency to my project. I already know that I can compile it into jar with .class files and then write dependencies{ compile files('libs/mylibrary-compiled.jar') }, but I do not want to lose comments, variable names, etc. Sadly writing the same thing for a jar file consisting of .java files does not work - packages are imported, but classes are not.
I think copy-pasting the sources right into src/main/java directory is an option too but I want to keep my code separate from libraries... So is it possible with gradle?
I'm using eclipse and ant to compile a java project. The ant compile script calls javac using a classpath refid of classpath, which is set based on System Property variable java.build.path.
My java.build.path variable is missing a library that was specified in
Project->Properties->Java Build Path->Libraries.
That is, the external jar was properly added to the list of libraries to add to the build path, is not missing or corrupt, and I have every expectation that eclipse would include the library in the build path. My build fails because java.build.path is missing this library.
Furthermore, the file <projectDir>/.classpath contains a valid classpathentry element for the missing jar file.
When building, javac fails at an import statement, claiming that the package does not exist. The value of java.build.classpath contains many of the libraries I set in the project properties, but does not include the missing library. Its as if the project property for that external jar was never set.
For what its worth, the missing library is jboss/lib/jbosssx.jar
Any help here would be appreciated.
At first,
Download jbosssx.jar jar file from this link
Then keep the jar file in the folder jboss/lib
Hope it will solve your issue.
UPDATE:
Sometimes jar files need to keep in lib folder physically. For this reason, you can put the jar file in your project lib folder.
I found where my configuration was messed up.
Using External Tools Configurations within eclipse, I found another Classpath settings tab for my ant build that did not contain my library.
Adding my library here caused the build to succeed!
Skywalker, thanks for the suggestion. :)
I have downloaded an Eclipse project and I want to be able to have other people compile it without using Eclipse. It is a fairly large Java project that is still being worked on. How would I make a compile script that compiles like eclipse?
I highly recommend you look into Maven. Basically you'll define a Maven pom file in the root of your Eclipse project directory which will contain your dependencies (jars) as well as compile and assembly configuration. With this in place you can simply checkout a project and run a maven build command against the local directory you checked out to and an executable/deployable package will be created.
I have a plain Java project (not a plugin project) which I want to add to a classpath of a eclipse plugin which I am developing. But in web projects I can add that project as a build path and it works fine. But I tried same thing in eclipse plugin, I am able to compile successfully, but at run time I am getting java.lang.ClassNotFoundException.
I know OSGi quite well and I know how to add OSGi into an classpath (using export-packages) but what I want is to add Standard, non-osgi project into an classpath, so that I wont' get runtime errors. Is there anyway I can achieve this?
I can export project as a jar file or make it as a plugin project and it would work fine. But that's not my option currently because, still that API is in pre-alpha stage, and there would be lot of changes going on. So I am trying to avoid pain of exporting it as jar file everytime. Is there any option for me other than this?
I have a similar situation: I want non-OSGi Maven dependencies integrated into the classpath of my plugin. I succeeded with a roundabout solution, which I think is the best I could get.
I have a build step outside of Eclipse where I copy the class files of the dependency into the plugin's lib folder. The lib folder is specified in MANIFEST.MF as an entry in Bundle-ClassPath and (here comes the hack) as a source folder in build.properties. That was the only way to make the plugin work both when launched from within Eclipse and when exported.
I am currently using eclipse for working with Java. Additionaly I use git to synchronize my project between my laptop and my desktop PC.
The problem is now the following: I added external JARs to the project (Slick-Util, LWJGL).
But the path to each library is another on each device. So everytime I start working on the other device, I have to change the path to the jar files and the javadocs.
The libraries are all stored in my eclipse workspace. So the libraries and the projects are all in the same folder. And this folder is also commited with git.
Is there a way to change the eclipse settings (or do something else) so I do not have to change the path to the libraries and javadocs everytime?
I already googled and searched for it, but I could not find something about it.
Just don't add the libraries' jars to git. There are multiple build tools for java, which manage dependencies for you - you just state the libraries you're going to use, and the build tool downloads it for you at build time.
I would recommend Gradle, but Maven is also a very popular choice.
In gradle, you would create a file build.gradle, and define your dependencies in it:
apply plugin: 'eclipse'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'org.lwjgl.lwjgl:lwjgl:2.9.0'
compile 'org.lwjgl.lwjgl:lwjgl_util:2.9.0'
}
Then you would run gradle eclipse from the command line - that would add the libraries you use to the classpath in eclipse. And when you want to compile and package your project you would run gradle build from the command line. You should read about it if you're going to use it, what I describe may not be exactly what you need.
Also, there are instructions for using LWJGL with maven.
add jar files to a lib folder inside your project like this : D:\Workspace\myproject\lib\your-jar-file.jar
then go to your projects build path select libraries tab and click on add jars and NOT add external jars this way your jar files path will be relative to your project
EDIT :
I highly recommend to use a build tool as Kiril Raychev described.
it will look a bit confusing to start with but after a while and after a normal growth in your application that will lead to using different frameworks, controlling and managing dependencies and their conflicts without a build tool will literally kill you.
You can simply use -f flag on add command.
git add -f test.jar
And, then commit and push to your repo.
Up until now i usually use svn so i'm not entirely sure how it works out in git, but have you tried to store the JARs in the lib folder of the project they are used in? (Eclipse displays the lib folder so you can easiely add them to the buildpath with a right click on the library in the package explorer.)
That way the relative location/path of the libraries to the project should stay the same. Furthermore if you plan to pack the project into a JAR later you ship the libraries inside that JAR without having to worry whether the user of that file even has them on his computer.
PS: Looks like i'm a minute too late. Dave basically said the same thing.