I recently found the library Libsodium and was glad that there are also Bindings for Java. Unfortunately, the libraries don't appear to work with Windows because they were developed for other systems.
How can I use the libraries under Windows (if possible)?
Are there any alternative libraries for Java?
On that page for other bindings, you find the Java binding is called Kalium. You'll see it requires Apache Maven. So I went and got that (at the bottom it explains how to install maven, but basically you just add some environment variables).
Now on to kalium, I got it from their abstract on github. I needed mvn clean install from the directory in order to install it in Maven. After changing directory to the unzipped Kalium folder I ran the specified command (which is telling Maven to get the files and install Kalium). This will handle the rest of the set-up.
Then it's just a matter of adding it as a dependency in your Maven projects as per the Kalium readme. As for libsodium: it is a library that works with MinGW, and VisualStudio in Windows. So if you want to do C/C++ coding you can use that instead. But for the Java binding it seems you'll have deploy it using Maven.
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.
So I installed Apache Netbeans. Installed some of the plugins and instead of just seeing the Java folder in the categories when I want to create a new Project, I see this:
What is Gradle, Ant, and Maven? I am not familiar with Java and wanted to study the language, but I have no idea of what these are.
I keep seeing that I need to have certain plug ins installed and active.
Here they are.
Ant, Maven and Gradle are Java build tools. You don't really need to know the exact differences though.
Java with Ant
The "Java with Ant" option uses NetBeans' own internal project format (based on Ant). In older NetBeans versions this category was simply called "Java"
If you don't need to share your project with non-NetBeans users, use that option.
You will have to manage dependent libraries yourself (download, add them to the project) unless you are only using libraries and frameworks that are bundled with NetBeans. The turnaround times (the time it takes between you hit "Run" and the application actually starts) are the shortest with this option, as Maven and Gradle add substantial overhead to that.
Java with Maven
Maven is a standardized dependency and build management tool. A project defined with Maven can be used by everybody else as it automatically manages (and downloads) any dependency.
Use that option if you know you need to share your project with other people (e.g. hand it in your school or university).
Java with Gradle
Gradle is yet another build tool, which also manages dependencies for your and has more flexibility than Maven. However the build scripts are less standardized than in Maven. But that is also a good option if you know that you need to share your project with other people.
Unless you are using NetBeans 11.1 (which is currently in Beta) I would not use this option as Gradle support in older versions is not as good as Ant or Maven support.
You might want to go through the tutorials on the NetBeans homepage:
http://netbeans.apache.org/help/index.html
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.
Where can I find the jar file or the source code of JEE6? Or is there another way how you can get autocompletion for this in Netbeans/Eclipse?
And I have just installed glassfish so that i can use JAX-RS but i do not understand how it works. Why does the javacompiler find these classes but netbeans does not? I building with maven2 but have not set any paths or so.
And why am I not able to install JEE6 without glassfish? I just do not need an application server for a REST service with Jersey.
Best regards,
CQQL
Question #1:
See this example project.
The example project is built with maven, which may answer your question about auto-complete. Netbeans 6.8+ (approx) has built-in maven support. After the first build of the example project, I think you'll see that auto-complete works better for any dependencies (i.e. jersey) inside the pom.xml. In my Netbeans, auto-complete works, but the javadocs are not there, which may mean that Jersey wasn't bundled with them.
Question #2: Your maven on the command line and the one inside Netbeans are different copies. You can make Netbeans use a specific copy of maven in Tools/Options/Misc/Maven/External Maven Home. This may clear up some confusion.
Question #3: Jersey can run in Tomcat or Jetty if you find Glassfish to be too much app server for your needs.
Perhaps the reason I stalled learning Java until now is because I HATE how Java handles external libraries. I'm stuck keeping them in one place, adding them individually, fixing problems with versioning and every time I move/rename them, and copying and writing the classpath over and over each time I release a Java application.
There has to be an elegant solution to all of this. I keep all of my libraries (regardless of task, platform, or other) in their own little folder inside a "lib" folder in my development folder, kind of like this:
Dev
-lib
+JS-jQuery
+Flex-Degrafa
-Java-Xerces
+Xerces-1.2.3
+More libraries
I can use either Netbeans or Eclipse for Java dev, but none of them provide a very streamlined (and not to mention idiot-proof) way of managing all of these.
A nudge in the right direction or an online article/tutorial on this would be greatly appreciated.
You can either use Ant + Ivy or Maven to manage your library dependencies.
If it is only dependency management you're after and you're happy with the rest of your build process, I would use Ivy, as it can unobtrusively manage your dependencies, leaving your existing build process intact. There is a plugin for Eclipse called IvyIDE that contributes your dependencies via a classpath container.
Maven 2 has a steeper learning curve but provides a much richer set of functionality for building your projects and Eclipse integration through m2eclipse or IAM.
Personally I use Maven as I have a large number of projects to work with and Maven is particularly suited to efficient development across lots of projects.
Have a look at the introductory documentation to see what works for you.
Ivy Tutorial
Maven Getting Started Guide
Netbeans 6.7.1's Maven support is quite good and comes out of the box with the IDE.
The Eclipse addon was frustrating enough that I gave Netbeans another try.
A third choice besides ChssPly76's options is to use Ant with the Maven Ant Tasks. I don't know if I'd call any of these solutions particularly "elegant," but they do spare you the need to manage your own lib/ directory and classpath variables.
If you're working on Linux you can install Java libraries with APT or RPM.
Otherwise, I normally check precompiled JARs into a lib directory in my project's version control repository and make sure the names of the JAR files include full version information. E.g. lib/foo-1.5.6.jar, not lib/foo.jar.
To avoid having to manually set the classpath before running your app, you can set the classpath in the Manifests of the JARs themselves to define the dependencies of each JAR file. The JVM will follow all the dependencies when loading classes.
Maven is often more trouble than it's worth, but the ability to open a maven project directly into IDEs such as IntelliJ is excellent. For example, IntelliJ will download all dependencies and have them available without having to run a build first, or an mvn command and then a project refresh. It also isn't necessary to re-generate the project every time a dependency is added. I work with a number of Eclipse developers who switched to IntelliJ for this alone.
However, one shortfall of Maven is that many libraries (or versions of libraries) are not available on public repositories. Therefore it is often necessary to set up a local repository such as archiva. In ant, it would just be a matter of adding it to the lib directory in the repository.
Maven can also attack when you need to do something that maven doesn't directly support via a plugin. What would normally be a few lines of ant can often turn into a morning's worth of work.
Finally, buildr is an excellent way of using Maven's dependency management and plugins, while also supporting ad-hoc tasks.