Can't build artifacts (export JAR) in IntelliJ? - java

I am trying to create a .JAR out of my JavaFX project to then convert it into an .exe file. But IntelliJ doesn't show a "build artifacts" option in the main menu, which the guides I've seen require me to click. Build only gives me the following options: Recompile Main.java, Build Project, Rebuild Project 'Project Title'. Any help is appreciated
I've already created an artifact in the project structure tab.

You must define an artifact in File > Project Structure > Artifacts. Once defined you can generate your final file under Build > Build artifacts > your_artifact
I leave you an example that I'm actually using

It looks like your IDE menu is customized and some of the items were removed. It should help if you either reset the menu to the defaults or add the missing items manually:

Related

Eclipse I can't link project B to project A

I work with Eclipse. I have two projects in the workspace. This is my Eclipse navigator.
I want to add AR04.CME to cmeWeb.
Folder cmeShare has some jar which I need in cmeWeb.
I click in cmeWeb properties ->Java Build Path -> Projects
This is the screen
AR04.CME doesn't appear as project.
How can I add this project?
Linking Project A to another Project B is useful when you have source code in A that you want to share to B. That's not your case. You don't seem to share source code, but a compiled library instead.
Your best option is to edit cmeWeb's Build Classpath > libraries > add jar > select your Jar library.

eclipse doesn't see java file generated during installation of maven module

I am working on a specific maven module. I have it imported into eclipse by m2eclipse plugin. The module uses our internal plugin to generate java files from some csv files. During install goal those files are being generated and put to target/generated-sources/folder_name.
Can you tell me how I can import these java files into eclipse so it stops showing me compilation errors saying that 'x' cannot be resolved to a type?
Now every module which uses those files has compilations errors in eclipse, everything works fine when I try to build from command line.
Thanks in advance.
UPDATE: Thanks a lot guys, I was trying similar solution but instead of adding source folder I was trying to add external classes :|
project -> properties -> java build path -> source -> add folder -> (search for target/generated-sources/folder_name, create it if deleted by maven) -> ok
now eclipse will only complain when you'll use mvn clean deleting target folder.
Eclipse refreshes file content on request, so any change made external to eclipse, eclipse doesn't know about that
You can make eclipse to use native hooks to detect external changes
preference > workspace > check refresh using native hooks
and add that directory to source path
You probably need to add the folder of the generated files as a Source folder in the project. Look in the Project Properties > Java Build Path > Source tab and add the folder.

Call to class from different eclipse plugin project

I have two different eclipse plugin projects and I want to call to class from proj1 in proj2,
what are the steps that I should do?
I have tried to do it with adding a project proj1 to project2 with the tab right click on project properties and in the tab project ,without success .it doesnt know it?
If you're working with plug-in projects, they can only rely on other plug-ins and .jar files according to their plug-in manifest files. Open proj2's MANIFEST.MF file in the Plug-In Manifest Editor and add proj1 as a Required Plug-in from the Dependency tab.
Sometimes Eclipse get confused or does not use your changed configuration by itself.
Often it helps to force eclipse to build all projects again.
Main menue: 'Project' than click on 'Clean ...' select 'Clean all projects' and press 'OK'

How to create a jar with external libraries included in Eclipse?

