Java Maven Could not find or load main class
I've just started to learn Java but have issues almost at every step...
At least I want to make this super simple getting started tutorial work (from official Maven page) :)
I've done every step like in this tutorial and have built the project but can't run it.
So, after mvn package
I have BUILD SUCCESSFUL
but when I'am trying to launch jar
file by this command java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
an error occurs:
Error: Could not find or load main class com.mycompany.app.App
Caused by: java.lang.ClassNotFoundException: com.mycompany.app.App
How to fix it?
java version "11.0.1" 2018-10-16 LTS
Apache Maven 3.6.0
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Project structure is created automatically by this command as shown in the docs
my-app
|-src
| |-main
| |-java
| |-com
| |-mycompany
| |-app
| |-App.java
|-pom.xml
|-target
And the App.java
code:
package com.mycompany.app;
/**
* Hello world!
*
*/
public class App
public static void main( String args )
System.out.println( "Hello World!" );
And pom.xml
file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>maven-test</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>maven-test</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
</project>
Also I had to add these lines to make work mvn package
command:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
java maven
|
show 5 more comments
I've just started to learn Java but have issues almost at every step...
At least I want to make this super simple getting started tutorial work (from official Maven page) :)
I've done every step like in this tutorial and have built the project but can't run it.
So, after mvn package
I have BUILD SUCCESSFUL
but when I'am trying to launch jar
file by this command java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
an error occurs:
Error: Could not find or load main class com.mycompany.app.App
Caused by: java.lang.ClassNotFoundException: com.mycompany.app.App
How to fix it?
java version "11.0.1" 2018-10-16 LTS
Apache Maven 3.6.0
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Project structure is created automatically by this command as shown in the docs
my-app
|-src
| |-main
| |-java
| |-com
| |-mycompany
| |-app
| |-App.java
|-pom.xml
|-target
And the App.java
code:
package com.mycompany.app;
/**
* Hello world!
*
*/
public class App
public static void main( String args )
System.out.println( "Hello World!" );
And pom.xml
file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>maven-test</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>maven-test</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
</project>
Also I had to add these lines to make work mvn package
command:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
java maven
1
if you are just starting to learn java, start by learning java on it's own. add maven later
– Stultuske
Nov 14 '18 at 9:13
I suggest you to write your code and compile it via javac command. later on ,when you increase your mindset and knowledge,you start to use frameworks ,libaries like maven etc.
– Türkmen Mustafa Demirci
Nov 14 '18 at 9:35
@Stultuske, thanks, but it doesn't solve the problem. Furthermore I'am trying to repeat very simple example from official maven docs.
– mr.boris
Nov 14 '18 at 9:36
@mr.boris no, it might, however, avoid this kind of problems for you in the long run. this is like someone who just learned to walk after being paralyzed for his entire life saying: "I just tried to run 15 miles and my leg hurts". Sure, you can massage the leg, but unless you build up and start at the beginning, that leg 'll hurt the next time as well.
– Stultuske
Nov 14 '18 at 9:40
@Stultuske, thank you for mentoring, but I have experience in programming generally. So, if some minor error occurs then should be some simple solution for it. All in all this issue is not about multithreading or concurrency. In my opinion solution for such issues should be in the first lines of Google searching but it isn't (especially if related to official docs). So, it's first wake-up call to me for keep on going with Java.
– mr.boris
Nov 14 '18 at 9:59
|
show 5 more comments
I've just started to learn Java but have issues almost at every step...
At least I want to make this super simple getting started tutorial work (from official Maven page) :)
I've done every step like in this tutorial and have built the project but can't run it.
So, after mvn package
I have BUILD SUCCESSFUL
but when I'am trying to launch jar
file by this command java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
an error occurs:
Error: Could not find or load main class com.mycompany.app.App
Caused by: java.lang.ClassNotFoundException: com.mycompany.app.App
How to fix it?
java version "11.0.1" 2018-10-16 LTS
Apache Maven 3.6.0
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Project structure is created automatically by this command as shown in the docs
my-app
|-src
| |-main
| |-java
| |-com
| |-mycompany
| |-app
| |-App.java
|-pom.xml
|-target
And the App.java
code:
package com.mycompany.app;
/**
* Hello world!
*
*/
public class App
public static void main( String args )
System.out.println( "Hello World!" );
And pom.xml
file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>maven-test</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>maven-test</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
</project>
Also I had to add these lines to make work mvn package
command:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
java maven
I've just started to learn Java but have issues almost at every step...
At least I want to make this super simple getting started tutorial work (from official Maven page) :)
I've done every step like in this tutorial and have built the project but can't run it.
So, after mvn package
I have BUILD SUCCESSFUL
but when I'am trying to launch jar
file by this command java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
an error occurs:
Error: Could not find or load main class com.mycompany.app.App
Caused by: java.lang.ClassNotFoundException: com.mycompany.app.App
How to fix it?
java version "11.0.1" 2018-10-16 LTS
Apache Maven 3.6.0
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Project structure is created automatically by this command as shown in the docs
my-app
|-src
| |-main
| |-java
| |-com
| |-mycompany
| |-app
| |-App.java
|-pom.xml
|-target
And the App.java
code:
package com.mycompany.app;
/**
* Hello world!
*
*/
public class App
public static void main( String args )
System.out.println( "Hello World!" );
And pom.xml
file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>maven-test</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>maven-test</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
</project>
Also I had to add these lines to make work mvn package
command:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
java maven
java maven
edited Nov 14 '18 at 10:15
mr.boris
asked Nov 14 '18 at 9:12
mr.borismr.boris
448519
448519
1
if you are just starting to learn java, start by learning java on it's own. add maven later
– Stultuske
Nov 14 '18 at 9:13
I suggest you to write your code and compile it via javac command. later on ,when you increase your mindset and knowledge,you start to use frameworks ,libaries like maven etc.
– Türkmen Mustafa Demirci
Nov 14 '18 at 9:35
@Stultuske, thanks, but it doesn't solve the problem. Furthermore I'am trying to repeat very simple example from official maven docs.
– mr.boris
Nov 14 '18 at 9:36
@mr.boris no, it might, however, avoid this kind of problems for you in the long run. this is like someone who just learned to walk after being paralyzed for his entire life saying: "I just tried to run 15 miles and my leg hurts". Sure, you can massage the leg, but unless you build up and start at the beginning, that leg 'll hurt the next time as well.
– Stultuske
Nov 14 '18 at 9:40
@Stultuske, thank you for mentoring, but I have experience in programming generally. So, if some minor error occurs then should be some simple solution for it. All in all this issue is not about multithreading or concurrency. In my opinion solution for such issues should be in the first lines of Google searching but it isn't (especially if related to official docs). So, it's first wake-up call to me for keep on going with Java.
– mr.boris
Nov 14 '18 at 9:59
|
show 5 more comments
1
if you are just starting to learn java, start by learning java on it's own. add maven later
– Stultuske
Nov 14 '18 at 9:13
I suggest you to write your code and compile it via javac command. later on ,when you increase your mindset and knowledge,you start to use frameworks ,libaries like maven etc.
– Türkmen Mustafa Demirci
Nov 14 '18 at 9:35
@Stultuske, thanks, but it doesn't solve the problem. Furthermore I'am trying to repeat very simple example from official maven docs.
– mr.boris
Nov 14 '18 at 9:36
@mr.boris no, it might, however, avoid this kind of problems for you in the long run. this is like someone who just learned to walk after being paralyzed for his entire life saying: "I just tried to run 15 miles and my leg hurts". Sure, you can massage the leg, but unless you build up and start at the beginning, that leg 'll hurt the next time as well.
– Stultuske
Nov 14 '18 at 9:40
@Stultuske, thank you for mentoring, but I have experience in programming generally. So, if some minor error occurs then should be some simple solution for it. All in all this issue is not about multithreading or concurrency. In my opinion solution for such issues should be in the first lines of Google searching but it isn't (especially if related to official docs). So, it's first wake-up call to me for keep on going with Java.
– mr.boris
Nov 14 '18 at 9:59
1
1
if you are just starting to learn java, start by learning java on it's own. add maven later
– Stultuske
Nov 14 '18 at 9:13
if you are just starting to learn java, start by learning java on it's own. add maven later
– Stultuske
Nov 14 '18 at 9:13
I suggest you to write your code and compile it via javac command. later on ,when you increase your mindset and knowledge,you start to use frameworks ,libaries like maven etc.
– Türkmen Mustafa Demirci
Nov 14 '18 at 9:35
I suggest you to write your code and compile it via javac command. later on ,when you increase your mindset and knowledge,you start to use frameworks ,libaries like maven etc.
– Türkmen Mustafa Demirci
Nov 14 '18 at 9:35
@Stultuske, thanks, but it doesn't solve the problem. Furthermore I'am trying to repeat very simple example from official maven docs.
– mr.boris
Nov 14 '18 at 9:36
@Stultuske, thanks, but it doesn't solve the problem. Furthermore I'am trying to repeat very simple example from official maven docs.
– mr.boris
Nov 14 '18 at 9:36
@mr.boris no, it might, however, avoid this kind of problems for you in the long run. this is like someone who just learned to walk after being paralyzed for his entire life saying: "I just tried to run 15 miles and my leg hurts". Sure, you can massage the leg, but unless you build up and start at the beginning, that leg 'll hurt the next time as well.
– Stultuske
Nov 14 '18 at 9:40
@mr.boris no, it might, however, avoid this kind of problems for you in the long run. this is like someone who just learned to walk after being paralyzed for his entire life saying: "I just tried to run 15 miles and my leg hurts". Sure, you can massage the leg, but unless you build up and start at the beginning, that leg 'll hurt the next time as well.
– Stultuske
Nov 14 '18 at 9:40
@Stultuske, thank you for mentoring, but I have experience in programming generally. So, if some minor error occurs then should be some simple solution for it. All in all this issue is not about multithreading or concurrency. In my opinion solution for such issues should be in the first lines of Google searching but it isn't (especially if related to official docs). So, it's first wake-up call to me for keep on going with Java.
– mr.boris
Nov 14 '18 at 9:59
@Stultuske, thank you for mentoring, but I have experience in programming generally. So, if some minor error occurs then should be some simple solution for it. All in all this issue is not about multithreading or concurrency. In my opinion solution for such issues should be in the first lines of Google searching but it isn't (especially if related to official docs). So, it's first wake-up call to me for keep on going with Java.
– mr.boris
Nov 14 '18 at 9:59
|
show 5 more comments
2 Answers
2
active
oldest
votes
You can re-try with this 4 commnds:
> mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
> cd my-app
> mvn package
> java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
Thank you for testing this sample. As for me I have an error onmvn package
step..BUILD FAILURE
Target option 1.5 is no longer supported. Use 1.6 or later.
. At least for this step I have to addproperties
to thepom.xml
file.
– mr.boris
Nov 14 '18 at 10:46
Now it's work. Thanks
– mr.boris
Nov 14 '18 at 10:54
add a comment |
Based on your the output of the jar
command, (the NoSuchFileException
from the comments), it seems you were running the java
command from some directory other than that of the maven project. @Sgrillon's answer works because he changes directory to that of my-app
, runs the mvn package
command and then the java
command from the same directory. Then the target/my-app-1.0-SNAPSHOT.jar
is there (generated by maven) and can be found by the java
command to include it in its classpath (-cp
)
This is not a java or maven problem but an issue with the file's path.
EDIT: I just realized on your pom.xml
that your artifact was named maven-test
<artifactId>maven-test</artifactId>
In this case, the jar would have been target/maven-test-1.0-SNAPSHOT.jar
instead of my-app...
and that's why neither java
nor jar
could find it.
Thanks, everything works now after removing current project and repeat all steps again despite that fact that I had to modifyproperties
inpom.xml
file a little bit for the right Maven compiler versioning. Actually, I tried to run.jar
file from the same directory (from the root of the project), so that I have no clue why that error occurred
– mr.boris
Nov 14 '18 at 12:48
@Mr.boris, see my edit on the answer, did you manually changed the artifactId on the pom.xml??
– Chirlo
Nov 14 '18 at 14:44
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296554%2fjava-maven-could-not-find-or-load-main-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can re-try with this 4 commnds:
> mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
> cd my-app
> mvn package
> java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
Thank you for testing this sample. As for me I have an error onmvn package
step..BUILD FAILURE
Target option 1.5 is no longer supported. Use 1.6 or later.
. At least for this step I have to addproperties
to thepom.xml
file.
– mr.boris
Nov 14 '18 at 10:46
Now it's work. Thanks
– mr.boris
Nov 14 '18 at 10:54
add a comment |
You can re-try with this 4 commnds:
> mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
> cd my-app
> mvn package
> java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
Thank you for testing this sample. As for me I have an error onmvn package
step..BUILD FAILURE
Target option 1.5 is no longer supported. Use 1.6 or later.
. At least for this step I have to addproperties
to thepom.xml
file.
– mr.boris
Nov 14 '18 at 10:46
Now it's work. Thanks
– mr.boris
Nov 14 '18 at 10:54
add a comment |
You can re-try with this 4 commnds:
> mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
> cd my-app
> mvn package
> java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
You can re-try with this 4 commnds:
> mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
> cd my-app
> mvn package
> java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
answered Nov 14 '18 at 10:36
sgrillonsgrillon
3,68312851
3,68312851
Thank you for testing this sample. As for me I have an error onmvn package
step..BUILD FAILURE
Target option 1.5 is no longer supported. Use 1.6 or later.
. At least for this step I have to addproperties
to thepom.xml
file.
– mr.boris
Nov 14 '18 at 10:46
Now it's work. Thanks
– mr.boris
Nov 14 '18 at 10:54
add a comment |
Thank you for testing this sample. As for me I have an error onmvn package
step..BUILD FAILURE
Target option 1.5 is no longer supported. Use 1.6 or later.
. At least for this step I have to addproperties
to thepom.xml
file.
– mr.boris
Nov 14 '18 at 10:46
Now it's work. Thanks
– mr.boris
Nov 14 '18 at 10:54
Thank you for testing this sample. As for me I have an error on
mvn package
step.. BUILD FAILURE
Target option 1.5 is no longer supported. Use 1.6 or later.
. At least for this step I have to add properties
to the pom.xml
file.– mr.boris
Nov 14 '18 at 10:46
Thank you for testing this sample. As for me I have an error on
mvn package
step.. BUILD FAILURE
Target option 1.5 is no longer supported. Use 1.6 or later.
. At least for this step I have to add properties
to the pom.xml
file.– mr.boris
Nov 14 '18 at 10:46
Now it's work. Thanks
– mr.boris
Nov 14 '18 at 10:54
Now it's work. Thanks
– mr.boris
Nov 14 '18 at 10:54
add a comment |
Based on your the output of the jar
command, (the NoSuchFileException
from the comments), it seems you were running the java
command from some directory other than that of the maven project. @Sgrillon's answer works because he changes directory to that of my-app
, runs the mvn package
command and then the java
command from the same directory. Then the target/my-app-1.0-SNAPSHOT.jar
is there (generated by maven) and can be found by the java
command to include it in its classpath (-cp
)
This is not a java or maven problem but an issue with the file's path.
EDIT: I just realized on your pom.xml
that your artifact was named maven-test
<artifactId>maven-test</artifactId>
In this case, the jar would have been target/maven-test-1.0-SNAPSHOT.jar
instead of my-app...
and that's why neither java
nor jar
could find it.
Thanks, everything works now after removing current project and repeat all steps again despite that fact that I had to modifyproperties
inpom.xml
file a little bit for the right Maven compiler versioning. Actually, I tried to run.jar
file from the same directory (from the root of the project), so that I have no clue why that error occurred
– mr.boris
Nov 14 '18 at 12:48
@Mr.boris, see my edit on the answer, did you manually changed the artifactId on the pom.xml??
– Chirlo
Nov 14 '18 at 14:44
add a comment |
Based on your the output of the jar
command, (the NoSuchFileException
from the comments), it seems you were running the java
command from some directory other than that of the maven project. @Sgrillon's answer works because he changes directory to that of my-app
, runs the mvn package
command and then the java
command from the same directory. Then the target/my-app-1.0-SNAPSHOT.jar
is there (generated by maven) and can be found by the java
command to include it in its classpath (-cp
)
This is not a java or maven problem but an issue with the file's path.
EDIT: I just realized on your pom.xml
that your artifact was named maven-test
<artifactId>maven-test</artifactId>
In this case, the jar would have been target/maven-test-1.0-SNAPSHOT.jar
instead of my-app...
and that's why neither java
nor jar
could find it.
Thanks, everything works now after removing current project and repeat all steps again despite that fact that I had to modifyproperties
inpom.xml
file a little bit for the right Maven compiler versioning. Actually, I tried to run.jar
file from the same directory (from the root of the project), so that I have no clue why that error occurred
– mr.boris
Nov 14 '18 at 12:48
@Mr.boris, see my edit on the answer, did you manually changed the artifactId on the pom.xml??
– Chirlo
Nov 14 '18 at 14:44
add a comment |
Based on your the output of the jar
command, (the NoSuchFileException
from the comments), it seems you were running the java
command from some directory other than that of the maven project. @Sgrillon's answer works because he changes directory to that of my-app
, runs the mvn package
command and then the java
command from the same directory. Then the target/my-app-1.0-SNAPSHOT.jar
is there (generated by maven) and can be found by the java
command to include it in its classpath (-cp
)
This is not a java or maven problem but an issue with the file's path.
EDIT: I just realized on your pom.xml
that your artifact was named maven-test
<artifactId>maven-test</artifactId>
In this case, the jar would have been target/maven-test-1.0-SNAPSHOT.jar
instead of my-app...
and that's why neither java
nor jar
could find it.
Based on your the output of the jar
command, (the NoSuchFileException
from the comments), it seems you were running the java
command from some directory other than that of the maven project. @Sgrillon's answer works because he changes directory to that of my-app
, runs the mvn package
command and then the java
command from the same directory. Then the target/my-app-1.0-SNAPSHOT.jar
is there (generated by maven) and can be found by the java
command to include it in its classpath (-cp
)
This is not a java or maven problem but an issue with the file's path.
EDIT: I just realized on your pom.xml
that your artifact was named maven-test
<artifactId>maven-test</artifactId>
In this case, the jar would have been target/maven-test-1.0-SNAPSHOT.jar
instead of my-app...
and that's why neither java
nor jar
could find it.
edited Nov 14 '18 at 14:43
answered Nov 14 '18 at 12:08
ChirloChirlo
4,57211937
4,57211937
Thanks, everything works now after removing current project and repeat all steps again despite that fact that I had to modifyproperties
inpom.xml
file a little bit for the right Maven compiler versioning. Actually, I tried to run.jar
file from the same directory (from the root of the project), so that I have no clue why that error occurred
– mr.boris
Nov 14 '18 at 12:48
@Mr.boris, see my edit on the answer, did you manually changed the artifactId on the pom.xml??
– Chirlo
Nov 14 '18 at 14:44
add a comment |
Thanks, everything works now after removing current project and repeat all steps again despite that fact that I had to modifyproperties
inpom.xml
file a little bit for the right Maven compiler versioning. Actually, I tried to run.jar
file from the same directory (from the root of the project), so that I have no clue why that error occurred
– mr.boris
Nov 14 '18 at 12:48
@Mr.boris, see my edit on the answer, did you manually changed the artifactId on the pom.xml??
– Chirlo
Nov 14 '18 at 14:44
Thanks, everything works now after removing current project and repeat all steps again despite that fact that I had to modify
properties
in pom.xml
file a little bit for the right Maven compiler versioning. Actually, I tried to run .jar
file from the same directory (from the root of the project), so that I have no clue why that error occurred– mr.boris
Nov 14 '18 at 12:48
Thanks, everything works now after removing current project and repeat all steps again despite that fact that I had to modify
properties
in pom.xml
file a little bit for the right Maven compiler versioning. Actually, I tried to run .jar
file from the same directory (from the root of the project), so that I have no clue why that error occurred– mr.boris
Nov 14 '18 at 12:48
@Mr.boris, see my edit on the answer, did you manually changed the artifactId on the pom.xml??
– Chirlo
Nov 14 '18 at 14:44
@Mr.boris, see my edit on the answer, did you manually changed the artifactId on the pom.xml??
– Chirlo
Nov 14 '18 at 14:44
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296554%2fjava-maven-could-not-find-or-load-main-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
if you are just starting to learn java, start by learning java on it's own. add maven later
– Stultuske
Nov 14 '18 at 9:13
I suggest you to write your code and compile it via javac command. later on ,when you increase your mindset and knowledge,you start to use frameworks ,libaries like maven etc.
– Türkmen Mustafa Demirci
Nov 14 '18 at 9:35
@Stultuske, thanks, but it doesn't solve the problem. Furthermore I'am trying to repeat very simple example from official maven docs.
– mr.boris
Nov 14 '18 at 9:36
@mr.boris no, it might, however, avoid this kind of problems for you in the long run. this is like someone who just learned to walk after being paralyzed for his entire life saying: "I just tried to run 15 miles and my leg hurts". Sure, you can massage the leg, but unless you build up and start at the beginning, that leg 'll hurt the next time as well.
– Stultuske
Nov 14 '18 at 9:40
@Stultuske, thank you for mentoring, but I have experience in programming generally. So, if some minor error occurs then should be some simple solution for it. All in all this issue is not about multithreading or concurrency. In my opinion solution for such issues should be in the first lines of Google searching but it isn't (especially if related to official docs). So, it's first wake-up call to me for keep on going with Java.
– mr.boris
Nov 14 '18 at 9:59