First of all, i searched for similar questions and i found something, but nothing helps me out.
I'm trying to create a jar file in intellij using the artifact, but everytime i build i have the error: Error: Could not find or load main class com.test.wms.test
This is my test.java file
package com.test.wms;
public class test {
public static void main(String[] args){
// empty
}
}
Then i went into Project Structure -> Artifacts and added a new artifact, selected the type (jar), selected the name (test.jar) and generated the manifest.mf (autogenerated from the artifact page on intelij)
Manifest-Version: 1.0
Main-Class: com.test.wms.test
And this is the artifact edit page
Then i build the project and try to lunch in konsole with java -jar test.jar and the error is always the same: Error: Could not find or load main class com.test.wms.test
This is my project structure:
And this is my artifact edit page
Where is the mistake?
Thanks!
Fixed by myself, when i was creating the jar from the artifact i was selecting empty instead of From modules with dependancy (the output is the same but with this option works, maybe the IDE does something particular)
Related
I just created a java project and ran it. It ran fine.
Then I converted it into a maven project and resolved all errors in POM.XMl file as well. When I try to run the class file , Am getting the error
Error: Could not find or load main class jhj
Caused by: java.lang.ClassNotFoundException: jhj
My class looks like this:
public class jhj {
public static void main(String[] args)
{
System.out.println("as");
}
}
And my Environment variables are properly set.
I have set the M2_home, MAVEN_HOME and JAVA_HOME as well.
I tried removing the project from the workspace and re-importing them.
Also, I tried with refresh and Maven>>update the project options as well
Check your project build-path and enable specific output folders for each folder. Go one by one though each source-folder of your project and set the output folder that maven would use.
For example, your web project's src/main/java should have target/classes under the web project, test classes should have target/test-classes also under the web project and so.
Using this configuration will allow you to execute unit tests in eclipse.
Just one more advice, if your web project's tests require some configuration files that are under the resources, be sure to include that folder as a source folder and to make the proper build-path configuration.
Hope it helps.
I'm trying to create a GroovyDSL script which references some external libraries. Here's my script:
import com.github.javaparser.ast.Node
import org.reflections.Reflections
def ctx = context(
ctype: 'groovy.util.ObjectGraphBuilder',
paths: ['com/example/scripts/.*'],
filetypes: ["groovy"]
)
Map<String, Class> candidateClasses = new Reflections(Node.packageName).getSubTypesOf(Node)
.collectEntries { Class type -> [(type.simpleName.uncapitalize()): type] }
contributor(ctx) {
candidateClasses.each { String methodName, Class type ->
method name: methodName, params: [props: "java.util.Map", closure: "groovy.lang.Closure"], type: type.name
}
}
Trying to enable it in Intellij, I'm getting:
startup failed: transformDslSyntaxgdsl: 1: unable to resolve class com.github.javaparser.ast.Node
# line 1, column 1.
import com.github.javaparser.ast.Node
Now, I have the proper external dependencies declared in pom.xml, the rest of the code that depends on them is working just fine. I've also put the script inside a source folder (which some other answers here suggested might be relevant).
I have seen some examples for GDSL reference Intellij types like PsiClass, which tells me the classpath for GDSL files seems to be different from the project classpath. Is there any way to make sure project dependencies are appended to that classpath?
I also tried using #Grape only to get this error. Adding Apache Ivy as a dependency doesn't help, because again, project dependencies don't seem to influence the GDSL classpath.
After a bit more digging, I found that it is pretty easy to modify the IDE's classpath itself.
All you need to do is to drop a dependency into Intellij installation directory's lib subfolder, and reference the jar inside classpath.txt.
Initially, I added the jars my GDSL depends on directly, but then I realized I could simply add a dependency on Apache Ivy to classpath.txt instead and #Grab annotations would start working.
I'm trying to run a basic Kotlin main file but the problem is I don't have any run/debug configurations available.
My main.kt file is under src>main and is a very simple Helloworld program. See below image.
When I enter Add Configuration>Kotlin and type MainKt in Main Class, I get Warning: Class MainKt not found. In previous projects MainKt has been the default and I haven't had to add a configuration manually. Has anyone else come across this issue?
Image of project
Run/Debug Configuration image
Project Structure image
If I hit Run(in toolbar)>Run you can see no available configurations
EDIT: added Main module to source and MainKt class is now available in Add Run/Debug Configuration, but I get the error in below image, "Error: Could not find or load main class MainKt
Caused by: java.lang.ClassNotFoundException: MainKt"
Error: Cannot find MainKt
The source for the class MainKt (main.kt) does not appear to be under your sources root (src/main/kotlin), it's one level up if I interpret the UI of intellij correctly. Try moving it into the kotlin/ directory.
I have a JavaFX project that I would like to build as a Jar-file. However, when I attempt to do so, I get an error.
Error:Java FX Packager: Can't build artifact - fx:deploy is not available in this JDK
I found a similar problem on here from last year, but it seemed like they concluded nothing.
This happens because either you have many JDKs installed and compiling by another and running by another or you are using the Javafx Application jar feature when creating artifacts in Intellij which is unfortunately broken. Before proceeding with the below steps make sure that you are compiling with and running with the same JDK version.
Here is you fix it:
1 - Create a Launcher class:
The Launcher class is going to call the main JavaFx class from which your appliaction runs. Choosing to make the Jar directly through the Main class is going to error out giving the following error:
Error: Could not find or load main class Main
Caused by: java.lang.ClassNotFoundException: Main
Your Launcher class should look something like this:
public class Launcher {
public static void main(String[] args) {
MainGUI.main(args);
}
}
2 - On to building the Jar
You probably still have a META-INF folder from the previous build so delete it.
Build the project as a JAR:
File->Project Structure -> Artifacts -> "+" -> JAR-> from modules with dependancies..
Choose the Launcher class for you main and check "copy to the output directory and link via Manifest" and Press Ok
Press Apply then OK.
go to Build -> Build artifacts-> Rebuild
In the JetBrains website I found a good article about, Package JavaFX applications which was really helpful. In the #troubleshoot section it says that,
Error:Java FX Packager: Can't build artifact – fx:deploy is not available in this JDK
The fx:deploy task was a part of the Ant plugin that was formerly
distributed in ant-javafx.jar as a part of Java Packager. The Ant
plugin is not included in jpackage in the current JDK versions.
If you're using a JDK build of version 9 and later, use third-party
solutions for packaging. For example, refer to section Runtime images
in the JavaFX official documentation.
My Feature files resides in src/test/resources and testrunner class resides in src/test/java as per default cucumber-jvm set up.
I want to package this project in a jar file so that when I execute the jar, my tests should run.
How should I do it?
After a lot of tinkering around I think I may have a solution.
You would have two files (Sorry if my jargon is a bit off, I'm new to this too)
A Step Definition file and a Test Runner file. Make sure in your Test Runner file you have a main method
public static void main(String[] args) throws Exception {
JUnitCore.main(
"PackageName.Filename");
}
So that is ends up looking something like this:
public class TestRunner {
public static void main(String[] args) throws Exception {
JUnitCore.main(
"cucumberTest.TestRunner");
}
}
Run it as a Java Application.
Once that is done, you can now click it and export it as a Runnable Jar File. In the Launch configuration after selecting the Runnable Jar File option, choose your TestRunner from the drop down if it hasn't been selected and then select the appropriate Library handling. (I chose Extract required libraries to generate JAR) And an appropriate file destination.
Then click finish.
In my Test Runner java file I also added this:
#CucumberOptions(
features = "Feature"
,glue={"stepDefinition"}
,plugin={"pretty",
"json:C:/EclipseWorkspace/ProjectName/cucumber.json",
"junit:C:/EclipseWorkspace/ProjectName/cucumber.xml"}
)
This dumps the test into two usable files, JSON and XML, where you can view the details of your test.
I hope this helps.