Currently, I have a few custom maven plugins which use the same libraries (JARs) as my application which uses it.
It is pertinent to mention that the libraries are also custom libraries developed by us and not 3rd party.
I want to let go of these libraries and integrate all of them directly inside my application source code - just have one problem - what do I do with
the maven plugins which use them.
Is there a way I can use the application source code (after integrating the libraries) while compiling / running the maven plugins?
Personally I wouldn't go on this path because of dependency hell etc, but if you really need to you could create a jar containing the source files (see https://maven.apache.org/plugin-developers/cookbook/attach-source-javadoc-artifacts.html) and then in the project you need to source unpack it like this https://maven.apache.org/plugins/maven-dependency-plugin/examples/using-dependencies-sources.html.
ps: what is the reason to drop the libraries and instead use the source code?
Related
i'm currently working on a Lexer in Java, i'm using jflex to do this, when my partner runs the code it works, he pushed it into a repo in github. I cloned it and when trying to run it, it says it cannot find a symbol which is Lexer, this is a class that jflex creates. I
I was expecting to be able to use the jflex library, which is stored in the lib directory in the project, also, in the .vscode directory we created a settings.json in order to be able to use it, we thought it worked but apparently when someone clones the repo it doesn't work. How can i solve this?
Download needed library
Commonly, projects uploaded to GitHub omit the various libraries needed by the app.
So you will need to manually obtain the needed library, usually a JAR file. Then place that JAR file in a location accessible by your project.
When deploying your app, you will need to either include the library within your app, or make the library available on the runtime computer.
Dependency management & build tool
Needed libraries are referred to as “dependencies”.
If doing any serious work in Java, I strongly recommend you learn how to use an IDE (such as IntelliJ, Eclipse, or NetBeans) in conjunction with a dependency management tool (such as Apache Maven or Apache Gradle).
Tools like Maven & Gradle will automatically locate a copy of your declared dependency libraries, automatically download from a repository, and then install within your project.
These tools (IDEs, and dependency managers) do come with a learning curve. But that learning time is well spent if you are invested in being a Java developer.
This question already has answers here:
How to include libraries in Java without using an IDE
(6 answers)
Closed 8 years ago.
I'm trying to use a java lib to connect to a database, im doing the tutorial outlined here, http://www.homeandlearn.co.uk/java/connect_to_a_database_using_java_code.html
and I can get it to work in netbeans by putting the .jar into the library file in my project file but I don't have a clue how to get it to work hen using an ide such as vim. can someone help?
If I got your question right, you can find the right answer on this other StackOverflow post: how to include libraries in java without using an IDE
You need to build both files into a JAR file, then you can run it.
I hope this helps.
A build tool which features dependency management such as Maven will help solve this problem. To use Maven you will add the location of libraries you require to an XML file (pom.xml) and Maven will download them for you and incorporate them in your target application archive (e.g. a war file).
Maven central provides a means to search for dependencies. In your case you can find the Derby client jar here. Click on the version of the library you would like to use and you'll see the sections of build descriptor code you needs to copy and paste in for: Maven, Ivy, and a few other popular build/dependency management tools.
Once you are comfortable with Maven, you could look up the Maven "Shade" plugin which will help you create a single jar file containing the necessary dependencies to run your application.
Vim, is more of an editor than an IDE, so you will need to specify the library .jar files manually on your class path when running your application.
You can do this by specifying the -cp parameter to the Java executable. e.g.
java -cp driver.jar MyMainClass
The way you are trying to use the library you desired requires manually adjusting your CLASSPATH. Oracle has some detailed instructions on that: PATH and CLASSPATH.
Though, I would suggest to use some kind of build tool which makes it easier to handle your applications dependencies.
In the Java world, the most convenient tools are Ant, Maven and Gradle.
I feel you have just started Java development, so I would prefer Gradle in your case, although Maven is still pretty widely used in projects.
With these build tools handling dependencies will not be -lets say- wired in the IDE and you can easily build your application in any environment.
I am new to openIMAJ and I want to process some pictures using it. There are a lot of tutorial available but they all tell using Maven. Does anyone know from where I can download the jar files of openIMAJ to directly use in my Java project?
Thanks!
For all the features of OpenIMAJ there are more than 50 Jar file that you need to Download individually. Also if you somehow manage to find all those files manually on internet you may end up mixing some or other version which will make some classes incompatible. Although I would strongly suggest you to try understand what maven is and its capabilities, you can follow the below steps if you dont want to add dependencies using maven or even don't even want to know what it is.
1.) Go to Help Menu -> Open MarketPlace.
2.) Search for maven and download the plugin.
3.) In file menu create new-> new maven project
4.) Select your workspace and click next
5.) In the select an Archetype window look for add archetype and enter the following details
GroupID: org.openimaj
ArtifactID: openimaj-quickstart-archetype
version: 1.1
URL: http://maven.openimaj.org/
6.) Click next and give details of your own project and click finish
All the jars will be downloaded which you can see in your project structure. You can now stop worrying about maven and start concentrating on openimaj.
OpenIMAJ is rather complex and contains a lot of modules that you probably don't need to use in your project (i.e. if your making something to do image processing, you probably don't care to much about audio analysis, or content analysis of web-pages). In addition each of the OpenIMAJ modules has dependencies on numerous other projects (which themselves have dependencies, and so on). For these reasons, it isn't really all that practical to provide direct downloads of all the modules and their dependencies as it would take an incredible effort for the user to try and figure out which bits are needed and which bits are not.
The ideal way to specify which bits of OpenIMAJ you need is to use an automatic dependency management system; this does not need to be Maven however - any Maven compatible dependency manager will work (i.e. Ivy, SBT, Grape, etc...). There are examples of the snippets you need to add to your build system configuration for these on the OpenIMAJ front page in the box on the right (you might need to scroll down a bit).
If you really do want to manually include the relevant jar files in your existing project, I'd recommend the following approach, which uses Maven to build a customised set of jars based on the exact OpenIMAJ modules you need:
Run mvn -DarchetypeRepository=http://maven.openimaj.org -DarchetypeArtifactId=openimaj-quickstart-archetype -DarchetypeGroupId=org.openimaj -DarchetypeVersion=1.2.1 -DartifactId=oi-deps -DgroupId=oi-deps -Dversion=1.0-SNAPSHOT -DinteractiveMode=false archetype:generate to create a basic OpenIMAJ project (called oi-deps in this case).
Go to the oi-deps directory: cd oi-deps
Edit the pom.xml file to include only the bits of OpenIMAJ you need by removing any unnecessary <dependency> sections.
Run mvn dependency:copy-dependencies. This will create a target/dependencies folder that contains all the jars you need to add to your project.
I also didn't find any 'download all' site. And I think the reason is that there are a lot of dependences in some jar files.
I extracted some jars recently to use in a project without maven but that was quite wiry.
And I was only able to do this using another project with maven.
I think maven is good stuff and easy to use within ie. netbeans. So give it a try.
I have multiple projects, an Android project and a couple of "Java Library" projects that I need to import into my main Android project.
My library uses springFramework.jar, when I include this library into my Android I get the following exception.
10-01 11:35:04.101: E/dalvikvm(1144): Could not find class 'org.springframework.web.client.RestTemplate', referenced from method com.nuvasive.shared.atlasmobile.service.ServiceClient.
If I include the jar files into my main project as well as the library everything works fine, but I rather not do that.
So there are two problems here:
Seems like jar file in my library is not being added to my main project
My main project can't access classes in my library project
What am I doing wrong here?
According to me if you have added jar files to build path(check in libraries tab) then remove them from that tab and as i can see you have not marked jars you are using in order and export please nark all jars you are using. You will see those under private libraries in libraries tab.
Try it.
I'm not entirely sure what you're trying do without knowing what 'springFramework.jar' is, what libraries you have linked in all your projects, what your code is doing, etc., but my guess is that this is some kind of dependency issue.
Check out http://mvnrepository.com/search.html?query=spring+framework+. Although this site is designed for maven dependencies, I believe you can download any of the jars directly.
'springframework.jar' is probably an older build of Spring that combined multiple components that are now broken up into different modules (spring-core, spring-jdbc, spring-web, etc.) Perhaps your main project has another needed dependency that your Android project does not?
Can I programmatically use an Eclipse plugin in my java code (so that it is independent from eclipse)?
Yes you can if:
The plugin you want to use doesn't have any external dependencies => it's just a library plugin
The plugin you want to use and ALL it's dependencies are in your classpath
No in all other cases. Because many plugins use at least the core concepts of OSGI/Equinox (have an activator) it will be quite hard to use them in a standalone java app.
For example, SWT can be used outside eclipse.
You should take a look in your eclipse directory. In the plugins folder you'll find a lot of .jar files. Sure, you could use these as dependencies in your project.
Yes, sure, you just need to care deploy plugin's jar files with you project properly.
Eclipse plugins are OSGi bundles.
OSGi bundles are JAR files that have extra info in META-INF that declares exports and imports. They sometimes make calls to OSGi APIs.
Many Eclipse plugins depend on other Eclipse-specific plugins.
If you use OSGi in your environment, you can easily reuse those plugins that have no Eclipse dependencies. If your application is not OSGi, you can only easily reuse those that avoid the direct use of OSGi APIs.
Well designed plugins are split into UI and "core" parts. You would probably want to grab just the core component. And you may well need to provide an OSGi framework to properly load and activate the plugin too - depending on how complex it is.
As others have also mentioned, don't forget the dependencies.