I am done with the project which connects to database (MySQL). Now I want to export the project as jar. But I don't know how to include its external dependencies? Is there any way of doing it in Eclipse or should I use any scripts for that?.
When you export your project as a 'Runnable jar' (Right mouse on project -> Export -> Runnable jar) you have the option to package all dependencies into the generated jar. It also has two other ways (see screenshot) to export your libraries, be aware of the licences when deciding which packaging method you will use.
The 'launch configuration' dropdown is populated with classes containing a main(String[]) method. The selected class is started when you 'run' the jar.
Exporting as a runnable jar uses the dependencies on your build path (Right mouse on project -> Build Path -> Configure Build Path...). When you export as a 'regular' (non-runnable) jar you can select any file in your project(s). If you have the libraries in your project folder you can include them but external dependencies, for example maven, cannot be included (for maven projects, search here).
You could use the Export->Java->Runnable Jar to create a jar that includes its dependencies
Alternatively, you could use the fatjar eclipse plugin as well to bundle jars together
You can right-click on the project, click on export, type 'jar', choose 'Runnable JAR File Export'. There you have the option 'Extract required libraries into generated JAR'.
Personally,
None of the answers above worked for me, I still kept getting NoClassDefFound errors (I am using Maven for dependencies). My solution was to build using "mvn clean install" and use the "[project]-jar-with-dependencies.jar" that that command creates. Similarly in Eclipse you can right click the project -> Run As -> Maven Install and it will place the jars in the target folder.
If you want to export all JAR-files of a Java web-project, open the latest generated WAR-file with a ZIP-tool (e.g. 7-Zip), navigate to the /WEB-INF/lib/ folder. Here you will find all JAR-files you need for this project (as listed in "Referenced Libraries").
While exporting your source into a jar, make sure you select runnable jar option from the options. Then select if you want to package all the dependency jars or just include them directly in the jar file. It depends on the project that you are working on.
You then run the jar directly by java -jar example.jar.
To generate jar file in eclipse right click on the project for which you want to generate, Select Export>Java>Runnable Jar File,
Its create jar which includes all the dependencies from Pom.xml, But please make sure license issue if you are using third-party dependency for your application.
If it is a standalone (Main method) java project then Not any specific path put all the jars inside the project not any specific path then right click on the project - > export - > Runnable jar --> Select the lunch configuration and Library handeling then choose the radio button option "Package required libraries into generated jar" -- > Finish.
Or
If you have a web project then put all the jars in web-inf/lib folder and do the same step.
Before exporting, click on Buildpath and configure java buildpath and add external jars inside the library. Then try to export as a runnable jar.

How to open jmeter project in IDEA?

I downloaded and extract jmeter's source code: http://jmeter.apache.org/download_jmeter.cgi
How do I go about opening this project in IntelliJ?
I tried to 'open project' and navigated to the directory, but it doesn't seem to pickup any of the files to open the project.
Do I have to import or something?
Create a new project over existing source--you can't open a project when there's been no project set up.
IntelliJ will pop up a window with the source directories it discovers; by default they'll all be checked.
You can add the Ant build file in the "Ant Build" tool window to make Ant builds easier.
UPDATE
Since JMeter 5.2 it uses Gradle instead of ant, you can easily import the project into IntelliJ like so:
You require IntelliJ 2018.3.1 or newer.
Open the build.gradle.kts file with IntelliJ IDEA and choose Open as
Project Make sure Create separate module per source set is selected
Make sure Use default Gradle wrapper is selected
In the File already exists dialogue, choose Yes to overwrite
In the Open Project dialogue, choose Delete Existing Project and Import (if IntelliJ project already exists)
ORIGINAL
These are the steps I followed to get the JMeter source code into IntelliJ. I've included some screenshots on my blog.
Import project from Git: https://github.com/apache/jmeter.git
Select "Create project from existing sources"
Name the project
Select all source file directories
Deselect any libraries, (add them later)
Select all of the discovered modules
Select the SDK (you might need to add one if you've not used IntelliJ before)
Press Next and then Finish
Click the "Ant Build" menu in IntelliJ
Press add and add the build.xml file
Run the download_jars target
Open project settings (Ctrl+Alt+Shift+S) then add the downloaded jars to the project
Notes:
You can compile and start the GUI by executing the run_gui ant target
If there are any errors in IntelliJ when viewing files (or pressing build project) you can usually solve them by pressing alt+enter on the offending code and making the appropriate 'module' a dependency - however this shouldn't stop you developing or running things via ant.
I've also created a screencast of the above steps:
https://youtu.be/r0Z79PjEb80

Categories

Resources