Save information beside JAR on runtime - java

Since some time I've been busy learning Java and I spent most of that time working with Spigot (Minecraft) plugins.
I love how to plugins are able to copy a YAML file from resources to a folder, so a user is able to edit those YAML files.
Now I trying to find information on how I would accomplish the same effect but with just a regular JAR application, but I find it hard to find any information on how to do so.
Basicly what I wanna do is shipping an YAML with the JAR and once the application ran once, it needs to place it outside the JAR so it will use that file to get the content out of it.
Is this easy to achieve and which packages would be best to use for this purpose?
Thank you in advance!

Related

Create Project Java Web without maven and Ide

I am trying to create an application for creating java web projects in a personalized, automated way, without maven, without IDE, but so far I have not seen anything on the internet that would suit me. Could someone guide me or tell me how I can do it?
I consider your question differently that you want to create an application which when run can automatically create web projects !! If that is correct you need to write set of programs which would make files necessary for your web project like generate java files, Jsp files, XML, properties etc depending on complexity of your web projects, also if customized with parameters it can make different kinds of projects. Then you will need to make war file which is going to be the final deploy-able component with these files. This is all that you would do manually through IDE and maven would be the jar files you would need if any. Let me know if you need any more help.
Please accept and like if you appreciate my gesture to help with my ideas n experience.

Given a JAR file, allegedly contains web server, how do I deploy it?

I've been handed a JAR file, told it contains a web application, and instructed to deploy it. I'm familiar with java as a language, but I have next to no experience with its web ecosystem. Trying to run it as an executable, I find out it has no main class, so I take a look at the contents, and find that it has a META-INF/web-fragment.xml file, along with a couple of Servlet classes and some config files referenced in the xml. It looks like there is basically everything here for a complete application, but I have no idea how to actually deploy it, and google only yields tutorials on how to build these things from scratch with IDEs and deploy using maven plugins and goals.
Assuming that building from source is out of the question and I only have standard unix and java CLI tools available, based on the information provided (And I can provide more if necessary), what is the simplest way to get this up and running?
A web applicaton should be in a WAR file, not a JAR file, and you should only need to just drop it into the webapp directory of your Tomcat, or follow the instructions for whatever other container you're using.
If it's only a fragment, as appears from the XML, (a) it isn't a webapp, only part of one, and (b) you personally can't deploy it at all. You need the whole thing.
Send the assignment back for clarification.

GSON installation

So I'm working on a server application, and i'd like to use json to serialize data into packets to send between the server and the client. However, I"m having a lot of trouble with actually adding the library to eclipse. Usually, I use Build Path to add external .jar files, but the repository i'm using for gson -> https://github.com/google/gson only has .java files. Am I missing something very obvious, or do i just make a folder and drag the .java files in?
Note: I'm a relatively beginner to intermediate java programmer, so some things might need a bit of explaining.
Thanks!
You can download the JAR files from here. Keep in mind, if you have the .java files you can actually compile the files yourself and turn them into .jars.
I would HIGHLY recommend you invest some time into understanding how Maven works. When you add more and more dependencies it will become a nightmare manually downloading them and managing them yourself.

Import Neo4J API in Netbeans

For a project I am building a Java GUI from which queries can be sent to Neo4j, to make it easier to do particular analyses. To get this all working, I have downloaded a .jar folder containing all relevant classes (neo4j-javadocs-2.1.7-javadoc.jar). I have loaded the library through the project->properties->libraries->Add JAR, but I can't seem to import the classes I want to use in my GUI (neither automatically nor manually).
I am dabbling in Java, so it is probably a basic oversight that I am making, but with the help from tutorials online and trying different commands (like entering the path of the .jar file) I can't get it working. One of these tutorials is specific on the Neo4j library, so I am very confused. That tutorial is written for Eclipse, instead of NetBeans which I am working with, but as far as my knowledge goes that shouldn't matter for the commands
I don't have enough reputation to post direct images, but this link contains a screenshot. If more information is required, let me know. http://i.stack.imgur.com/lUytK.png
Additionally, when I normally add a class that is not imported, there is an automatic function to import the class. This option is missing for my specific class, so maybe I added the library in an incorrect way?
http://i.stack.imgur.com/QeDX4.png
Edit: Issue resolved thanks to a colleague that came in. Apparently I loaded the Javadoc where I should have loaded to individual classes from the lib directory.
It really should work.
Try to save all changes. NetBeans reparses the classes when you save them.
Try to build your project manually from command line using Ant build script
Use Maven, Ivy or Gradle for Dependency Management then you can depend on the Neo4j artifacts.
For sending queries to the server you actually don't need Neo4j artifacts.
You can also use the JDBC driver, see http://neo4j.com/developer/java

JavaWebStart- multiple jars in same jnlp?

I'm trying to convert my java software jar into a Java WebStart application. I've managed to successfully deploy it as a WebStart with a jnlp file that provides details about the software's jar.
However, my software requires certain details to be stored locally in a file on user's machine. These details can be set & the file can be generated by having the user run another java software (a very small java utility software) coded by me. I wonder if it's possible to package in this smaller software's jar as well along with the main software using the tag. As far as I know, we can use the tag to specify additional jars/ libraries that our software jar uses.
Can we package in another java jar created by us in the jnlp and would it then get downloaded alongside the main software jar and other libraries (jars) when the user launches the jnlp ?
Kindly let me know. Thanks.
P.S: I know that all jars downloaded by a WebStart application end up in the deployment cache. Is there no way to specify where they should get downloaded to ? In my case, I would prefer it if the 2nd software's jar gets downloaded in an easier-to-find location.
Yes, it would be downloaded - but it would end up in the deployment-cache with no easy way to find it (names get all mixed up) or start it.
There's no way around webstart keeping the files in the deployment-cache: if you could specify the download-location different versions of jar-files with the same names and different codebase could end up in the same location causing no end of trouble.
I see two ways to get the wanted functionality:
Add the ability to change the local configuration as an additional function in the main application. You probably can use most of the existing code but use a method-call instead of starting it as a separate application
Create a second jnlp-file to start the configuration-program. From what you write it should be pretty small and not too much effort to create.

Categories