Maven: Create directory when needed in target [duplicate] - java

This question already has answers here:
create directory when needed in maven
(3 answers)
Closed 7 years ago.
I have JUnit-tests within my Maven project that save an image to a folder within the target directory. I want Maven to create this folder during the build phase if it doesn't already exist. I thought it might be possible to achieve this by adding a directory within the pom.xml but can't find any documentation about it.
Do I need to use a plugin for that?

You can simply create new file with new File("target", "<directory>/<file>"). then file.mkDirs(), It will create directory in target directory.

Related

What does it mean when the "out" folder in a project is highlighted in IDEA? [duplicate]

This question already has answers here:
What is the function of the "out" and ".idea" folder in Intellij?
(3 answers)
Closed 2 years ago.
Why is the out folder and all its content highlighted? Does it mean I did something wrong?
This is the project compiler output directory. The red color means that it is excluded directory in project. Files in excluded folders are ignored by code completion, navigation and inspection.
This folder is created when you're compiling your project and contains compiled classes.

Packing external files into jar and then allowing code to perform operations on these packed files [duplicate]

This question already has an answer here:
Executing a python file from within JAR
(1 answer)
Closed 5 years ago.
So I'm using IntelliJ IDEA and I've got my structure as follows:
So firstly, I want to be able to package the res folder with all my scripts inside the jar, and then when I run my program it can access the python scripts from inside the jar itself.
So far when I try running things on res/test.py it can't find the file.
EDIT: I've taken a look at an article which suggests getting the temporary files location using System.getProperty("java.io.tmpdir") and maybe copying the files to there using Class.getResourceAsStream("/path/to/file")
I'm not sure however if Class#getResourceAsStream is suitable for getting it from inside the jar to write it to the temporary location.
The code works when you check the file exists prior to executing the Process:
File f = new File("res/test.py");
System.out.println(f.exists()); // true

When does manifest file created in java? [duplicate]

This question already has answers here:
Use of the MANIFEST.MF file in Java
(2 answers)
Closed 6 years ago.
I have a basic question about the manifest file: when is this file created?
Is it created in the .class file when we compile a java file? Or should we create the manifest file from the command line after the .class file is created?
Update: you can find the answer here: Use of the MANIFEST.MF file in Java
The manifest file has nothing to do with the compilation/running process of a class.
If you configured your project correctly in your IDE (depending on the IDE), it will be generated during the build project process.
If you are working using the command prompt and notepad, you can always create it manually.

is there a way to know java packages in a jar file? [duplicate]

This question already has answers here:
How do I find the packages defined in a jar?
(5 answers)
Closed 8 years ago.
Is there any way to know the packages of a .jar file as I want to use "gtranslateapi-1.0" but not getting the package or class names in it.
I have also added it to my libraries in netbeans 8.0
You can see it here: https://code.google.com/p/java-google-translate-text-to-speech/downloads/list
please help, thanks in advance !!
jar is just a zip.so if you want to know what is packed into a jar file, you may unzip it (using either your favourite zip tool or jar itself e.g jar -t to list the contents). hint jar without args gives you a list of options
in netbeans you can easily see packages and classes .or you can rename .jar to .zip and open in compress program like winrar
in netbeans you can expand jar easily.add jar to libries and expand it .this is your jar file

How to export image files into runnable JAR with eclipse [duplicate]

This question already has answers here:
Including Images with an executable jar
(2 answers)
Closed 8 years ago.
Title speaks for itself. I've made a clone of space invaders which uses several image assets. How do I tell eclipse to export the image files into the runnable JAR so they can be used by the program? I'm using eclipse europa.
As Mr. Anderser pointed out, make sure to read them as resources when inside of a jar, not files.
This might help.
Toolkit.getDefaultToolkit().getImage(getClass().getResource("images/imageFile.png"));
Images inside jar files must be read as resources and not plain files.
You can create a new sourcefolder, e.g. named "images", and put your images in there.

Categories